Spaces:
Sleeping
Sleeping
Commit
·
cd15d96
1
Parent(s):
de084a6
Code
Browse files- app.py +23 -2
- requirements.txt +1 -1
app.py
CHANGED
@@ -7,6 +7,7 @@ import gradio as gr
|
|
7 |
import huggingface_hub
|
8 |
import numpy as np
|
9 |
from dotenv import load_dotenv
|
|
|
10 |
from fastapi import FastAPI
|
11 |
from fastapi.responses import HTMLResponse, StreamingResponse
|
12 |
from fastrtc import (
|
@@ -30,6 +31,26 @@ client = huggingface_hub.InferenceClient(
|
|
30 |
)
|
31 |
stt_model = get_stt_model()
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
def response(
|
35 |
audio: tuple[int, np.ndarray],
|
@@ -75,7 +96,7 @@ stream = Stream(
|
|
75 |
additional_outputs=[chatbot, state],
|
76 |
additional_outputs_handler=lambda *a: (a[2], a[3]),
|
77 |
concurrency_limit=20 if get_space() else None,
|
78 |
-
rtc_configuration=
|
79 |
)
|
80 |
|
81 |
app = FastAPI()
|
@@ -95,7 +116,7 @@ class InputData(BaseModel):
|
|
95 |
|
96 |
@app.get("/")
|
97 |
async def _():
|
98 |
-
rtc_config =
|
99 |
html_content = (curr_dir / "index.html").read_text()
|
100 |
html_content = html_content.replace("__RTC_CONFIGURATION__", json.dumps(rtc_config))
|
101 |
return HTMLResponse(content=html_content)
|
|
|
7 |
import huggingface_hub
|
8 |
import numpy as np
|
9 |
from dotenv import load_dotenv
|
10 |
+
import requests
|
11 |
from fastapi import FastAPI
|
12 |
from fastapi.responses import HTMLResponse, StreamingResponse
|
13 |
from fastrtc import (
|
|
|
31 |
)
|
32 |
stt_model = get_stt_model()
|
33 |
|
34 |
+
ttl = 86400 # Can modify TTL, here it's set to 24 hours
|
35 |
+
|
36 |
+
turn_key_id = os.environ.get("TWILIO_ACCOUNT_SID")
|
37 |
+
turn_key_api_token = os.environ.get("TWILIO_AUTH_TOKEN")
|
38 |
+
|
39 |
+
response = requests.post(
|
40 |
+
f"https://rtc.live.cloudflare.com/v1/turn/keys/{turn_key_id}/credentials/generate-ice-servers",
|
41 |
+
headers={
|
42 |
+
"Authorization": f"Bearer {turn_key_api_token}",
|
43 |
+
"Content-Type": "application/json",
|
44 |
+
},
|
45 |
+
json={"ttl": ttl},
|
46 |
+
)
|
47 |
+
if response.ok:
|
48 |
+
rtc_configuration = response.json()
|
49 |
+
else:
|
50 |
+
raise Exception(
|
51 |
+
f"Failed to get TURN credentials: {response.status_code} {response.text}"
|
52 |
+
)
|
53 |
+
|
54 |
|
55 |
def response(
|
56 |
audio: tuple[int, np.ndarray],
|
|
|
96 |
additional_outputs=[chatbot, state],
|
97 |
additional_outputs_handler=lambda *a: (a[2], a[3]),
|
98 |
concurrency_limit=20 if get_space() else None,
|
99 |
+
rtc_configuration=rtc_configuration,
|
100 |
)
|
101 |
|
102 |
app = FastAPI()
|
|
|
116 |
|
117 |
@app.get("/")
|
118 |
async def _():
|
119 |
+
rtc_config = rtc_configuration
|
120 |
html_content = (curr_dir / "index.html").read_text()
|
121 |
html_content = html_content.replace("__RTC_CONFIGURATION__", json.dumps(rtc_config))
|
122 |
return HTMLResponse(content=html_content)
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
fastrtc[vad,
|
2 |
python-dotenv
|
3 |
huggingface_hub>=0.29.0
|
4 |
twilio
|
|
|
1 |
+
fastrtc[vad,stt]@https://huggingface.co/datasets/freddyaboulton/bucket/resolve/main/wheels/fastrtc/fastrtc-0.0.17rc1-py3-none-any.whl
|
2 |
python-dotenv
|
3 |
huggingface_hub>=0.29.0
|
4 |
twilio
|