Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import gradio as gr
|
|
| 8 |
import numpy as np
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
from elevenlabs import ElevenLabs
|
|
|
|
| 11 |
from fastapi.responses import HTMLResponse, StreamingResponse
|
| 12 |
from fastrtc import AdditionalOutputs, ReplyOnPause, Stream, get_twilio_turn_credentials
|
| 13 |
from fastrtc.utils import aggregate_bytes_to_16bit, audio_to_bytes
|
|
@@ -101,7 +102,12 @@ class InputData(BaseModel):
|
|
| 101 |
chatbot: list[Message]
|
| 102 |
|
| 103 |
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
async def _():
|
| 106 |
rtc_config = get_twilio_turn_credentials() if get_space() else None
|
| 107 |
html_content = (curr_dir / "index.html").read_text()
|
|
@@ -109,13 +115,13 @@ async def _():
|
|
| 109 |
return HTMLResponse(content=html_content, status_code=200)
|
| 110 |
|
| 111 |
|
| 112 |
-
@
|
| 113 |
async def _(body: InputData):
|
| 114 |
stream.set_input(body.webrtc_id, body.model_dump()["chatbot"])
|
| 115 |
return {"status": "ok"}
|
| 116 |
|
| 117 |
|
| 118 |
-
@
|
| 119 |
def _(webrtc_id: str):
|
| 120 |
print("outputs", webrtc_id)
|
| 121 |
|
|
@@ -129,6 +135,13 @@ def _(webrtc_id: str):
|
|
| 129 |
|
| 130 |
|
| 131 |
if __name__ == "__main__":
|
| 132 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
-
|
|
|
|
| 8 |
import numpy as np
|
| 9 |
from dotenv import load_dotenv
|
| 10 |
from elevenlabs import ElevenLabs
|
| 11 |
+
from fastapi import FastAPI
|
| 12 |
from fastapi.responses import HTMLResponse, StreamingResponse
|
| 13 |
from fastrtc import AdditionalOutputs, ReplyOnPause, Stream, get_twilio_turn_credentials
|
| 14 |
from fastrtc.utils import aggregate_bytes_to_16bit, audio_to_bytes
|
|
|
|
| 102 |
chatbot: list[Message]
|
| 103 |
|
| 104 |
|
| 105 |
+
app = FastAPI()
|
| 106 |
+
|
| 107 |
+
stream.mount(app)
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
@app.get("/")
|
| 111 |
async def _():
|
| 112 |
rtc_config = get_twilio_turn_credentials() if get_space() else None
|
| 113 |
html_content = (curr_dir / "index.html").read_text()
|
|
|
|
| 115 |
return HTMLResponse(content=html_content, status_code=200)
|
| 116 |
|
| 117 |
|
| 118 |
+
@app.post("/input_hook")
|
| 119 |
async def _(body: InputData):
|
| 120 |
stream.set_input(body.webrtc_id, body.model_dump()["chatbot"])
|
| 121 |
return {"status": "ok"}
|
| 122 |
|
| 123 |
|
| 124 |
+
@app.get("/outputs")
|
| 125 |
def _(webrtc_id: str):
|
| 126 |
print("outputs", webrtc_id)
|
| 127 |
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
if __name__ == "__main__":
|
| 138 |
+
import os
|
| 139 |
+
|
| 140 |
+
if (mode := os.getenv("MODE")) == "UI":
|
| 141 |
+
stream.ui.launch(server_port=7860, server_name="0.0.0.0")
|
| 142 |
+
elif mode == "PHONE":
|
| 143 |
+
stream.fastphone(host="0.0.0.0", port=7860)
|
| 144 |
+
else:
|
| 145 |
+
import uvicorn
|
| 146 |
|
| 147 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|