File size: 962 Bytes
2c82342
34a3bb8
2c82342
 
 
 
d691009
 
eb6ada7
1041028
8c07c53
2c82342
1041028
 
 
 
00d3151
eb6ada7
33ef78b
 
2c82342
1041028
2c82342
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import transformers
#def predict(image):
#  predictions = pipeline(image)
 #  return {p["label"]: p["score"] for p in predictions}

from datasets import load_dataset
import torch
from transformers import pipeline

def predict(speech):
 # load model and tokenizer
   torch.manual_seed(42)
   ds = load_dataset("hf-internal-testing/librispeech_asr_demo", "clean", split="validation")
   audio_file = ds[0]["audio"]["path"]
   audio_classifier = pipeline(
   task="audio-classification", model="ehcalabres/wav2vec2-lg-xlsr-en-speech-emotion-recognition")
   preds = audio_classifier(audio_file)
   return [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
 
   
demo = gr.Interface(fn=predict, inputs='texts'  outputs="texts")

demo.launch()


#gr.Interface(
#    predict,
#    inputs=gr.inputs.speech(label="Upload", type="filepath"),
#    outputs=gr.outputs.Label(num_top_classes=2),
#    title="Audio",
#).launch()