ikerml commited on
Commit
7671d8b
β€’
1 Parent(s): d5d421e

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.text.all import *
2
+ import gradio as gr
3
+ from huggingface_hub import from_pretrained_fastai
4
+
5
+ # Cargamos el learner
6
+ repo_id = "ikerml/twitter_class"
7
+
8
+ learner = from_pretrained_fastai(repo_id)
9
+
10
+ # Definimos las etiquetas de nuestro modelo
11
+ labels = ['❀','😍','πŸ˜‚','πŸ’•','πŸ”₯','😊','😎','✨','πŸ’™','😘','πŸ“·','πŸ‡ΊπŸ‡Έ','β˜€','πŸ’œ','πŸ˜‰','πŸ’―','😁','πŸŽ„','πŸ“Έ','😜']
12
+
13
+ example1 = "I like potatoe"
14
+ example2 = "My house is on fire"
15
+ example3 = "The other day, i eat a banana"
16
+
17
+ # Definimos una funciΓ³n que se encarga de llevar a cabo las predicciones
18
+ def predict(text):
19
+ pred,pred_idx,probs = learner.predict(text)
20
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
21
+
22
+ # Creamos la interfaz y la lanzamos.
23
+ gr.Interface(fn=predict, inputs=gr.inputs.Textbox(), outputs=gr.outputs.Label(),examples=[example1,example2,example3]).launch(share=False)