BrianChuan commited on
Commit
6e2e7f5
·
1 Parent(s): ca2aba8

Optimize the User process

Browse files
Files changed (2) hide show
  1. app.py +14 -5
  2. emotion.py +1 -1
app.py CHANGED
@@ -162,7 +162,7 @@ def _score_to_radio_value(score):
162
 
163
  def bridge_start_click(st):
164
  res = emotion.on_restart(st)
165
- return res[1], res[0], gr.update(visible=True), res[5], res[4]
166
 
167
  def bridge_stop_click(st):
168
  res = emotion.on_stop(st)
@@ -172,14 +172,16 @@ def bridge_predict_frame(frame, st):
172
  res = emotion.on_stream(frame, st)
173
  out_cam = res[0]; out_result = res[1]; out_st = res[4]; out_btn_start = res[5]
174
  score_update = gr.update(); tabs_update = gr.update(); out_btn_stop = gr.update()
 
 
175
 
176
  if out_st.finished and hasattr(out_st, 'final_score'):
177
  new_val = _score_to_radio_value(out_st.final_score)
178
  score_update = gr.update(value=new_val)
179
- tabs_update = gr.Tabs(selected=1)
180
  out_btn_stop = gr.update(visible=False)
 
181
 
182
- return out_cam, out_result, out_st, out_btn_stop, out_btn_start, score_update, tabs_update
183
 
184
 
185
  # ==========================================
@@ -204,6 +206,7 @@ with gr.Blocks(title="AI 心情食堂", css=css_) as demo:
204
 
205
  cam = gr.Image(sources=["webcam"], streaming=True, type="numpy", label="攝影機畫面", visible=False)
206
  result_markdown = gr.Markdown(emotion._hint_html("請按「開啟攝影機辨識」並允許瀏覽器使用相機。"))
 
207
 
208
  # Tab 2: 主功能區
209
  with gr.TabItem("🍽️ AI 心情食堂 (Step 2)", id=1):
@@ -236,7 +239,7 @@ with gr.Blocks(title="AI 心情食堂", css=css_) as demo:
236
  btn_start.click(
237
  fn=bridge_start_click,
238
  inputs=[st_state],
239
- outputs=[result_markdown, cam, btn_stop, btn_start, st_state],
240
  show_progress="minimal"
241
  )
242
 
@@ -250,10 +253,16 @@ with gr.Blocks(title="AI 心情食堂", css=css_) as demo:
250
  cam.stream(
251
  fn=bridge_predict_frame,
252
  inputs=[cam, st_state],
253
- outputs=[cam, result_markdown, st_state, btn_stop, btn_start, score_input, tabs],
254
  show_progress="minimal"
255
  )
256
 
 
 
 
 
 
 
257
  submit_btn.click(
258
  fn=mood_agent_logic,
259
  inputs=[score_input, food_input, diary_input],
 
162
 
163
  def bridge_start_click(st):
164
  res = emotion.on_restart(st)
165
+ return res[1], res[0], gr.update(visible=True), res[5], res[4], gr.update(visible=False)
166
 
167
  def bridge_stop_click(st):
168
  res = emotion.on_stop(st)
 
172
  res = emotion.on_stream(frame, st)
173
  out_cam = res[0]; out_result = res[1]; out_st = res[4]; out_btn_start = res[5]
174
  score_update = gr.update(); tabs_update = gr.update(); out_btn_stop = gr.update()
175
+ out_btn_stop = gr.update()
176
+ btn_go_visible = gr.update(visible=False)
177
 
178
  if out_st.finished and hasattr(out_st, 'final_score'):
179
  new_val = _score_to_radio_value(out_st.final_score)
180
  score_update = gr.update(value=new_val)
 
181
  out_btn_stop = gr.update(visible=False)
182
+ btn_go_visible = gr.update(visible=True)
183
 
184
+ return out_cam, out_result, out_st, out_btn_stop, out_btn_start, score_update, tabs_update, btn_go_visible
185
 
186
 
187
  # ==========================================
 
206
 
207
  cam = gr.Image(sources=["webcam"], streaming=True, type="numpy", label="攝影機畫面", visible=False)
208
  result_markdown = gr.Markdown(emotion._hint_html("請按「開啟攝影機辨識」並允許瀏覽器使用相機。"))
209
+ btn_go_dining = gr.Button("🚀 確定心情,來找餐廳!", variant="primary", visible=False, size="lg")
210
 
211
  # Tab 2: 主功能區
212
  with gr.TabItem("🍽️ AI 心情食堂 (Step 2)", id=1):
 
239
  btn_start.click(
240
  fn=bridge_start_click,
241
  inputs=[st_state],
242
+ outputs=[result_markdown, cam, btn_stop, btn_start, st_state, btn_go_dining],
243
  show_progress="minimal"
244
  )
245
 
 
253
  cam.stream(
254
  fn=bridge_predict_frame,
255
  inputs=[cam, st_state],
256
+ outputs=[cam, result_markdown, st_state, btn_stop, btn_start, score_input, btn_go_dining],
257
  show_progress="minimal"
258
  )
259
 
260
+ btn_go_dining.click(
261
+ fn=lambda: gr.Tabs(selected=1),
262
+ inputs=None,
263
+ outputs=tabs
264
+ )
265
+
266
  submit_btn.click(
267
  fn=mood_agent_logic,
268
  inputs=[score_input, food_input, diary_input],
emotion.py CHANGED
@@ -150,7 +150,7 @@ def _result_card_html(emo_key: str, conf: Optional[float]) -> str:
150
  </div>
151
 
152
  <div style="font-size:16px;color:#000000;margin-bottom:6px;">
153
- 心情分數:<b>{score}</b>({score_desc})
154
  </div>
155
 
156
  <div style="font-size:14px;color:#000000;">
 
150
  </div>
151
 
152
  <div style="font-size:16px;color:#000000;margin-bottom:6px;">
153
+ 心情分數:{score}({score_desc})
154
  </div>
155
 
156
  <div style="font-size:14px;color:#000000;">