igmarco commited on
Commit
4ee211c
1 Parent(s): fa972f2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import from_pretrained_fastai
2
+ import gradio as gr
3
+ # from fastai.vision.all import *
4
+ from fastai.text.all import *
5
+
6
+
7
+
8
+ # repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME"
9
+ repo_id = "igmarco/AWD_LSTM-text-classification"
10
+
11
+ learner = from_pretrained_fastai(repo_id)
12
+ labels = learner.dls.vocab
13
+
14
+ # Definimos una función que se encarga de llevar a cabo las predicciones
15
+ def predict(txt):
16
+ pred,pred_idx,probs = learner.predict(txt)
17
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
18
+
19
+ # Creamos la interfaz y la lanzamos.
20
+ gr.Interface(fn=predict, inputs=gr.Textbox(lines=2, placeholder="Text Here..."), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=False)