melkani commited on
Commit
a624888
Β·
verified Β·
1 Parent(s): fcd00ea

Test UI update check

Browse files
Files changed (1) hide show
  1. app.py +55 -17
app.py CHANGED
@@ -1,45 +1,80 @@
1
  import gradio as gr
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,
@@ -53,12 +88,15 @@ with gr.Blocks() as demo:
53
  analyze_btn.click(
54
  fn=eldersafe_interface,
55
  inputs=msg,
56
- outputs=output,
57
  )
58
 
 
 
 
 
 
 
 
59
  if __name__ == "__main__":
60
- debug = False
61
- if debug:
62
- print("Debug mode, not launching")
63
- else:
64
- demo.launch()
 
1
  import gradio as gr
2
  import uuid
3
+ import time
4
  from eldersafe_pipeline import run_eldersafe
5
 
6
+ # GLOBAL session state
7
  SESSION_ID = str(uuid.uuid4())
8
 
9
+ # STATS
10
+ stats = {
11
+ "total_checks": 0,
12
+ "last_claim": "",
13
+ "last_time": 0,
14
+ }
15
+
16
+
17
+ def new_session():
18
+ global SESSION_ID, stats
19
+ SESSION_ID = str(uuid.uuid4())
20
+ stats = {"total_checks": 0, "last_claim": "", "last_time": 0}
21
+ return f"πŸ”„ New session started!\n**Session ID:** {SESSION_ID}", format_stats()
22
+
23
+
24
+ def format_stats():
25
+ return f"""
26
+ ### πŸ“Š Analysis Stats
27
+ - **Total checks this session:** {stats['total_checks']}
28
+ - **Last Claim:** {stats['last_claim'] or 'β€”'}
29
+ - **Last Response Time:** {stats['last_time']:.2f} sec
30
+ - **Session ID:** `{SESSION_ID}`
31
+ """
32
+
33
+
34
  async def eldersafe_interface(message: str):
35
  if not message.strip():
36
+ return "Please paste a WhatsApp / social media message to analyze.", format_stats()
37
 
38
+ start = time.time()
39
+
40
+ # Use current session ID
41
  result = await run_eldersafe(message, SESSION_ID)
42
 
43
  clean_claim = result.get("clean_claim", "")
44
  final_report = result.get("final_report", "")
45
  memory_context = result.get("memory_context", "")
46
 
47
+ # Update stats
48
+ stats["total_checks"] += 1
49
+ stats["last_claim"] = clean_claim
50
+ stats["last_time"] = time.time() - start
51
+
52
+ md = f"### πŸ” Viral Message Analyzed\n> *{clean_claim}*\n\n{final_report}\n"
53
 
54
  if memory_context and "No previous checks" not in str(memory_context):
55
  md += "\n---\n**πŸ“œ Your Recent Checks:**\n"
56
  md += str(memory_context)
57
 
58
+ return md, format_stats()
59
 
60
 
61
  title = "πŸ§“ ElderSafe – Fake News Evidence Mapping Agent"
62
  description = """
63
  Paste any WhatsApp or social media forward, and ElderSafe will:
64
+ - Extract the main claim
65
+ - Search for evidence
66
+ - Provide a clear verdict
67
+ - Explain in simple terms for elderly users
68
  """
69
 
70
  with gr.Blocks() as demo:
71
  gr.Markdown(f"# {title}")
72
  gr.Markdown(description)
73
 
74
+ with gr.Row():
75
+ new_session_btn = gr.Button("πŸ†• New Session")
76
+ stats_box = gr.Markdown(format_stats())
77
+
78
  msg = gr.Textbox(
79
  label="Paste WhatsApp / Social Media Message",
80
  lines=6,
 
88
  analyze_btn.click(
89
  fn=eldersafe_interface,
90
  inputs=msg,
91
+ outputs=[output, stats_box],
92
  )
93
 
94
+ new_session_btn.click(
95
+ fn=new_session,
96
+ inputs=[],
97
+ outputs=[output, stats_box],
98
+ )
99
+
100
+
101
  if __name__ == "__main__":
102
+ demo.launch()