EliseoBaquero commited on
Commit
f4e2883
·
verified ·
1 Parent(s): b9cc091

Creación de tres modelos

Browse files

Son tres modelos para audio, texto y clasificador de imagenes

Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+ from PIL import Image
4
+
5
+
6
+ def classify_img(im):
7
+ im = Image.fromarray(im.astype('uint8'), 'RGB')
8
+ ans = image_cla(im)
9
+ labels = {v["label"]: v["score"] for v in ans}
10
+ return labels
11
+
12
+
13
+ def voice2text(audio):
14
+ text = voice_cla(audio)["text"]
15
+ return text
16
+
17
+
18
+ def text2sentiment(text):
19
+ sentiment = text_cla(text)[0]["label"]
20
+ return sentiment
21
+
22
+
23
+ def make_block(dem):
24
+ with dem:
25
+ gr.Markdown("""
26
+ # Ejemplo de `space` multiclassifier:
27
+ Se pide incluir un tercer boton, se integran tres modelos.
28
+ Este `space` contiene los siguientes modelos:
29
+ - ASR: [Wav2Vec2](https://huggingface.co/facebook/wav2vec2-large-xlsr-53-spanish)
30
+ - Text Classification: [Robertuito](https://huggingface.co/pysentimiento/robertuito-sentiment-analysis)
31
+ - Image classifier: [Swin-small-patch4](https://huggingface.co/microsoft/swin-small-patch4-window7-224)
32
+ """)
33
+ with gr.Tabs():
34
+ with gr.TabItem("Transcribe audio en español"):
35
+ with gr.Row():
36
+ audio = gr.Audio(source="microphone", type="filepath")
37
+ transcripcion = gr.Textbox()
38
+ b1 = gr.Button("Voz a Texto")
39
+
40
+ with gr.TabItem("Análisis de sentimiento en español"):
41
+ with gr.Row():
42
+ texto = gr.Textbox()
43
+ label = gr.Label()
44
+ b2 = gr.Button("Texto a Sentimiento")
45
+ with gr.TabItem("Clasificación de Imágenes"):
46
+ with gr.Row():
47
+ image = gr.Image(label="Carga una imagen aquí")
48
+ label_image = gr.Label(num_top_classes=5)
49
+ b3 = gr.Button("Clasifica")
50
+
51
+ b1.click(voice2text, inputs=audio, outputs=transcripcion)
52
+ b2.click(text2sentiment, inputs=texto, outputs=label)
53
+ b3.click(classify_img, inputs=image, outputs=label_image)
54
+
55
+
56
+ if __name__ == '__main__':
57
+ image_cla = pipeline("image-classification", model="microsoft/swin-tiny-patch4-window7-224")
58
+ voice_cla = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-large-xlsr-53-spanish")
59
+ text_cla = pipeline("text-classification", model="pysentimiento/robertuito-sentiment-analysis")
60
+
61
+ demo = gr.Blocks()
62
+ make_block(demo)
63
+ demo.launch()