Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from setfit import SetFitModel
|
| 3 |
+
|
| 4 |
+
# Cargar el modelo
|
| 5 |
+
model = SetFitModel.from_pretrained("rovargasc/modelopruebaUNAL2")
|
| 6 |
+
|
| 7 |
+
def predict_text(text):
|
| 8 |
+
"""Función para hacer predicciones con el modelo"""
|
| 9 |
+
if not text.strip():
|
| 10 |
+
return "Por favor ingresa un texto"
|
| 11 |
+
|
| 12 |
+
try:
|
| 13 |
+
prediction = model(text)
|
| 14 |
+
return f"Predicción: {prediction}"
|
| 15 |
+
except Exception as e:
|
| 16 |
+
return f"Error: {str(e)}"
|
| 17 |
+
|
| 18 |
+
# Crear la interfaz
|
| 19 |
+
interface = gr.Interface(
|
| 20 |
+
fn=predict_text,
|
| 21 |
+
inputs=gr.Textbox(
|
| 22 |
+
lines=3,
|
| 23 |
+
placeholder="Escribe tu texto aquí...",
|
| 24 |
+
label="Texto de entrada"
|
| 25 |
+
),
|
| 26 |
+
outputs=gr.Textbox(label="Resultado"),
|
| 27 |
+
title="Clasificador de Texto - SetFit Model",
|
| 28 |
+
description="Ingresa un texto para obtener una predicción del modelo SetFit",
|
| 29 |
+
examples=[
|
| 30 |
+
["This movie is amazing!"],
|
| 31 |
+
["I don't like this product"],
|
| 32 |
+
["chokes on its own depiction of upper-crust decorum."]
|
| 33 |
+
]
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
if __name__ == "__main__":
|
| 37 |
+
interface.launch()
|