GCLing commited on
Commit
5d86a34
Β·
1 Parent(s): 7443e37

Switch to gr.Interface webcam version

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -1,15 +1,19 @@
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()
 
 
1
+ import gradio as gr
2
  from deepface import DeepFace
3
 
4
  def analyze_frame(frame):
5
+ # frame: numpy array from webcam
6
  result = DeepFace.analyze(frame, actions=['emotion'], enforce_detection=False)
7
  return result['dominant_emotion']
8
 
9
+ iface = gr.Interface(
10
+ fn=analyze_frame,
11
+ inputs=gr.Image(source="webcam", type="numpy", label="θ«‹ε°ζΊ–δ½ ηš„θ‡‰"),
12
+ outputs="text",
13
+ title="πŸ“± ζ‰‹ζ©Ÿη€θ¦½ε™¨ε³ζ™‚θ‡‰ιƒ¨ζƒ…η·’εˆ†ζž",
14
+ live=True
15
+ )
16
 
17
  if __name__=="__main__":
18
+ # 运葌在 0.0.0.0:7860,Spaces 会转到 HTTPS 443
19
+ iface.launch(server_name="0.0.0.0", server_port=7860)