melkani commited on
Commit
1e06814
Β·
verified Β·
1 Parent(s): 1f0432d

Rollback to basic UI

Browse files
Files changed (1) hide show
  1. app.py +36 -98
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
- # Session ID Helpers
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 history, session_id
29
 
30
- history.append(("πŸ§‘β€πŸ’¬ You", message))
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
- reply = f"""
39
- ### πŸ” **Claim Analyzed**
40
- > *{clean_claim}*
41
 
42
- {final_report}
43
- """
 
44
 
45
- if memory_context and "No previous checks" not in memory_context:
46
- reply += f"""
47
- ---
48
- ### πŸ“œ **Your Recent Checks**
49
- {memory_context}
50
- """
51
 
52
- history.append(("πŸ€– ElderSafe", reply))
53
 
54
- return history, session_id
 
 
 
 
 
 
 
55
 
56
- # -------------------------
57
- # BUILD UI (VERSION SAFE)
58
- # -------------------------
59
  with gr.Blocks() as demo:
 
 
60
 
61
- cookie_state = gr.State({})
62
- session_box = gr.State("")
63
-
64
- gr.HTML("""
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
- # Submit via SEND button
104
- send_btn.click(
105
- eldersafe_chat,
106
- inputs=[chatbot, message_input, session_box],
107
- outputs=[chatbot, session_box],
108
- )
109
 
110
- # Reset session
111
- new_session_btn.click(
112
- reset_session,
113
- inputs=None,
114
- outputs=[session_box, chatbot, chatbot],
115
- )
116
 
117
- # Initialize session ID from cookie
118
- demo.load(
119
- get_or_create_session_id,
120
- inputs=cookie_state,
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()