Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
|
|
| 1 |
from pathlib import Path
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
-
from gradio.utils import get_space
|
| 5 |
import numpy as np
|
| 6 |
-
import json
|
| 7 |
from dotenv import load_dotenv
|
|
|
|
| 8 |
from fastapi.responses import HTMLResponse, StreamingResponse
|
| 9 |
from fastrtc import (
|
| 10 |
AdditionalOutputs,
|
|
@@ -13,6 +13,7 @@ from fastrtc import (
|
|
| 13 |
audio_to_bytes,
|
| 14 |
get_twilio_turn_credentials,
|
| 15 |
)
|
|
|
|
| 16 |
from groq import AsyncClient
|
| 17 |
|
| 18 |
cur_dir = Path(__file__).parent
|
|
@@ -44,8 +45,12 @@ stream = Stream(
|
|
| 44 |
concurrency_limit=20 if get_space() else None,
|
| 45 |
)
|
| 46 |
|
|
|
|
| 47 |
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
| 49 |
def _(webrtc_id: str):
|
| 50 |
async def output_stream():
|
| 51 |
async for output in stream.output_stream(webrtc_id):
|
|
@@ -55,7 +60,7 @@ def _(webrtc_id: str):
|
|
| 55 |
return StreamingResponse(output_stream(), media_type="text/event-stream")
|
| 56 |
|
| 57 |
|
| 58 |
-
@
|
| 59 |
def index():
|
| 60 |
rtc_config = get_twilio_turn_credentials() if get_space() else None
|
| 61 |
html_content = (cur_dir / "index.html").read_text()
|
|
@@ -64,6 +69,13 @@ def index():
|
|
| 64 |
|
| 65 |
|
| 66 |
if __name__ == "__main__":
|
| 67 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
-
|
|
|
|
| 1 |
+
import json
|
| 2 |
from pathlib import Path
|
| 3 |
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
import numpy as np
|
|
|
|
| 6 |
from dotenv import load_dotenv
|
| 7 |
+
from fastapi import FastAPI
|
| 8 |
from fastapi.responses import HTMLResponse, StreamingResponse
|
| 9 |
from fastrtc import (
|
| 10 |
AdditionalOutputs,
|
|
|
|
| 13 |
audio_to_bytes,
|
| 14 |
get_twilio_turn_credentials,
|
| 15 |
)
|
| 16 |
+
from gradio.utils import get_space
|
| 17 |
from groq import AsyncClient
|
| 18 |
|
| 19 |
cur_dir = Path(__file__).parent
|
|
|
|
| 45 |
concurrency_limit=20 if get_space() else None,
|
| 46 |
)
|
| 47 |
|
| 48 |
+
app = FastAPI()
|
| 49 |
|
| 50 |
+
stream.mount(app)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
@app.get("/transcript")
|
| 54 |
def _(webrtc_id: str):
|
| 55 |
async def output_stream():
|
| 56 |
async for output in stream.output_stream(webrtc_id):
|
|
|
|
| 60 |
return StreamingResponse(output_stream(), media_type="text/event-stream")
|
| 61 |
|
| 62 |
|
| 63 |
+
@app.get("/")
|
| 64 |
def index():
|
| 65 |
rtc_config = get_twilio_turn_credentials() if get_space() else None
|
| 66 |
html_content = (cur_dir / "index.html").read_text()
|
|
|
|
| 69 |
|
| 70 |
|
| 71 |
if __name__ == "__main__":
|
| 72 |
+
import os
|
| 73 |
+
|
| 74 |
+
if (mode := os.getenv("MODE")) == "UI":
|
| 75 |
+
stream.ui.launch(server_port=7860)
|
| 76 |
+
elif mode == "PHONE":
|
| 77 |
+
stream.fastphone(host="0.0.0.0", port=7860)
|
| 78 |
+
else:
|
| 79 |
+
import uvicorn
|
| 80 |
|
| 81 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|