YanagiKp commited on
Commit
550f8c3
路
verified 路
1 Parent(s): 38093b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -1,20 +1,21 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
 
 
3
 
4
- # Cargamos un modelo real de detecci贸n de emociones faciales
5
  model = pipeline("image-classification", model="dima806/facial_emotions_image_detection")
6
 
7
- def predict_emotion(image):
8
- # El modelo procesa la imagen y devuelve una lista de etiquetas y puntajes
 
9
  predictions = model(image)
10
- return predictions
11
 
12
- # Creamos la interfaz que tu Android consumir谩
13
  demo = gr.Interface(
14
  fn=predict_emotion,
15
- inputs=gr.Image(type="pil"),
16
  outputs="json",
17
- api_name="predict_emotion"
18
  )
19
-
20
- demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import base64
4
+ from PIL import Image
5
+ import io
6
 
 
7
  model = pipeline("image-classification", model="dima806/facial_emotions_image_detection")
8
 
9
+ def predict_emotion(image_b64: str):
10
+ image_data = base64.b64decode(image_b64.split(",")[1] if "," in image_b64 else image_b64)
11
+ image = Image.open(io.BytesIO(image_data)).convert("RGB")
12
  predictions = model(image)
13
+ return [[{"label": p["label"], "score": p["score"]} for p in predictions]]
14
 
 
15
  demo = gr.Interface(
16
  fn=predict_emotion,
17
+ inputs=gr.Textbox(),
18
  outputs="json",
19
+ api_name="predict"
20
  )
21
+ demo.launch()