File size: 2,645 Bytes
1f0432d a624888 1f0432d a624888 1e06814 1f0432d a624888 1e06814 1f0432d a624888 1f0432d a624888 1e06814 1f0432d a624888 1f0432d 1e06814 1f0432d a624888 1f0432d 1e06814 a624888 1e06814 1f0432d 727484b 1e06814 f0a8626 a624888 1e06814 f0a8626 1e06814 f0a8626 1e06814 f0a8626 1e06814 a624888 f0a8626 1e06814 a624888 1e06814 a624888 |
1 2 3 4 5 6 7 8 9 10 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
import gradio as gr
import uuid
import time
from eldersafe_pipeline import run_eldersafe
# GLOBAL session state
SESSION_ID = str(uuid.uuid4())
# STATS
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()
# Use current session ID
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", "")
# Update stats
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()
|