Spaces:
Sleeping
Sleeping
| from huggingface_hub import from_pretrained_fastai | |
| import gradio as gr | |
| # Cargar el modelo desde Hugging Face Hub | |
| repo_id = "dagarcsot/entregable3" | |
| learner = from_pretrained_fastai(repo_id) | |
| def predict_sentiment(text): | |
| pred, pred_idx, probs = learner.predict(text) | |
| prob_positive = float(probs[1]) | |
| # Seleccionar imagen según rango de positividad | |
| if prob_positive < 0.25: | |
| image = "very_sad.png" | |
| nivel = "Very negative" | |
| elif prob_positive < 0.5: | |
| image = "sad.png" | |
| nivel = "Negative" | |
| elif prob_positive < 0.75: | |
| image = "happy.png" | |
| nivel = "Positive" | |
| else: | |
| image = "very_happy.png" | |
| nivel = "Veery positive" | |
| mensaje = f"{nivel} ({prob_positive*100:.2f}%)" | |
| return mensaje, image | |
| # Interfaz Gradio | |
| gr.Interface( | |
| fn=predict_sentiment, | |
| inputs=gr.Textbox(lines=3, placeholder="Escribe algo..."), | |
| outputs=[ | |
| gr.Text(label="Evaluación"), | |
| gr.Image(type="filepath", label="Expresión facial") | |
| ], | |
| title="Clasificador de Sentimiento", | |
| description="This model evaluates how positive a text is and represents it with a face. (Trained on movie reviews).", | |
| examples=[ | |
| "I love this thing.", | |
| "Good, I think?.", | |
| "It had some very good moments, but sometimes it was little boring. I love Danny DeVito", | |
| "I hate it." | |
| ] | |
| ).launch() | |