Update app.py
Browse files
app.py
CHANGED
@@ -1,27 +1,23 @@
|
|
|
|
1 |
from huggingface_hub import from_pretrained_fastai
|
2 |
import gradio as gr
|
3 |
-
from fastai.text.all import *
|
4 |
|
5 |
-
#
|
6 |
repo_id = "luis56125/news2"
|
|
|
|
|
7 |
learner = from_pretrained_fastai(repo_id)
|
8 |
|
9 |
-
#
|
10 |
labels = ['Mundo', 'Deportes', 'Negocios', 'Ciencia/Tecnolog铆a']
|
11 |
|
12 |
-
#
|
13 |
def predict(text):
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
"Global stock markets have fallen sharply as investors worry about the potential impact of rising interest rates.",
|
21 |
-
"Scientists have discovered a new species of dinosaur that sheds light on the evolutionary history of reptiles.",
|
22 |
-
"The local sports team won their championship game after a stunning comeback in the second half.",
|
23 |
-
"New advancements in artificial intelligence are revolutionizing how we interact with technology."
|
24 |
-
]
|
25 |
|
26 |
-
# Crea y lanza la interfaz de Gradio
|
27 |
-
gr.Interface(fn=predict, inputs="text", outputs=gr.outputs.Label(num_top_classes=4), examples=examples).launch(share=True)
|
|
|
1 |
+
# Importaci贸n de las bibliotecas necesarias
|
2 |
from huggingface_hub import from_pretrained_fastai
|
3 |
import gradio as gr
|
|
|
4 |
|
5 |
+
# Identificador del repositorio en Hugging Face donde est谩 almacenado el modelo
|
6 |
repo_id = "luis56125/news2"
|
7 |
+
|
8 |
+
# Cargar el modelo preentrenado desde Hugging Face
|
9 |
learner = from_pretrained_fastai(repo_id)
|
10 |
|
11 |
+
# Definir las etiquetas de clasificaci贸n disponibles
|
12 |
labels = ['Mundo', 'Deportes', 'Negocios', 'Ciencia/Tecnolog铆a']
|
13 |
|
14 |
+
# Definir una funci贸n para predecir la categor铆a de un texto dado
|
15 |
def predict(text):
|
16 |
+
# Obtener las probabilidades de las etiquetas desde el modelo
|
17 |
+
probs = learner.predict(text)
|
18 |
+
# Devolver un diccionario que mapea cada etiqueta a su probabilidad correspondiente
|
19 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
20 |
|
21 |
+
# Crear una interfaz de usuario para el modelo utilizando Gradio
|
22 |
+
gr.Interface(fn=predict, inputs="text", outputs=gr.components.Label(num_top_classes=5)).launch(share=False)
|
|
|
|
|
|
|
|
|
|
|
23 |
|
|
|
|