3v324v23 commited on
Commit
cdbc372
·
1 Parent(s): 35626f1

refactor: update app.py to improve maintainability and performance

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -44,7 +44,9 @@ with gr.Blocks(title="Facial Expression Recognition") as demo:
44
  gr.Markdown("# 🎭 Facial Expression Recognition (RMN)")
45
  gr.Markdown(
46
  "Upload an image or use your webcam to detect facial expressions using the **Residual Masking Network (RMN)**. "
47
- "This model achieves state-of-the-art results on the FER2013 dataset."
 
 
48
  )
49
 
50
  with gr.Row():
@@ -58,7 +60,10 @@ with gr.Blocks(title="Facial Expression Recognition") as demo:
58
  output_image = gr.Image(label="Detected Result", type="numpy")
59
  output_text = gr.Textbox(label="Detection Details", lines=3)
60
 
61
- # Kết nối nút bấm với hàm xử
 
 
 
62
  btn.click(fn=detect_emotion, inputs=input_image, outputs=[output_image, output_text])
63
 
64
  # Cho phép demo các ảnh có sẵn
 
44
  gr.Markdown("# 🎭 Facial Expression Recognition (RMN)")
45
  gr.Markdown(
46
  "Upload an image or use your webcam to detect facial expressions using the **Residual Masking Network (RMN)**. "
47
+ "This model achieves state-of-the-art results on the FER2013 dataset.\n\n"
48
+ "**MẸO SỬ DỤNG WEBCAM:** Hãy bấm vào **biểu tượng chiếc máy ảnh 📷 lơ lửng giữa khung hình** để chụp. "
49
+ "Ngay sau khi bức ảnh tĩnh được chụp xong, hệ thống sẽ **tự động** phân tích khuôn mặt mà không cần bạn bấm thêm nút nào cả!"
50
  )
51
 
52
  with gr.Row():
 
60
  output_image = gr.Image(label="Detected Result", type="numpy")
61
  output_text = gr.Textbox(label="Detection Details", lines=3)
62
 
63
+ # Tự động nhận diện ngay khi ảnh được upload hoặc chụp xong từ webcam
64
+ input_image.change(fn=detect_emotion, inputs=input_image, outputs=[output_image, output_text])
65
+
66
+ # Kết nối nút bấm thủ công (phòng hờ trường hợp auto không chạy hoặc user thích tự bấm)
67
  btn.click(fn=detect_emotion, inputs=input_image, outputs=[output_image, output_text])
68
 
69
  # Cho phép demo các ảnh có sẵn