File size: 1,792 Bytes
3e1fc67
713e80d
0e5871d
713e80d
a92da65
 
845a206
a92da65
 
 
 
3e1fc67
 
0e5871d
a92da65
52deb65
0e5871d
23ac7a2
 
 
 
 
 
 
 
68af898
 
 
26b284c
0c89c5e
23ac7a2
 
 
 
 
 
0e5871d
 
 
 
a92da65
68af898
3e1fc67
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

import gradio as gr
from transformers import pipeline

#Model_1 = "hackathon-pln-es/wav2vec2-base-finetuned-sentiment-classification-MESD"
#Model_2 ="hackathon-pln-es/wav2vec2-base-finetuned-sentiment-mesd"

model_name2id = {"Model A": "hackathon-pln-es/wav2vec2-base-finetuned-sentiment-classification-MESD", "Model B": "hackathon-pln-es/wav2vec2-base-finetuned-sentiment-mesd"}

def classify_sentiment(audio, model_name):
  pipe = pipeline("audio-classification", model=model_name2id[model_name])
  pred = pipe(audio)
  return {dic["label"]: dic["score"] for dic in pred}

input_audio = [gr.inputs.Audio(source="microphone", type="filepath", label="Record/ Drop audio"), gr.inputs.Dropdown([model_name2id[model_name], model_name2id[model_name]], label="Model Name")]
label = gr.outputs.Label(num_top_classes=5)

################### Gradio Web APP ################################

title = "Audio Sentiment Classifier"

description = """
<p>
<center>
This application classifies the sentiment of the audio input provided by the user. 
#</center>
#</p>
#<center>
#<img src="https://huggingface.co/spaces/hackathon-pln-es/Audio-Sentiment-Classifier/tree/main/sentiment.jpg" alt="logo" width="750"/>
#<img src="https://huggingface.co/spaces/hackathon-pln-es/Audio-Sentiment-Classifier/tree/main/sentiment.jpg" style="max-width: 100%; max-height: 10%; height: 250px; object-fit: fill">
</center>
"""




gr.Interface(
    fn = classify_sentiment,
    inputs = input_audio,
    outputs = label,
    examples=[["basta_neutral.wav", model_name2id[model_name]], ["detras_disgust.wav", model_name2id[model_name]], ["mortal_sadness.wav", model_name2id[model_name]], ["respiracion_happiness.wav", model_name2id[model_name]], ["robo_fear.wav", model_name2id[model_name]]],
    theme="grass").launch()