Metantropia commited on
Commit
56d538d
Β·
verified Β·
1 Parent(s): a327afa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -7
app.py CHANGED
@@ -1,33 +1,56 @@
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
- clasificador=pipeline("text-classification",model="pysentimiento/robertuito-sentiment-analysis")
 
6
 
7
  def audio2text(audio):
8
  text = trans(audio)["text"]
9
  return text
10
 
11
  def text2sentiment(text):
12
- return clasificador(text)[0]["label"]
13
 
14
- demo=gr.Blocks()
15
- with demo:
16
- gr.Markdown("Gradio + Blocks + TabItem")
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  with gr.Tabs():
18
- with gr.TabItem("Transcribe audio en espanol"):
 
19
  with gr.Row():
20
  audio=gr.Audio(sources="microphone",type="filepath")
21
  transcripcion=gr.Textbox()
22
  b1=gr.Button("Transcribe")
23
 
24
- with gr.TabItem("Analisis de sentimiento en espanol"):
25
  with gr.Row():
26
  text=gr.Textbox()
27
  label=gr.Label()
28
  b2=gr.Button("Sentimiento")
29
 
 
 
 
 
 
 
30
  b1.click(audio2text,inputs=audio,outputs=transcripcion)
31
  b2.click(text2sentiment,inputs=text,outputs=label)
 
32
 
33
  demo.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ from PIL import Image
4
 
5
  trans=pipeline("automatic-speech-recognition",model="facebook/wav2vec2-large-xlsr-53-spanish")
6
+ sentiment_cla=pipeline("text-classification",model="pysentimiento/robertuito-sentiment-analysis")
7
+ image_cla=pipeline("image-classification", model="microsoft/swin-tiny-patch4-window7-224")
8
 
9
  def audio2text(audio):
10
  text = trans(audio)["text"]
11
  return text
12
 
13
  def text2sentiment(text):
14
+ return sentiment_cla(text)[0]["label"]
15
 
16
+ def classify_img(im):
17
+ im = Image.fromarray(im.astype('uint8'), 'RGB')
18
+ ans = image_cla(im)
19
+ labels = {v["label"]: v["score"] for v in ans}
20
+ return labels
21
+
22
+ def make_block(dem):
23
+ with dem:
24
+ gr.Markdown("""
25
+ # Este 'space' permite la inferencia los siguientes modelos open-source:
26
+ - Voice2Text: [Wav2Vec2](https://huggingface.co/facebook/wav2vec2-large-xlsr-53-spanish)
27
+ - Sentiment Analysis: [Robertuito](https://huggingface.co/pysentimiento/robertuito-sentiment-analysis)
28
+ - Image Classifier: [Swin-small-patch4](https://huggingface.co/microsoft/swin-small-patch4-window7-224)
29
+ Autor del demo: [ΞœΞ•Ξ€Ξ‘ΞΞ˜Ξ‘Ξ©Ξ Ξ™Ξ‘](https://www.instagram.com/metantropia.jpg)
30
+ """)
31
+
32
  with gr.Tabs():
33
+
34
+ with gr.TabItem("Audio a Texto"):
35
  with gr.Row():
36
  audio=gr.Audio(sources="microphone",type="filepath")
37
  transcripcion=gr.Textbox()
38
  b1=gr.Button("Transcribe")
39
 
40
+ with gr.TabItem("Analisis de Sentimiento"):
41
  with gr.Row():
42
  text=gr.Textbox()
43
  label=gr.Label()
44
  b2=gr.Button("Sentimiento")
45
 
46
+ with gr.TabItem("ClasificaciΓ³n de ImΓ‘genes"):
47
+ with gr.Row():
48
+ image = gr.Image(label="Carga una imagen aquΓ­")
49
+ label_image = gr.Label(num_top_classes=5)
50
+ b3 = gr.Button("Clasifica")
51
+
52
  b1.click(audio2text,inputs=audio,outputs=transcripcion)
53
  b2.click(text2sentiment,inputs=text,outputs=label)
54
+ b3.click(classify_img, inputs=image, outputs=label_image)
55
 
56
  demo.launch()