mahernto commited on
Commit
2a4d57a
·
verified ·
1 Parent(s): b9162e1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import from_pretrained_fastai
2
+ import gradio as gr
3
+ from fastai.text.all import *
4
+
5
+ repo_id = "mahernto/imdbmodel"
6
+ learner = from_pretrained_fastai(repo_id)
7
+
8
+ labels = learner.dls.vocab
9
+
10
+ # Función para hacer predicciones con texto
11
+ def predict(text):
12
+ pred, pred_idx, probs = learner.predict(text)
13
+ # Retornamos dict con etiqueta y su probabilidad
14
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
15
+
16
+ # Interfaz Gradio para texto y etiquetas de salida
17
+ gr.Interface(
18
+ fn=predict,
19
+ inputs=gr.Textbox(lines=2, placeholder="Write your movie review here..."),
20
+ outputs=gr.Label(num_top_classes=2),
21
+ examples=[
22
+ ["This movie was fantastic, I loved the plot and acting!"],
23
+ ["The film was boring and too long."]
24
+ ]
25
+ ).launch(share=False)