Benny-Tang commited on
Commit
8f148d5
·
verified ·
1 Parent(s): b102e7d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -8
app.py CHANGED
@@ -1,12 +1,27 @@
1
- # app.py
2
- from api import api as fastapi_app, run_agent, run_all_agents
3
- from main import build_ui
4
  import gradio as gr
 
 
5
 
6
- # Build Gradio UI and mount it onto the FastAPI app at "/"
7
- blocks = build_ui(run_agent, run_all_agents)
8
- app = gr.mount_gradio_app(fastapi_app, blocks, path="/")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
 
10
- # Hugging Face Spaces will look for a variable named `app`.
11
- # No need to call .launch() or start Uvicorn manually.
12
 
 
1
+ import os
 
 
2
  import gradio as gr
3
+ import uvicorn
4
+ from fastapi import FastAPI
5
 
6
+ # --- FastAPI app ---
7
+ api = FastAPI()
8
+
9
+ @api.get("/ping")
10
+ async def ping():
11
+ return {"message": "pong"}
12
+
13
+ # --- Gradio app ---
14
+ with gr.Blocks() as demo:
15
+ gr.Markdown("# Hello from Gradio + FastAPI")
16
+ txt = gr.Textbox(label="Type something")
17
+ out = gr.Textbox(label="Echo")
18
+ txt.change(lambda x: x, txt, out)
19
+
20
+ # Mount Gradio inside FastAPI
21
+ api = gr.mount_gradio_app(api, demo, path="/")
22
+
23
+ if __name__ == "__main__":
24
+ port = int(os.environ.get("PORT", 7860)) # HF Spaces injects $PORT
25
+ uvicorn.run(api, host="0.0.0.0", port=port)
26
 
 
 
27