qqwjq1981 commited on
Commit
7b7ca24
·
verified ·
1 Parent(s): 73b4d62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -42
app.py CHANGED
@@ -1,48 +1,16 @@
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)
 
1
+ from fastapi import FastAPI, Request
2
+ import uvicorn
3
 
4
+ # Initialize FastAPI app
5
  app = FastAPI()
6
 
7
+ # FastAPI route to handle WhatsApp webhook
8
+ @app.post("/whatsapp-webhook")
9
+ async def whatsapp_webhook(request: Request):
10
+ data = await request.json() # Parse incoming JSON data
11
+ print(f"Received data: {data}") # Log incoming data for debugging
12
+ return {"status": "success", "received_data": data}
13
 
14
+ # Run the FastAPI app with Uvicorn
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  if __name__ == "__main__":
 
16
  uvicorn.run(app, host="0.0.0.0", port=7860)