IniNLP247 commited on
Commit
71ea6eb
·
verified ·
1 Parent(s): 193120d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -27
app.py CHANGED
@@ -96,6 +96,33 @@ current_emotion_state = {
96
  "last_update": None
97
  }
98
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  def analyze_emotion(image):
100
  """Analyze emotion from webcam image"""
101
  global current_emotion_state
@@ -451,33 +478,6 @@ with gr.Blocks(
451
  def toggle_examples():
452
  return gr.Row(visible=True)
453
 
454
- def update_emotion_status():
455
- """Update emotion status text"""
456
- if current_emotion_state["last_update"] is None:
457
- return "*Waiting for emotion data...*"
458
-
459
- elapsed = time.time() - current_emotion_state["last_update"]
460
- if elapsed > 60:
461
- return "*Emotion data outdated - please ensure webcam is active*"
462
-
463
- dominant = current_emotion_state["dominant"]
464
- confidence = current_emotion_state["confidence"]
465
- return f"**Current Emotion:** {dominant.capitalize()} ({confidence:.1f}% confidence)\n*Last updated: {int(elapsed)}s ago*"
466
-
467
- def update_threat_status():
468
- """Update threat status text"""
469
- if current_threat_state["last_update"] is None:
470
- return "*Monitoring for threats...*"
471
-
472
- elapsed = time.time() - current_threat_state["last_update"]
473
-
474
- threats = current_threat_state["threat_detected"] # Corrected variable name
475
- if threats:
476
- threat_list = ", ".join([t["type"] for t in threats])
477
- return f"**⚠️ ALERT:** {threat_list} detected\n*Last updated: {int(elapsed)}s ago*"
478
- else:
479
- return f"**✅ Safe:** No threats detected\n*Last updated: {int(elapsed)}s ago*"
480
-
481
 
482
  # Event handlers
483
  submit = msg.submit(fn=respond, inputs=[msg, chatbot], outputs=[msg, chatbot, audio_output])
 
96
  "last_update": None
97
  }
98
 
99
+ def update_emotion_status():
100
+ """Update emotion status text"""
101
+ if current_emotion_state["last_update"] is None:
102
+ return "*Waiting for emotion data...*"
103
+
104
+ elapsed = time.time() - current_emotion_state["last_update"]
105
+ if elapsed > 60:
106
+ return "*Emotion data outdated - please ensure webcam is active*"
107
+
108
+ dominant = current_emotion_state["dominant"]
109
+ confidence = current_emotion_state["confidence"]
110
+ return f"**Current Emotion:** {dominant.capitalize()} ({confidence:.1f}% confidence)\n*Last updated: {int(elapsed)}s ago*"
111
+
112
+ def update_threat_status():
113
+ """Update threat status text"""
114
+ if current_threat_state["last_update"] is None:
115
+ return "*Monitoring for threats...*"
116
+
117
+ elapsed = time.time() - current_threat_state["last_update"]
118
+
119
+ threats = current_threat_state["threat_detected"]
120
+ if threats:
121
+ threat_list = ", ".join([t["type"] for t in threats])
122
+ return f"**⚠️ ALERT:** {threat_list} detected\n*Last updated: {int(elapsed)}s ago*"
123
+ else:
124
+ return f"**✅ Safe:** No threats detected\n*Last updated: {int(elapsed)}s ago*"
125
+
126
  def analyze_emotion(image):
127
  """Analyze emotion from webcam image"""
128
  global current_emotion_state
 
478
  def toggle_examples():
479
  return gr.Row(visible=True)
480
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
 
482
  # Event handlers
483
  submit = msg.submit(fn=respond, inputs=[msg, chatbot], outputs=[msg, chatbot, audio_output])