import time import random import gradio as gr from transformers import pipeline p = pipeline("automatic-speech-recognition", "facebook/wav2vec2-base-960h") def user(user_message, history): return "", history + [[user_message, None]] # def transcribe(audio, state=""): # text = p(audio)["text"] # state += text + " " # return state, state def transcribe(audio): text = p(audio)["text"] return text def bot(history): bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"]) history[-1][1] = "" for character in bot_message: history[-1][1] += character time.sleep(0.05) yield history css = """ .gradio-container { font-family: 'IBM Plex Sans', sans-serif; } .gr-button { color: white; border-color: black; background: black; } .container { max-width: 730px; margin: auto; padding-top: 1.5rem; } #chatbot { min-height: 30rem; margin-bottom: 15px; margin-left: auto; margin-right: auto; } #prompt-container { margin-bottom: 15px; margin-left: auto; margin-right: auto; } """ with gr.Blocks(css=css) as demo: gr.HTML( """