Spaces:
Sleeping
Sleeping
Add app.py and requirements.txt, update README
Browse files- README.md +14 -32
- __pycache__/get_started.cpython-312.pyc +0 -0
- __pycache__/modal_backend.cpython-312.pyc +0 -0
- app.py +55 -48
- requirements.txt +4 -1
README.md
CHANGED
@@ -1,37 +1,19 @@
|
|
|
|
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
-
sdk: gradio
|
7 |
-
|
8 |
-
app_file: app.py
|
9 |
pinned: false
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
- gradio
|
14 |
-
- hackathon
|
15 |
---
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
**Hackathon Track:** Agentic Demo Showcase (`agent-demo-track`)
|
20 |
-
|
21 |
-
## Description
|
22 |
-
|
23 |
-
This is a very simple Gradio app for the Agents-MCP-Hackathon.
|
24 |
-
It demonstrates a basic "agent" that just echoes back whatever you type, with a prefix.
|
25 |
-
|
26 |
-
## How to Use
|
27 |
-
|
28 |
-
1. Type a message in the input box.
|
29 |
-
2. Click the "Echo Message" button.
|
30 |
-
3. See the agent's response.
|
31 |
-
|
32 |
-
## Video Overview
|
33 |
-
|
34 |
-
* **[YOUR VIDEO LINK HERE]** - *You MUST create a short video showing your app and link it here.*
|
35 |
-
* _Example: A screen recording of you typing and seeing the echo._
|
36 |
|
37 |
-
|
|
|
1 |
+
# File: README.md
|
2 |
+
|
3 |
---
|
4 |
+
title: "GHAPA: Intelligent Health AI Assistant"
|
5 |
+
emoji: "🧠⚡"
|
6 |
+
colorFrom: "blue"
|
7 |
+
colorTo: "green"
|
8 |
+
sdk: "gradio"
|
9 |
+
app_file: "app.py"
|
|
|
10 |
pinned: false
|
11 |
+
# This app runs on the free CPU tier, as all heavy work is done by Modal
|
12 |
+
secrets:
|
13 |
+
- MODAL_BACKEND_URL
|
|
|
|
|
14 |
---
|
15 |
|
16 |
+
# 🧠 GHAPA: Intelligent Health AI Assistant (Powered by Modal ⚡)
|
17 |
+
This is the user interface for the GHAPA system. It provides a simple, responsive UI that communicates with a powerful, GPU-accelerated backend hosted on Modal Labs.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
Ask your health question in **English, Spanish, Hindi, or French**. The system will auto-detect your language, find the most relevant PubMed article, and provide a trusted answer at high speed.
|
__pycache__/get_started.cpython-312.pyc
ADDED
Binary file (802 Bytes). View file
|
|
__pycache__/modal_backend.cpython-312.pyc
ADDED
Binary file (12.5 kB). View file
|
|
app.py
CHANGED
@@ -1,55 +1,62 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
-
|
|
|
5 |
"""
|
6 |
-
|
7 |
-
|
8 |
-
'history' is a list of previous [user_message, bot_message] pairs.
|
9 |
"""
|
10 |
-
if not
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
#
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
)
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
Type a message, and the 'agent' will echo it back.
|
45 |
-
This version includes specific button configurations suitable for newer Gradio versions.
|
46 |
-
""",
|
47 |
-
examples=[["Hello!"], ["How are you today?"]], # Example prompts
|
48 |
-
cache_examples=False, # Don't cache examples for dynamic functions usually
|
49 |
|
50 |
-
|
51 |
-
|
|
|
|
|
52 |
|
53 |
-
# Launch the app
|
54 |
if __name__ == "__main__":
|
55 |
-
|
|
|
1 |
+
# File: app.py
|
2 |
+
|
3 |
import gradio as gr
|
4 |
+
import requests
|
5 |
+
import os
|
6 |
+
|
7 |
+
# --- Configuration ---
|
8 |
+
# This securely retrieves the backend URL from the Hugging Face Space secret.
|
9 |
+
MODAL_BACKEND_URL = os.getenv("MODAL_BACKEND_URL")
|
10 |
+
|
11 |
+
# A critical check to ensure the secret is set. The app will not start without it.
|
12 |
+
if not MODAL_BACKEND_URL:
|
13 |
+
raise ValueError("The MODAL_BACKEND_URL secret is not set in your Hugging Face Space! Please add it in the Settings tab.")
|
14 |
|
15 |
+
# This function is the bridge between your Gradio UI and your Modal backend.
|
16 |
+
def call_modal_backend(user_input: str):
|
17 |
"""
|
18 |
+
Takes the user's input, sends it to the Modal backend via an HTTP POST
|
19 |
+
request, and returns the final markdown response.
|
|
|
20 |
"""
|
21 |
+
if not user_input or not user_input.strip():
|
22 |
+
return "Please enter a question to get started."
|
23 |
+
|
24 |
+
# Prepare the request headers and payload
|
25 |
+
headers = {"Content-Type": "application/json"}
|
26 |
+
payload = {"user_input": user_input}
|
27 |
+
|
28 |
+
try:
|
29 |
+
# Make the POST request to the Modal serverless function
|
30 |
+
response = requests.post(MODAL_BACKEND_URL, headers=headers, json=payload, timeout=300)
|
31 |
+
|
32 |
+
# Raise an exception for bad HTTP status codes (like 404 or 500)
|
33 |
+
response.raise_for_status()
|
34 |
+
|
35 |
+
# Parse the JSON response from the backend
|
36 |
+
result = response.json()
|
37 |
+
|
38 |
+
# Safely get the final markdown. If the key is missing, return an error.
|
39 |
+
return result.get("final_markdown", "### ❗ Error\nReceived an unexpected response format from the backend.")
|
40 |
+
|
41 |
+
except requests.exceptions.Timeout:
|
42 |
+
return "### ❗ Error: The request timed out. The AI backend may be busy or starting up. Please try again in a moment."
|
43 |
+
except requests.exceptions.RequestException as e:
|
44 |
+
# Handle any other network errors (e.g., connection failed)
|
45 |
+
return f"### ❗ Error: Could not connect to the AI backend.\n**Details**: {e}"
|
46 |
+
|
47 |
+
# --- Gradio User Interface ---
|
48 |
+
with gr.Blocks(theme=gr.themes.Soft(), css="footer {display: none !important}") as demo:
|
49 |
+
gr.Markdown("""# 🧠 GHAPA: Intelligent Health AI Assistant (Powered by Modal ⚡)
|
50 |
+
Ask your health question in **English, Spanish, Hindi, or French**. The system fetches trusted PubMed answers at high speed.""")
|
51 |
+
|
52 |
+
with gr.Row():
|
53 |
+
inp = gr.Textbox(label="Enter your question", placeholder="e.g., 'What are the symptoms of dengue?'", scale=4)
|
54 |
+
btn = gr.Button("Submit", variant="primary", scale=1)
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
+
o5 = gr.Markdown(label="Answer & Explanation")
|
57 |
+
|
58 |
+
# The click function is now simple and calls our backend function.
|
59 |
+
btn.click(fn=call_modal_backend, inputs=[inp], outputs=[o5])
|
60 |
|
|
|
61 |
if __name__ == "__main__":
|
62 |
+
demo.launch()
|
requirements.txt
CHANGED
@@ -1 +1,4 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
1 |
+
# File: requirements.txt
|
2 |
+
|
3 |
+
gradio==4.44.1
|
4 |
+
requests
|