Add application file
Browse files- app.py +40 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# pipelines
|
6 |
+
pipeline_clf = pipeline("text-classification", model = "stinoco/beto-sentiment-analysis-finetuned", return_all_scores = True)
|
7 |
+
pipeline_pos = pipeline("token-classification", model = "sagorsarker/codeswitch-spaeng-pos-lince")
|
8 |
+
|
9 |
+
|
10 |
+
def predict(text: str):
|
11 |
+
|
12 |
+
'''
|
13 |
+
Función que recibe texto como input, devuelve la clasificación de texto para ser recibida por el demo.
|
14 |
+
text: texto a clasificar (str)
|
15 |
+
'''
|
16 |
+
|
17 |
+
# Text Classification
|
18 |
+
classes = pipeline_clf(text)[0]
|
19 |
+
|
20 |
+
# POS
|
21 |
+
classes = {element['label']: element['score'] for element in classes}
|
22 |
+
|
23 |
+
labeled_text = {'text': text, 'entities': pipeline_pos(text)}
|
24 |
+
|
25 |
+
return classes, labeled_text
|
26 |
+
|
27 |
+
demo = gr.Interface(fn = predict,
|
28 |
+
inputs = [gr.Textbox(placeholder = "Ingresa el reclamo acá", label = 'Reclamo')],
|
29 |
+
outputs = [gr.outputs.Label(label = 'Categorías'),
|
30 |
+
gr.Highlightedtext(label = 'Part of Speech')],
|
31 |
+
examples = [
|
32 |
+
['al ser de region simpre esta con quiebre de stock'],
|
33 |
+
['que tienen que tener vendedores que conozcan el rubro y que sepan lo que estan vendiendo'],
|
34 |
+
['un solo vendedor no pude estar encargado de miles de articulos debe especificarse en cerveza'],
|
35 |
+
['no hay mercaderia']
|
36 |
+
],
|
37 |
+
title = 'Demo Clasificación NPS'
|
38 |
+
)
|
39 |
+
|
40 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
numpy
|
2 |
+
openpyxl
|