Spaces:
Runtime error
Runtime error
import time | |
import random | |
import gradio as gr | |
# from transformers import pipeline | |
# p = pipeline("automatic-speech-recognition") | |
def user(user_message, history): | |
return "", history + [[user_message, None]] | |
# def transcribe(audio, state=""): | |
# text = p(audio)["text"] | |
# state += text + " " | |
# return state, state | |
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 | |
with gr.Blocks() as demo: | |
# chatbot = gr.Chatbot() | |
# msg = gr.Textbox() | |
chatbot = gr.Chatbot([], show_label=False, elem_id="chatbot").style(height=500) | |
with gr.Row(): | |
with gr.Column(scale=0.85): | |
txt = gr.Textbox( | |
show_label=False, | |
placeholder="Type your response and press enter, or record your response", | |
).style(container=False) | |
with gr.Column(scale=0.15, min_width=0): | |
submit = gr.Button("Submit") | |
# gr.Interface( | |
# fn=transcribe, | |
# inputs=[ | |
# gr.Audio(source="microphone", type="filepath", streaming=True), | |
# "state" | |
# ], | |
# outputs=[ | |
# msg, | |
# "state" | |
# ], | |
# live=True) | |
txt.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then( | |
bot, chatbot, chatbot | |
) | |
submit.click(user, [msg, chatbot], [msg, chatbot], queue=False).then( | |
bot, chatbot, chatbot | |
) | |
demo.queue() | |
demo.launch() | |