panda992 commited on
Commit
191f903
·
1 Parent(s): 70a0777

Add app.py and requirements.txt, update README

Browse files
README.md CHANGED
@@ -1,37 +1,19 @@
 
 
1
  ---
2
- title: Simple Echo Agent Demo
3
- emoji: 👋
4
- colorFrom: green
5
- colorTo: blue
6
- sdk: gradio
7
- sdk_version: 4.31.0 # Or your Gradio version
8
- app_file: app.py
9
  pinned: false
10
- license: apache-2.0
11
- tags:
12
- - agent-demo-track # IMPORTANT for Track 3
13
- - gradio
14
- - hackathon
15
  ---
16
 
17
- # Simple Echo Agent Demo
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 time # For a more "natural" typing simulation
 
 
 
 
 
 
 
 
 
3
 
4
- def echo_chat_function(message, history):
 
5
  """
6
- Responds to a user's message in a chat context.
7
- 'message' is the latest user input.
8
- 'history' is a list of previous [user_message, bot_message] pairs.
9
  """
10
- if not message:
11
- # In a chat, if the user sends an empty message,
12
- # you might want to prompt them or do nothing.
13
- return "Agent: Hmm, did you mean to send something?"
14
-
15
- # This is where you would put your agent's logic (e.g., LLM calls).
16
- # For now, we'll just echo with a prefix.
17
- response_prefix = "Agent Echo: "
18
- full_response = f"{response_prefix}{message}"
19
-
20
- # Simulate the agent "typing" for a better chat feel
21
- # gr.ChatInterface handles streaming if you yield partial responses
22
- partial_response = ""
23
- for char in full_response:
24
- partial_response += char
25
- time.sleep(0.03) # Small delay for each character
26
- yield partial_response # Yield intermediate parts of the response
27
-
28
- # Create the Gradio Chat Interface
29
- chat_iface = gr.ChatInterface(
30
- fn=echo_chat_function, # The Python function to call for responses
31
- chatbot=gr.Chatbot(
32
- height=400,
33
- # The deprecation warning you saw earlier is for the underlying data format.
34
- # When using ChatInterface, it generally handles this for you.
35
- # If you were manually populating a Chatbot, you'd use:
36
- # value=[{"role": "user", "content": "Hi"}], type="messages"
37
- # But ChatInterface handles this internally.
38
- ),
39
- textbox=gr.Textbox(placeholder="Type your message here and press Enter...",
40
- container=False, scale=7), # Input textbox configuration
41
- title="Simple Echo Chat Agent ",
42
- description="""
43
- This is a simple chat interface for the Agents-MCP-Hackathon.
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
- submit_btn="Send" # Text for the submit button (optional, Enter also works)
51
- )
 
 
52
 
53
- # Launch the app
54
  if __name__ == "__main__":
55
- chat_iface.launch()
 
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
- gradio
 
 
 
 
1
+ # File: requirements.txt
2
+
3
+ gradio==4.44.1
4
+ requests