Rollback to basic UI
Browse files
app.py
CHANGED
|
@@ -2,121 +2,59 @@ import gradio as gr
|
|
| 2 |
import uuid
|
| 3 |
from eldersafe_pipeline import run_eldersafe
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
# -------------------------
|
| 9 |
-
def get_or_create_session_id(cookie):
|
| 10 |
-
if cookie and "session_id" in cookie:
|
| 11 |
-
return cookie["session_id"]
|
| 12 |
-
return str(uuid.uuid4())
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def reset_session():
|
| 16 |
-
return (
|
| 17 |
-
str(uuid.uuid4()),
|
| 18 |
-
[],
|
| 19 |
-
"",
|
| 20 |
-
)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# -------------------------
|
| 24 |
-
# Main chat handler
|
| 25 |
-
# -------------------------
|
| 26 |
-
async def eldersafe_chat(history, message, session_id):
|
| 27 |
if not message.strip():
|
| 28 |
-
return
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
result = await run_eldersafe(message, session_id)
|
| 33 |
|
| 34 |
clean_claim = result.get("clean_claim", "")
|
| 35 |
final_report = result.get("final_report", "")
|
| 36 |
memory_context = result.get("memory_context", "")
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
> *{clean_claim}*
|
| 41 |
|
| 42 |
-
|
| 43 |
-
""
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
reply += f"""
|
| 47 |
-
---
|
| 48 |
-
### π **Your Recent Checks**
|
| 49 |
-
{memory_context}
|
| 50 |
-
"""
|
| 51 |
|
| 52 |
-
history.append(("π€ ElderSafe", reply))
|
| 53 |
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
# -------------------------
|
| 57 |
-
# BUILD UI (VERSION SAFE)
|
| 58 |
-
# -------------------------
|
| 59 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
<div style="text-align:center; padding:18px; font-family: sans-serif;">
|
| 66 |
-
<h1 style="color:#008080; margin-bottom: 6px;">π‘οΈ ElderSafe</h1>
|
| 67 |
-
<h3 style="color:#444; margin-top:0;">Fake News Evidence Mapping Assistant</h3>
|
| 68 |
-
<p style="color:#666; font-size:15px;">
|
| 69 |
-
A warm, simple WhatsApp-like chat to help verify WhatsApp forwards.
|
| 70 |
-
</p>
|
| 71 |
-
</div>
|
| 72 |
-
""")
|
| 73 |
-
|
| 74 |
-
with gr.Row():
|
| 75 |
-
new_session_btn = gr.Button("π New Analysis")
|
| 76 |
-
|
| 77 |
-
chatbot = gr.Chatbot(label="ElderSafe Assistant")
|
| 78 |
-
|
| 79 |
-
# -------------------------
|
| 80 |
-
# FLOATING SEND BUTTON (Option C)
|
| 81 |
-
# -------------------------
|
| 82 |
-
with gr.Row():
|
| 83 |
-
message_input = gr.Textbox(
|
| 84 |
-
placeholder="Paste any WhatsApp message hereβ¦",
|
| 85 |
-
label="Your Message",
|
| 86 |
-
lines=3,
|
| 87 |
-
scale=8, # makes textbox wider
|
| 88 |
-
)
|
| 89 |
-
|
| 90 |
-
send_btn = gr.Button(
|
| 91 |
-
"Send",
|
| 92 |
-
variant="primary",
|
| 93 |
-
scale=1 # keeps button small and floating-like
|
| 94 |
-
)
|
| 95 |
-
|
| 96 |
-
# Submit via ENTER
|
| 97 |
-
message_input.submit(
|
| 98 |
-
eldersafe_chat,
|
| 99 |
-
inputs=[chatbot, message_input, session_box],
|
| 100 |
-
outputs=[chatbot, session_box],
|
| 101 |
)
|
| 102 |
|
| 103 |
-
|
| 104 |
-
send_btn.click(
|
| 105 |
-
eldersafe_chat,
|
| 106 |
-
inputs=[chatbot, message_input, session_box],
|
| 107 |
-
outputs=[chatbot, session_box],
|
| 108 |
-
)
|
| 109 |
|
| 110 |
-
|
| 111 |
-
new_session_btn.click(
|
| 112 |
-
reset_session,
|
| 113 |
-
inputs=None,
|
| 114 |
-
outputs=[session_box, chatbot, chatbot],
|
| 115 |
-
)
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
outputs=session_box,
|
| 122 |
)
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import uuid
|
| 3 |
from eldersafe_pipeline import run_eldersafe
|
| 4 |
|
| 5 |
+
# Generate one session ID per app run
|
| 6 |
+
SESSION_ID = str(uuid.uuid4())
|
| 7 |
|
| 8 |
+
# Gradio supports async functions, so we can await the pipeline directly.
|
| 9 |
+
async def eldersafe_interface(message: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
if not message.strip():
|
| 11 |
+
return "Please paste a WhatsApp / social media message to analyze."
|
| 12 |
|
| 13 |
+
# Use auto-generated session ID for all calls
|
| 14 |
+
result = await run_eldersafe(message, SESSION_ID)
|
|
|
|
| 15 |
|
| 16 |
clean_claim = result.get("clean_claim", "")
|
| 17 |
final_report = result.get("final_report", "")
|
| 18 |
memory_context = result.get("memory_context", "")
|
| 19 |
|
| 20 |
+
md = f"### π Viral Message Analyzed\n> *{clean_claim}*\n\n"
|
| 21 |
+
md += f"{final_report}\n"
|
|
|
|
| 22 |
|
| 23 |
+
if memory_context and "No previous checks" not in str(memory_context):
|
| 24 |
+
md += "\n---\n**π Your Recent Checks:**\n"
|
| 25 |
+
md += str(memory_context)
|
| 26 |
|
| 27 |
+
return md
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
|
|
|
| 29 |
|
| 30 |
+
title = "π§ ElderSafe β Fake News Evidence Mapping Agent"
|
| 31 |
+
description = """
|
| 32 |
+
Paste any WhatsApp or social media forward, and ElderSafe will:
|
| 33 |
+
- Extract the main claim
|
| 34 |
+
- Search for evidence
|
| 35 |
+
- Show a clear verdict
|
| 36 |
+
- Explain it in simple terms for elderly users
|
| 37 |
+
"""
|
| 38 |
|
|
|
|
|
|
|
|
|
|
| 39 |
with gr.Blocks() as demo:
|
| 40 |
+
gr.Markdown(f"# {title}")
|
| 41 |
+
gr.Markdown(description)
|
| 42 |
|
| 43 |
+
msg = gr.Textbox(
|
| 44 |
+
label="Paste WhatsApp / Social Media Message",
|
| 45 |
+
lines=6,
|
| 46 |
+
placeholder="e.g. NASA has selected an Indian Ayurvedic doctor for space medicine research.",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
)
|
| 48 |
|
| 49 |
+
output = gr.Markdown(label="Verification Report")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
analyze_btn = gr.Button("π Analyze Message")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
+
analyze_btn.click(
|
| 54 |
+
fn=eldersafe_interface,
|
| 55 |
+
inputs=msg,
|
| 56 |
+
outputs=output,
|
|
|
|
| 57 |
)
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
demo.launch()
|