Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,30 @@
|
|
| 1 |
from huggingface_hub import from_pretrained_fastai
|
| 2 |
import gradio as gr
|
| 3 |
-
from fastai.text.all import *
|
| 4 |
|
| 5 |
-
#
|
| 6 |
repo_id = "jojimene/entregable3"
|
| 7 |
-
|
| 8 |
learner = from_pretrained_fastai(repo_id)
|
| 9 |
-
labels = learner.dls.vocab[0]
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
|
|
|
|
|
|
| 16 |
|
|
|
|
| 17 |
gr.Interface(
|
| 18 |
-
fn=
|
| 19 |
-
inputs=gr.Textbox(lines=
|
| 20 |
outputs=gr.Label(num_top_classes=3),
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
).launch(
|
| 24 |
-
|
|
|
|
| 1 |
from huggingface_hub import from_pretrained_fastai
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
+
# Cargar el modelo desde Hugging Face
|
| 5 |
repo_id = "jojimene/entregable3"
|
|
|
|
| 6 |
learner = from_pretrained_fastai(repo_id)
|
|
|
|
| 7 |
|
| 8 |
+
# Funci贸n para predecir el sentimiento del texto
|
| 9 |
+
def predict_sentiment(text):
|
| 10 |
+
try:
|
| 11 |
+
result = learner.predict(text)
|
| 12 |
+
print("Raw prediction:", result)
|
| 13 |
+
|
| 14 |
+
if isinstance(result, tuple) and len(result) == 3:
|
| 15 |
+
pred, _, probs = result
|
| 16 |
+
return {str(learner.dls.vocab[i]): float(probs[i]) for i in range(len(probs))}
|
| 17 |
+
else:
|
| 18 |
+
return f"{result}"
|
| 19 |
|
| 20 |
+
except Exception as e:
|
| 21 |
+
return f"Error: {str(e)}"
|
| 22 |
|
| 23 |
+
# Crear interfaz con Gradio
|
| 24 |
gr.Interface(
|
| 25 |
+
fn=predict_sentiment,
|
| 26 |
+
inputs=gr.Textbox(lines=3, placeholder="Escribe un texto para analizar el sentimiento..."),
|
| 27 |
outputs=gr.Label(num_top_classes=3),
|
| 28 |
+
title="An谩lisis de Sentimiento del Clima",
|
| 29 |
+
description="Este modelo analiza el sentimiento de textos relacionados con el clima."
|
| 30 |
+
).launch()
|
|
|