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

Pin gradio and use Blocks+Image for webcam

Browse files
Files changed (2) hide show
  1. app.py +6 -8
  2. requirements.txt +1 -1
app.py CHANGED
@@ -2,17 +2,15 @@ import gradio as gr
2
  from deepface import DeepFace
3
 
4
  def analyze_frame(frame):
5
- # frame θΏ™ι‡Œε°±ζ˜―δ»Žζ‘„εƒε€΄ζŠ“εˆ°ηš„ numpy array
6
  result = DeepFace.analyze(frame, actions=['emotion'], enforce_detection=False)
7
  return result['dominant_emotion']
8
 
9
- demo = gr.Interface(
10
- fn=analyze_frame,
11
- inputs=gr.inputs.Image(source="webcam", label="ε°ζΊ–δ½ ηš„θ‡‰"),
12
- outputs=gr.outputs.Textbox(label="識εˆ₯εˆ°ηš„ζƒ…η·’"),
13
- title="πŸ“± ζ‰‹ζ©Ÿη€θ¦½ε™¨ε³ζ™‚θ‡‰ιƒ¨ζƒ…η·’εˆ†ζž",
14
- live=True
15
- )
16
 
17
  if __name__ == "__main__":
18
  demo.launch()
 
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()
requirements.txt CHANGED
@@ -1,4 +1,4 @@
1
- gradio
2
  deepface
3
  tensorflow
4
  opencv-python
 
1
+ gradio==3.39.0
2
  deepface
3
  tensorflow
4
  opencv-python