Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from eldersafe_pipeline import run_eldersafe
|
| 3 |
+
|
| 4 |
+
# Gradio supports async functions, so we can await the pipeline directly.
|
| 5 |
+
async def eldersafe_interface(message: str, session_id: str):
|
| 6 |
+
if not message.strip():
|
| 7 |
+
return "Please paste a WhatsApp / social media message to analyze."
|
| 8 |
+
|
| 9 |
+
if not session_id.strip():
|
| 10 |
+
session_id = "default-session"
|
| 11 |
+
|
| 12 |
+
result = await run_eldersafe(message, session_id)
|
| 13 |
+
|
| 14 |
+
clean_claim = result.get("clean_claim", "")
|
| 15 |
+
final_report = result.get("final_report", "")
|
| 16 |
+
memory_context = result.get("memory_context", "")
|
| 17 |
+
|
| 18 |
+
md = f"### 🔍 Viral Message Analyzed\n> *{clean_claim}*\n\n"
|
| 19 |
+
md += f"{final_report}\n"
|
| 20 |
+
|
| 21 |
+
if memory_context and "No previous checks" not in str(memory_context):
|
| 22 |
+
md += "\n---\n**📜 Your Recent Checks:**\n"
|
| 23 |
+
md += str(memory_context)
|
| 24 |
+
|
| 25 |
+
return md
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
title = "🧓 ElderSafe – Fake News Evidence Mapping Agent"
|
| 29 |
+
description = """
|
| 30 |
+
Paste any WhatsApp or social media forward, and ElderSafe will:
|
| 31 |
+
- Extract the main claim
|
| 32 |
+
- Search for evidence
|
| 33 |
+
- Show a clear verdict
|
| 34 |
+
- Explain it in simple terms for elderly users
|
| 35 |
+
"""
|
| 36 |
+
|
| 37 |
+
with gr.Blocks() as demo:
|
| 38 |
+
gr.Markdown(f"# {title}")
|
| 39 |
+
gr.Markdown(description)
|
| 40 |
+
|
| 41 |
+
with gr.Row():
|
| 42 |
+
msg = gr.Textbox(
|
| 43 |
+
label="Paste WhatsApp / Social Media Message",
|
| 44 |
+
lines=6,
|
| 45 |
+
placeholder="e.g. NASA has selected an Indian Ayurvedic doctor for space medicine research.",
|
| 46 |
+
)
|
| 47 |
+
session_id = gr.Textbox(
|
| 48 |
+
label="Session ID (optional)",
|
| 49 |
+
value="nasa-session-v2",
|
| 50 |
+
placeholder="Use same ID to keep history together",
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
output = gr.Markdown(label="Verification Report")
|
| 54 |
+
|
| 55 |
+
analyze_btn = gr.Button("🔎 Analyze Message")
|
| 56 |
+
|
| 57 |
+
analyze_btn.click(
|
| 58 |
+
fn=eldersafe_interface,
|
| 59 |
+
inputs=[msg, session_id],
|
| 60 |
+
outputs=output,
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
demo.launch()
|