Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,25 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
#
|
5 |
classifier = pipeline(
|
6 |
"text-classification",
|
7 |
-
model="finiteautomata/bertweet-base-sentiment-analysis",
|
8 |
device=-1
|
9 |
)
|
10 |
|
|
|
11 |
def classify_text(text):
|
12 |
result = classifier(text)
|
13 |
-
return "videojuegos" if result[0]['label'] == 'POS' else "películas"
|
14 |
|
15 |
-
|
|
|
16 |
fn=classify_text,
|
17 |
inputs=gr.Textbox(lines=2, placeholder="Pega la noticia aquí..."),
|
18 |
outputs="text",
|
19 |
-
title="Filtro de Noticias: ¿Videojuego o Película?"
|
|
|
20 |
)
|
21 |
-
|
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Carga el modelo
|
5 |
classifier = pipeline(
|
6 |
"text-classification",
|
7 |
+
model="finiteautomata/bertweet-base-sentiment-analysis",
|
8 |
device=-1
|
9 |
)
|
10 |
|
11 |
+
# Función de clasificación
|
12 |
def classify_text(text):
|
13 |
result = classifier(text)
|
14 |
+
return "videojuegos" if result[0]['label'] == 'POS' else "películas"
|
15 |
|
16 |
+
# Configuración de Gradio con endpoints API
|
17 |
+
app = gr.Interface(
|
18 |
fn=classify_text,
|
19 |
inputs=gr.Textbox(lines=2, placeholder="Pega la noticia aquí..."),
|
20 |
outputs="text",
|
21 |
+
title="Filtro de Noticias: ¿Videojuego o Película?",
|
22 |
+
api_name="predict" # <--- ¡Clave para exponer la API!
|
23 |
)
|
24 |
+
|
25 |
+
app.launch(show_api=True) # Muestra la documentación de la API
|