BrianChuan commited on
Commit
0016aeb
·
1 Parent(s): 8a4f0ff

Optimize the User Exprence

Browse files
Files changed (1) hide show
  1. emotion.py +7 -4
emotion.py CHANGED
@@ -16,7 +16,7 @@ ANALYZE_EVERY_SEC = 0.8
16
  DOWNSAMPLE_W = 720
17
  EMA_ALPHA = 0.45
18
  CONF_TH = 40.0
19
- SWITCH_CONFIRM_SEC = 2.5
20
  IOU_TH = 0.25
21
  ZOOM_FACTOR = 1.5
22
 
@@ -92,6 +92,7 @@ class AppState:
92
 
93
  final_score: int = 3
94
 
 
95
 
96
  # =========================
97
  # UI HTML (強制黑色文字)
@@ -265,6 +266,7 @@ def _reset_state_for_camera(st: AppState) -> AppState:
265
  st.final_emo = None
266
  st.final_conf = None
267
  st.final_score = 3
 
268
  return st
269
 
270
 
@@ -273,7 +275,7 @@ def _reset_state_for_camera(st: AppState) -> AppState:
273
  # =========================
274
  def on_stream(frame_rgb: np.ndarray, st: AppState):
275
  if st.finished or (not st.running):
276
- cam_visible = False
277
 
278
  if st.final_emo:
279
  result_html = _result_card_html(st.final_emo, st.final_conf)
@@ -285,7 +287,7 @@ def on_stream(frame_rgb: np.ndarray, st: AppState):
285
  hint_html = _camera_hint_stopped()
286
 
287
  return (
288
- gr.update(visible=cam_visible),
289
  gr.update(value=result_html),
290
  gr.update(value=mood_val),
291
  gr.update(value=hint_html),
@@ -411,9 +413,10 @@ def on_stream(frame_rgb: np.ndarray, st: AppState):
411
 
412
  st.running = False
413
  st.finished = True
 
414
 
415
  return (
416
- gr.update(visible=False),
417
  gr.update(value=_result_card_html(stable_key, top_conf)),
418
  gr.update(value=_score_radio_value(EMO_TO_SCORE.get(stable_key, 3))),
419
  gr.update(value=_camera_hint_done()),
 
16
  DOWNSAMPLE_W = 720
17
  EMA_ALPHA = 0.45
18
  CONF_TH = 40.0
19
+ SWITCH_CONFIRM_SEC = 1.5
20
  IOU_TH = 0.25
21
  ZOOM_FACTOR = 1.5
22
 
 
92
 
93
  final_score: int = 3
94
 
95
+ frozen_frame: Optional[np.ndarray] = None
96
 
97
  # =========================
98
  # UI HTML (強制黑色文字)
 
266
  st.final_emo = None
267
  st.final_conf = None
268
  st.final_score = 3
269
+ st.frozen_frame = None
270
  return st
271
 
272
 
 
275
  # =========================
276
  def on_stream(frame_rgb: np.ndarray, st: AppState):
277
  if st.finished or (not st.running):
278
+ out_img = st.frozen_frame if st.frozen_frame is not None else None
279
 
280
  if st.final_emo:
281
  result_html = _result_card_html(st.final_emo, st.final_conf)
 
287
  hint_html = _camera_hint_stopped()
288
 
289
  return (
290
+ gr.update(visible=True, value=out_img),
291
  gr.update(value=result_html),
292
  gr.update(value=mood_val),
293
  gr.update(value=hint_html),
 
413
 
414
  st.running = False
415
  st.finished = True
416
+ st.frozen_frame = frame_rgb # 把現在這一幀畫面存起來
417
 
418
  return (
419
+ gr.update(visible=True, value=st.frozen_frame),
420
  gr.update(value=_result_card_html(stable_key, top_conf)),
421
  gr.update(value=_score_radio_value(EMO_TO_SCORE.get(stable_key, 3))),
422
  gr.update(value=_camera_hint_done()),