import os import numpy as np import gradio as gr from gradio.mix import Series from transformers import pipeline path_to_L_model = str(os.environ['path_to_L_model']) read_token = str(os.environ['read_token']) description = "Talk to Breud!" title = "Breud (BERT + Freud)" # wisper = gr.Interface.load("models/openai/whisper-base") # interface_model_L = gr.Interface.load( # name=path_to_L_model, # api_key=read_token, # ) # Series( # wisper, # interface_model_L, # description = description, # title = title, # inputs = gr.Audio(source="microphone"), # ).launch() asr = pipeline("automatic-speech-recognition", "models/openai/whisper-base") classifier = pipeline("text-classification", path_to_L_model, api_token=read_token) def speech_to_text(speech): text = asr(speech)["text"] return text def text_to_sentiment(text): return classifier(text)[0]["label"] demo = gr.Blocks() with demo: audio_file = gr.Audio(source="microphone") text = gr.Textbox() label = gr.Label() b1 = gr.Button("Recognize Speech") b2 = gr.Button("Classify Sentiment") b1.click(speech_to_text, inputs=audio_file, outputs=text) b2.click(text_to_sentiment, inputs=text, outputs=label) demo.launch()