mirror of
https://github.com/HumanAIGC-Engineering/gradio-webrtc.git
synced 2026-02-04 17:39:23 +08:00
* Add code * add code * add code * Rename messages * rename * add code * Add demo * docs + demos + bug fixes * add code * styles * user guide * Styles * Add code * misc docs updates * print nit * whisper + pr * url for images * whsiper update * Fix bugs * remove demo files * version number * Fix pypi readme * Fix * demos * Add llama code editor * Update llama code editor and object detection cookbook * Add more cookbook demos * add code * Fix links for PR deploys * add code * Fix the install * add tts * TTS docs * Typo * Pending bubbles for reply on pause * Stream redesign (#63) * better error handling * Websocket error handling * add code --------- Co-authored-by: Freddy Boulton <freddyboulton@hf-freddy.local> * remove docs from dist * Some docs typos * more typos * upload changes + docs * docs * better phone * update docs * add code * Make demos better * fix docs + websocket start_up * remove mention of FastAPI app * fastphone tweaks * add code * ReplyOnStopWord fixes * Fix cookbook * Fix pypi readme * add code * bump versions * sambanova cookbook * Fix tags * Llm voice chat * kyutai tag * Add error message to all index.html * STT module uses Moonshine * Not required from typing extensions * fix llm voice chat * Add vpn warning * demo fixes * demos * Add more ui args and gemini audio-video * update cookbook * version 9 --------- Co-authored-by: Freddy Boulton <freddyboulton@hf-freddy.local>
53 lines
1.4 KiB
Python
53 lines
1.4 KiB
Python
import os
|
|
from typing import Literal
|
|
|
|
import requests
|
|
|
|
|
|
def get_hf_turn_credentials(token=None):
|
|
if token is None:
|
|
token = os.getenv("HF_TOKEN")
|
|
credentials = requests.get(
|
|
"https://freddyaboulton-turn-server-login.hf.space/credentials",
|
|
headers={"X-HF-Access-Token": token},
|
|
)
|
|
if not credentials.status_code == 200:
|
|
raise ValueError("Failed to get credentials from HF turn server")
|
|
return {
|
|
"iceServers": [
|
|
{
|
|
"urls": "turn:gradio-turn.com:80",
|
|
**credentials.json(),
|
|
},
|
|
]
|
|
}
|
|
|
|
|
|
def get_twilio_turn_credentials(twilio_sid=None, twilio_token=None):
|
|
try:
|
|
from twilio.rest import Client
|
|
except ImportError:
|
|
raise ImportError("Please install twilio with `pip install twilio`")
|
|
|
|
if not twilio_sid and not twilio_token:
|
|
twilio_sid = os.environ.get("TWILIO_ACCOUNT_SID")
|
|
twilio_token = os.environ.get("TWILIO_AUTH_TOKEN")
|
|
|
|
client = Client(twilio_sid, twilio_token)
|
|
|
|
token = client.tokens.create()
|
|
|
|
return {
|
|
"iceServers": token.ice_servers,
|
|
"iceTransportPolicy": "relay",
|
|
}
|
|
|
|
|
|
def get_turn_credentials(method: Literal["hf", "twilio"] = "hf", **kwargs):
|
|
if method == "hf":
|
|
return get_hf_turn_credentials(**kwargs)
|
|
elif method == "twilio":
|
|
return get_twilio_turn_credentials(**kwargs)
|
|
else:
|
|
raise ValueError("Invalid method. Must be 'hf' or 'twilio'")
|