Jhoeel commited on
Commit
3061ca9
1 Parent(s): af6166c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -35
app.py CHANGED
@@ -1,41 +1,20 @@
1
- # Importa librerias
2
  from transformers import pipeline
3
  import gradio as gr
4
 
5
- # Inicializaci贸n de Modelo de Clasificaci贸n de Sentimiento
6
- modelo = 'pysentimiento/robertuito-sentiment-analysis'
7
- pipeline_de_clasificador = pipeline("text-classification",model=modelo)
8
 
9
- def clasificador(texto):
10
- return str(pipeline_de_clasificador(texto)[0]['label'])
11
 
12
- with gr.Blocks() as demo:
13
- with gr.Row():
14
- with gr.Column():
15
- input = gr.Textbox(label="Texto a clasificar")
16
- btn_clasificar = gr.Button(value="Clasificar")
17
- with gr.Column():
18
- output = gr.Textbox(label="Sentimiento")
19
 
20
- def clasificador(btn):
21
- # perform sentiment analysis on input text and get the result as `sentiment`
22
- sentiment = "POS" # replace with actual sentiment analysis result
23
-
24
- # map sentiment to the corresponding label
25
- if sentiment == "POS":
26
- sentiment_label = "Positivo"
27
- elif sentiment == "NEU":
28
- sentiment_label = "Neutro"
29
- elif sentiment == "NEG":
30
- sentiment_label = "Negativo"
31
- else:
32
- sentiment_label = "Desconocido"
33
-
34
- output.value = sentiment_label
35
-
36
- btn_clasificar.click(clasificador, inputs=input, outputs=output)
37
- examples = gr.Examples(examples=['Estoy feliz 馃 de mostrarles un toolkit para An谩lisis de Sentimientos y otras tareas de SocialNLP',
38
- 'Espero que no lo odien.',
39
- 'Lo odiamos.'], inputs=[input])
40
-
41
- demo.launch()
 
1
+ # Import libraries
2
  from transformers import pipeline
3
  import gradio as gr
4
 
5
+ # Initialize Sentiment Classification Model
6
+ model_name = 'pysentimiento/robertuito-sentiment-analysis'
7
+ classifier = pipeline("text-classification", model=model_name)
8
 
9
+ def classify_text(text):
10
+ return str(classifier(text)[0]['label'])
11
 
12
+ # Create Gradio Interface
13
+ input_text = gr.inputs.Textbox(label="Texto a clasificar")
14
+ output_text = gr.outputs.Textbox(label="Sentimiento")
 
 
 
 
15
 
16
+ gr.Interface(fn=classify_text, inputs=input_text, outputs=output_text, examples=[
17
+ ['Estoy feliz 馃 de mostrarles un toolkit para An谩lisis de Sentimientos y otras tareas de SocialNLP'],
18
+ ['Espero que no lo odien.'],
19
+ ['Lo odiamos.']
20
+ ]).launch()