entregable3 / app.py
nereamart's picture
Update app.py
fe79163 verified
from huggingface_hub import from_pretrained_fastai
import gradio as gr
from fastai.text.all import *
# repo_id = "YOUR_USERNAME/YOUR_LEARNER_NAME"
repo_id = "nereamart/rotten_tomatoes"
# Cargar el modelo
learner = from_pretrained_fastai(repo_id)
labels = learner.dls.vocab
# Función para hacer predicciones de texto
def predict(text):
pred = learner.predict(text)
if pred == 1:
return {"POSITIVE": 1.0, "NEGATIVE": 0.0}
else:
return {"POSITIVE": 0.0, "NEGATIVE": 1.0}
# Creamos la interfaz con componentes de texto
examples = [
"This movie was fantastic! The acting was superb.",
"Terrible film. Waste of time and money.",
"It was okay, not great but not awful either."
]
interface = gr.Interface(
fn=predict,
inputs=gr.Textbox(lines=5, placeholder="Review"),
outputs=gr.Label(num_top_classes=2),
examples=examples,
title="Rotten Tomatoes Review Classifier",
description="Predict whether a movie review is positive (1) or negative (0)"
)
interface.launch(share=False)