MarioGL commited on
Commit
eebc7aa
verified
1 Parent(s): 55d54b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -4,15 +4,16 @@ from fastai.vision.all import *
4
 
5
  repo_id = "MarioGL/emotion"
6
 
7
- learner = from_pretrained_fastai(repo_id)
8
- labels = learner.dls.vocab
9
 
10
- # Definimos una funci贸n que se encarga de llevar a cabo las predicciones
11
- def predict(img):
12
- #img = PILImage.create(img)
13
- pred,pred_idx,probs = learner.predict(img)
14
- return {labels[i]: float(probs[i]) for i in range(len(labels))}
15
-
16
- # Creamos la interfaz y la lanzamos.
17
- gr.Interface(fn=predict, inputs=gr.Image(), outputs=gr.Label(num_top_classes=3),examples=['okabe.jpg','kurisu.jpg']).launch(share=False)
18
-
 
 
 
4
 
5
  repo_id = "MarioGL/emotion"
6
 
7
+ learn = load_learner(f'{repo_id}/model.pkl')
 
8
 
9
+
10
+ def classify_text(text):
11
+ pred, pred_idx, probs = learn.predict(text)
12
+ return pred, probs[pred_idx].item()
13
+
14
+ iface = gr.Interface(fn=classify_text,
15
+ inputs=gr.Textbox(label="Introduce un texto"),
16
+ outputs=[gr.Label(), gr.Textbox()],
17
+ live=True)
18
+
19
+ iface.launch()