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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -1,27 +1,26 @@
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
 
 
 
1
  import os
 
2
  import uvicorn
3
  from fastapi import FastAPI
4
+ import gradio as gr
5
 
 
6
  api = FastAPI()
7
 
8
  @api.get("/ping")
9
  async def ping():
10
  return {"message": "pong"}
11
 
 
12
  with gr.Blocks() as demo:
13
+ gr.Markdown("## Gradio + FastAPI running in HF Spaces")
14
+ msg = gr.Textbox()
15
+ out = gr.Textbox()
16
+ msg.change(lambda x: f"You typed: {x}", msg, out)
17
 
18
+ # Mount gradio at root
19
  api = gr.mount_gradio_app(api, demo, path="/")
20
 
21
  if __name__ == "__main__":
22
+ port = int(os.environ.get("PORT", 7860)) # 👈 use HF Spaces port
23
  uvicorn.run(api, host="0.0.0.0", port=port)
24
 
25
 
26
+