mahernto commited on
Commit
5c97177
·
verified ·
1 Parent(s): aafb923

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -19
app.py CHANGED
@@ -1,25 +1,14 @@
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, _, probs = learn.predict(text)
13
- labels = learn.dls.vocab
14
- return {label: float(prob) for label, prob in zip(labels, probs)}
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)
 
 
 
1
  from fastai.text.all import *
2
+ import gradio as gr
3
 
4
+ # Cargar el modelo
5
+ learn = load_learner('model.pkl')
 
 
6
 
7
+ # Función de predicción
8
  def predict(text):
9
  pred, _, probs = learn.predict(text)
10
+ return f"Predicción: {pred} (confianza: {probs.max():.2%})"
 
11
 
12
+ # Interfaz Gradio
13
+ demo = gr.Interface(fn=predict, inputs=gr.Textbox(lines=4, placeholder="Escribe un texto..."), outputs="text")
14
+ demo.launch()