freddyaboulton HF staff commited on
Commit
7c79caf
·
verified ·
1 Parent(s): 98011ab

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -7,6 +7,7 @@ import gradio as gr
7
  import numpy as np
8
  import openai
9
  from dotenv import load_dotenv
 
10
  from fastapi.responses import HTMLResponse, StreamingResponse
11
  from fastrtc import (
12
  AdditionalOutputs,
@@ -119,8 +120,12 @@ stream = Stream(
119
  concurrency_limit=20 if get_space() else None,
120
  )
121
 
 
122
 
123
- @stream.get("/")
 
 
 
124
  async def _():
125
  rtc_config = get_twilio_turn_credentials() if get_space() else None
126
  html_content = (cur_dir / "index.html").read_text()
@@ -128,7 +133,7 @@ async def _():
128
  return HTMLResponse(content=html_content)
129
 
130
 
131
- @stream.get("/outputs")
132
  def _(webrtc_id: str):
133
  async def output_stream():
134
  import json
@@ -141,6 +146,13 @@ def _(webrtc_id: str):
141
 
142
 
143
  if __name__ == "__main__":
144
- import uvicorn
 
 
 
 
 
 
 
145
 
146
- uvicorn.run(stream, host="0.0.0.0", port=7860)
 
7
  import numpy as np
8
  import openai
9
  from dotenv import load_dotenv
10
+ from fastapi import FastAPI
11
  from fastapi.responses import HTMLResponse, StreamingResponse
12
  from fastrtc import (
13
  AdditionalOutputs,
 
120
  concurrency_limit=20 if get_space() else None,
121
  )
122
 
123
+ app = FastAPI()
124
 
125
+ stream.mount(app)
126
+
127
+
128
+ @app.get("/")
129
  async def _():
130
  rtc_config = get_twilio_turn_credentials() if get_space() else None
131
  html_content = (cur_dir / "index.html").read_text()
 
133
  return HTMLResponse(content=html_content)
134
 
135
 
136
+ @app.get("/outputs")
137
  def _(webrtc_id: str):
138
  async def output_stream():
139
  import json
 
146
 
147
 
148
  if __name__ == "__main__":
149
+ import os
150
+
151
+ if (mode := os.getenv("MODE")) == "UI":
152
+ stream.ui.launch(server_port=7860, server_name="0.0.0.0")
153
+ elif mode == "PHONE":
154
+ stream.fastphone(host="0.0.0.0", port=7860)
155
+ else:
156
+ import uvicorn
157
 
158
+ uvicorn.run(app, host="0.0.0.0", port=7860)