qqwjq1981 commited on
Commit
73b4d62
·
verified ·
1 Parent(s): 120e60d

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +48 -0
  2. requirements.txt +16 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import gradio as gr
3
+
4
+ # Create FastAPI app
5
+ app = FastAPI()
6
+
7
+ # Shared data
8
+ shared_message = {"text": "Hello from FastAPI + Gradio!"}
9
+
10
+
11
+ # --- FastAPI Route ---
12
+ @app.get("/api/message")
13
+ def get_message():
14
+ """Fetch the current message."""
15
+ return {"message": shared_message["text"]}
16
+
17
+
18
+ @app.post("/api/message")
19
+ def update_message(new_message: str):
20
+ """Update the current message."""
21
+ shared_message["text"] = new_message
22
+ return {"success": True, "message": shared_message["text"]}
23
+
24
+
25
+ # --- Gradio Interface ---
26
+ def fetch_message():
27
+ return shared_message["text"]
28
+
29
+
30
+ def set_message(new_message):
31
+ shared_message["text"] = new_message
32
+ return f"Updated message: {new_message}"
33
+
34
+
35
+ with gr.Blocks() as demo:
36
+ gr.Markdown("## Simple Gradio + FastAPI Integration")
37
+ message_display = gr.Textbox(label="Current Message", value=fetch_message, interactive=False)
38
+ new_message_input = gr.Textbox(label="Set New Message")
39
+ submit_button = gr.Button("Update Message")
40
+ submit_button.click(set_message, inputs=new_message_input, outputs=message_display)
41
+
42
+ # Mount Gradio app at `/gradio`
43
+ gradio_app = gr.mount_gradio_app(app, demo, path="/gradio")
44
+
45
+ # --- Run ---
46
+ if __name__ == "__main__":
47
+ import uvicorn
48
+ uvicorn.run(app, host="0.0.0.0", port=7860)
requirements.txt ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ gradio
2
+ newspaper3k
3
+ transformers
4
+ sentence-transformers
5
+ openai
6
+ todoist-api-python
7
+ flask
8
+ twilio
9
+ fastapi
10
+ uvicorn
11
+ ffmpy
12
+ google-cloud-storage
13
+ fpdf
14
+ markdown
15
+ nest_asyncio
16
+ reportlab