jemole commited on
Commit
5ba33e0
1 Parent(s): 3678d5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -16
app.py CHANGED
@@ -1,34 +1,21 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- #trans = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-large-xlsr-53-spanish")
5
  classifier = pipeline("text-classification", model="pysentimiento/robertuito-sentiment-analysis")
6
 
7
- def audio_to_text(audio):
8
- text = trans(audio)["text"]
9
- return text
10
-
11
  def text_to_sentiment(text):
12
- return classifier(text)[0]#["label"]
13
 
14
  demo = gr.Blocks()
15
 
16
  with demo:
17
- gr.Markdown("Demostración de análisis de sentimientos de textos")
18
  with gr.Tabs():
19
- #with gr.TabItem("Transcribe audio in Spanish"):
20
- # with gr.Row():
21
- # audio = gr.Audio(source="microphone", type="filepath")
22
- # transcription = gr.Textbox()
23
- # b1 = gr.Button("Transcribe")
24
-
25
  with gr.TabItem("Análisis de sentimientos de textos en español"):
26
  with gr.Row():
27
  texto = gr.Textbox()
28
  label = gr.Label(num_top_classes=1)
29
- b2 = gr.Button("Sentimiento")
30
 
31
- #b1.click(audio_to_text, inputs=audio, outputs=transcription)
32
- b2.click(text_to_sentiment, inputs=texto, outputs=label)
33
 
34
  demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
 
4
  classifier = pipeline("text-classification", model="pysentimiento/robertuito-sentiment-analysis")
5
 
 
 
 
 
6
  def text_to_sentiment(text):
7
+ return {classifier(text)[0]["label"]: classifier(text)[0]["score"]}
8
 
9
  demo = gr.Blocks()
10
 
11
  with demo:
 
12
  with gr.Tabs():
 
 
 
 
 
 
13
  with gr.TabItem("Análisis de sentimientos de textos en español"):
14
  with gr.Row():
15
  texto = gr.Textbox()
16
  label = gr.Label(num_top_classes=1)
17
+ b1 = gr.Button("Analizar")
18
 
19
+ b1.click(text_to_sentiment, inputs=texto, outputs=label)
 
20
 
21
  demo.launch()