osrojo commited on
Commit
7717d1f
verified
1 Parent(s): 6fdad92

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import from_pretrained_fastai
2
+
3
+ from fastai.text.all import *
4
+
5
+ import gradio as gr
6
+
7
+
8
+
9
+
10
+
11
+
12
+ # Cargamos el learner
13
+
14
+ learner = from_pretrained_fastai('osrojo/learnClass')
15
+
16
+
17
+ # Definimos las etiquetas de nuestro modelo
18
+
19
+ labels = ['0','1','2','3']
20
+
21
+
22
+ example1 = 'shaft abrasions from panties merely shifted to the side'
23
+
24
+ example2 = "I'm changing the snowman's into awful looking monsters at night. Its so funny when their owners encounter them and scream!"
25
+
26
+ example3 = "Don't be afraid of your fears. Their purpose is not to frighten you, but enlighten you and lead you into a better future."
27
+
28
+ example4 = "I've finished reading it; simply mind-blogging. The writer said 'to be continued' but I haven't found part 2."
29
+
30
+ # Definimos una funci贸n que se encarga de llevar a cabo las predicciones
31
+
32
+ def predict(text):
33
+
34
+ pred,pred_idx, probs = learner.predict(text)
35
+
36
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
37
+
38
+
39
+ # Creamos la interfaz y la lanzamos.
40
+
41
+ gr.Interface(fn=predict, inputs=gr.Textbox(), outputs=gr.Label(),examples=[example1,example2,example3,example4]).launch(share=False)