Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- app.py +44 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
+
from fastapi.responses import RedirectResponse
|
| 4 |
+
from fastrtc import ReplyOnPause, Stream, get_twilio_turn_credentials
|
| 5 |
+
from gradio.utils import get_space
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def detection(audio: tuple[int, np.ndarray]):
|
| 9 |
+
# Implement any iterator that yields audio
|
| 10 |
+
# See "LLM Voice Chat" for a more complete example
|
| 11 |
+
yield audio
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
stream = Stream(
|
| 15 |
+
handler=ReplyOnPause(detection),
|
| 16 |
+
modality="audio",
|
| 17 |
+
mode="send-receive",
|
| 18 |
+
rtc_configuration=get_twilio_turn_credentials() if get_space() else None,
|
| 19 |
+
concurrency_limit=20 if get_space() else None,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
app = FastAPI()
|
| 23 |
+
|
| 24 |
+
stream.mount(app)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@app.get("/")
|
| 28 |
+
async def index():
|
| 29 |
+
return RedirectResponse(
|
| 30 |
+
url="/ui" if not get_space() else "https://fastrtc-echo-audio.hf.space/ui/"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
if __name__ == "__main__":
|
| 35 |
+
import os
|
| 36 |
+
|
| 37 |
+
if (mode := os.getenv("MODE")) == "UI":
|
| 38 |
+
stream.ui.launch(server_port=7860, server_name="0.0.0.0")
|
| 39 |
+
elif mode == "PHONE":
|
| 40 |
+
stream.fastphone(host="0.0.0.0", port=7860)
|
| 41 |
+
else:
|
| 42 |
+
import uvicorn
|
| 43 |
+
|
| 44 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastrtc[vad]
|
| 2 |
+
twilio
|
| 3 |
+
python-dotenv
|