GCLing commited on
Commit
7443e37
Β·
1 Parent(s): 89e98cb

Switch to gradio Blocks+components for webcam

Browse files
Files changed (1) hide show
  1. app.py +7 -8
app.py CHANGED
@@ -1,16 +1,15 @@
1
- import gradio as gr
2
  from deepface import DeepFace
3
 
4
  def analyze_frame(frame):
5
  result = DeepFace.analyze(frame, actions=['emotion'], enforce_detection=False)
6
  return result['dominant_emotion']
7
 
8
- with gr.Blocks() as demo:
9
- gr.Markdown("## πŸ“± ζ‰‹ζ©Ÿη€θ¦½ε™¨ε³ζ™‚θ‡‰ιƒ¨ζƒ…η·’εˆ†ζž")
10
- webcam = gr.Image(source="webcam", tool="editor", label="ε°ζΊ–δ½ ηš„θ‡‰")
11
- emotion = gr.Textbox(label="識εˆ₯εˆ°ηš„ζƒ…η·’")
12
- # 每欑画青更新就直ζŽ₯εˆ†ζž
13
- webcam.change(analyze_frame, inputs=webcam, outputs=emotion)
14
 
15
- if __name__ == "__main__":
16
  demo.launch()
 
1
+ from gradio import Blocks, components
2
  from deepface import DeepFace
3
 
4
  def analyze_frame(frame):
5
  result = DeepFace.analyze(frame, actions=['emotion'], enforce_detection=False)
6
  return result['dominant_emotion']
7
 
8
+ with Blocks() as demo:
9
+ demo.markdown("## πŸ“± ζ‰‹ζ©Ÿη€θ¦½ε™¨ε³ζ™‚θ‡‰ιƒ¨ζƒ…η·’εˆ†ζž")
10
+ webcam = components.Image(source="webcam", tool="editor", label="ε°ζΊ–δ½ ηš„θ‡‰")
11
+ emotion = components.Textbox(label="識εˆ₯εˆ°ηš„ζƒ…η·’")
12
+ webcam.change(fn=analyze_frame, inputs=webcam, outputs=emotion)
 
13
 
14
+ if __name__=="__main__":
15
  demo.launch()