Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
@@ -8,6 +8,7 @@ from typing import AsyncGenerator, Literal
|
|
8 |
import gradio as gr
|
9 |
import numpy as np
|
10 |
from dotenv import load_dotenv
|
|
|
11 |
from fastapi.responses import HTMLResponse
|
12 |
from fastrtc import (
|
13 |
AsyncStreamHandler,
|
@@ -149,13 +150,18 @@ class InputData(BaseModel):
|
|
149 |
api_key: str
|
150 |
|
151 |
|
152 |
-
|
|
|
|
|
|
|
|
|
|
|
153 |
async def _(body: InputData):
|
154 |
stream.set_input(body.webrtc_id, body.api_key, body.voice_name)
|
155 |
return {"status": "ok"}
|
156 |
|
157 |
|
158 |
-
@
|
159 |
async def index():
|
160 |
rtc_config = get_twilio_turn_credentials() if get_space() else None
|
161 |
html_content = (current_dir / "index.html").read_text()
|
@@ -166,9 +172,11 @@ async def index():
|
|
166 |
if __name__ == "__main__":
|
167 |
import os
|
168 |
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
stream.fastphone(host="0.0.0.0", port=7860)
|
173 |
else:
|
174 |
-
uvicorn
|
|
|
|
|
|
8 |
import gradio as gr
|
9 |
import numpy as np
|
10 |
from dotenv import load_dotenv
|
11 |
+
from fastapi import FastAPI
|
12 |
from fastapi.responses import HTMLResponse
|
13 |
from fastrtc import (
|
14 |
AsyncStreamHandler,
|
|
|
150 |
api_key: str
|
151 |
|
152 |
|
153 |
+
app = FastAPI()
|
154 |
+
|
155 |
+
stream.mount(app)
|
156 |
+
|
157 |
+
|
158 |
+
@app.post("/input_hook")
|
159 |
async def _(body: InputData):
|
160 |
stream.set_input(body.webrtc_id, body.api_key, body.voice_name)
|
161 |
return {"status": "ok"}
|
162 |
|
163 |
|
164 |
+
@app.get("/")
|
165 |
async def index():
|
166 |
rtc_config = get_twilio_turn_credentials() if get_space() else None
|
167 |
html_content = (current_dir / "index.html").read_text()
|
|
|
172 |
if __name__ == "__main__":
|
173 |
import os
|
174 |
|
175 |
+
if (mode := os.getenv("MODE")) == "UI":
|
176 |
+
stream.ui.launch(server_port=7860, server_name="0.0.0.0")
|
177 |
+
elif mode == "PHONE":
|
178 |
stream.fastphone(host="0.0.0.0", port=7860)
|
179 |
else:
|
180 |
+
import uvicorn
|
181 |
+
|
182 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|