abelllanas commited on
Commit
a900b67
verified
1 Parent(s): a7dc0d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -17
app.py CHANGED
@@ -4,28 +4,13 @@ from huggingface_hub import from_pretrained_fastai
4
 
5
  # Cargar el modelo desde Hugging Face
6
  learn = from_pretrained_fastai("abelllanas/emotions_dl")
7
-
8
- # Crear un mapeo de etiquetas traducidas al ingl茅s (solo una vez)
9
- label_map = {
10
- "alegr铆a cuadros pintura": "joy",
11
- "ira cuadros pintura": "anger",
12
- "miedo cuadros pintura": "fear",
13
- "tristeza cuadros pintura": "sadness"
14
- }
15
 
16
  # Funci贸n para predecir emociones
17
  def predict(img):
18
  img = PILImage.create(img) # Convertir la imagen al formato adecuado
19
  pred, pred_idx, probs = learn.predict(img) # Realizar la predicci贸n
20
-
21
- # Obtener las etiquetas originales
22
- original_labels = learn.dls.vocab
23
-
24
- # Traducir las etiquetas utilizando el diccionario de mapeo
25
- translated_labels = [label_map.get(label, label) for label in original_labels]
26
-
27
- # Devolver las probabilidades con las etiquetas traducidas
28
- return {translated_labels[i]: float(probs[i]) for i in range(len(translated_labels))}
29
 
30
 
31
  title = "Emotion predictor"
 
4
 
5
  # Cargar el modelo desde Hugging Face
6
  learn = from_pretrained_fastai("abelllanas/emotions_dl")
7
+ labels = learn.dls.vocab # Obtener las etiquetas de emociones
 
 
 
 
 
 
 
8
 
9
  # Funci贸n para predecir emociones
10
  def predict(img):
11
  img = PILImage.create(img) # Convertir la imagen al formato adecuado
12
  pred, pred_idx, probs = learn.predict(img) # Realizar la predicci贸n
13
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
 
 
 
 
 
 
 
 
14
 
15
 
16
  title = "Emotion predictor"