GCLing commited on
Commit
e84206e
Β·
1 Parent(s): 3fcb7be

Use gr.Interface with gr.inputs.Image for webcam support

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -2,16 +2,17 @@ import gradio as gr
2
  from deepface import DeepFace
3
 
4
  def analyze_frame(frame):
5
- # DeepFace ζŽ₯ζ”Άηš„ζ˜― RGB numpy array
6
  result = DeepFace.analyze(frame, actions=['emotion'], enforce_detection=False)
7
  return result['dominant_emotion']
8
 
9
- # Gradio Blocks εΈƒε±€
10
- with gr.Blocks() as demo:
11
- gr.Markdown("## πŸ“± ζ‰‹ζ©Ÿη€θ¦½ε™¨ε―¦ζ™‚θ‡‰ιƒ¨ζƒ…η·’εˆ†ζž")
12
- webcam = gr.Camera(label="ε°ζΊ–δ½ ηš„θ‡‰")
13
- emotion = gr.Textbox(label="θ­˜εˆ«εˆ°ηš„ζƒ…η·’")
14
- webcam.change(fn=analyze_frame, inputs=webcam, outputs=emotion)
 
15
 
16
  if __name__ == "__main__":
17
  demo.launch()
 
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()