|
|
import gradio as gr |
|
|
import uuid |
|
|
import time |
|
|
from eldersafe_pipeline import run_eldersafe |
|
|
|
|
|
|
|
|
SESSION_ID = str(uuid.uuid4()) |
|
|
|
|
|
|
|
|
stats = { |
|
|
"total_checks": 0, |
|
|
"last_claim": "", |
|
|
"last_time": 0, |
|
|
} |
|
|
|
|
|
|
|
|
def new_session(): |
|
|
global SESSION_ID, stats |
|
|
SESSION_ID = str(uuid.uuid4()) |
|
|
stats = {"total_checks": 0, "last_claim": "", "last_time": 0} |
|
|
return f"π New session started!\n**Session ID:** {SESSION_ID}", format_stats() |
|
|
|
|
|
|
|
|
def format_stats(): |
|
|
return f""" |
|
|
### π Analysis Stats |
|
|
- **Total checks this session:** {stats['total_checks']} |
|
|
- **Last Claim:** {stats['last_claim'] or 'β'} |
|
|
- **Last Response Time:** {stats['last_time']:.2f} sec |
|
|
- **Session ID:** `{SESSION_ID}` |
|
|
""" |
|
|
|
|
|
|
|
|
async def eldersafe_interface(message: str): |
|
|
if not message.strip(): |
|
|
return "Please paste a WhatsApp / social media message to analyze.", format_stats() |
|
|
|
|
|
start = time.time() |
|
|
|
|
|
|
|
|
result = await run_eldersafe(message, SESSION_ID) |
|
|
|
|
|
clean_claim = result.get("clean_claim", "") |
|
|
final_report = result.get("final_report", "") |
|
|
memory_context = result.get("memory_context", "") |
|
|
|
|
|
|
|
|
stats["total_checks"] += 1 |
|
|
stats["last_claim"] = clean_claim |
|
|
stats["last_time"] = time.time() - start |
|
|
|
|
|
md = f"### π Viral Message Analyzed\n> *{clean_claim}*\n\n{final_report}\n" |
|
|
|
|
|
if memory_context and "No previous checks" not in str(memory_context): |
|
|
md += "\n---\n**π Your Recent Checks:**\n" |
|
|
md += str(memory_context) |
|
|
|
|
|
return md, format_stats() |
|
|
|
|
|
|
|
|
title = "π§ ElderSafe β Fake News Evidence Mapping Agent" |
|
|
description = """ |
|
|
Paste any WhatsApp or social media forward, and ElderSafe will: |
|
|
- Extract the main claim |
|
|
- Search for evidence |
|
|
- Provide a clear verdict |
|
|
- Explain in simple terms for elderly users |
|
|
""" |
|
|
|
|
|
with gr.Blocks() as demo: |
|
|
gr.Markdown(f"# {title}") |
|
|
gr.Markdown(description) |
|
|
|
|
|
with gr.Row(): |
|
|
new_session_btn = gr.Button("π New Session") |
|
|
stats_box = gr.Markdown(format_stats()) |
|
|
|
|
|
msg = gr.Textbox( |
|
|
label="Paste WhatsApp / Social Media Message", |
|
|
lines=6, |
|
|
placeholder="e.g. NASA has selected an Indian Ayurvedic doctor for space medicine research.", |
|
|
) |
|
|
|
|
|
output = gr.Markdown(label="Verification Report") |
|
|
|
|
|
analyze_btn = gr.Button("π Analyze Message") |
|
|
|
|
|
analyze_btn.click( |
|
|
fn=eldersafe_interface, |
|
|
inputs=msg, |
|
|
outputs=[output, stats_box], |
|
|
) |
|
|
|
|
|
new_session_btn.click( |
|
|
fn=new_session, |
|
|
inputs=[], |
|
|
outputs=[output, stats_box], |
|
|
) |
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|