How to get the textbox input in a function in the chatbot streaming app
Hi,I am just starting with gradio and copied a code from gradioimport gradio as grimport randomimport timefrom googletrans import Translatortranslator = Translator()def my _translate_func(response, translate_to):return translator.translate(response,dest=translate_to).text#gradiochat1.py demo.appwith gr.Blocks() as demo:drop_lang = gr.Dropdown([“nl”, “de”, “en”,“fr”], label=“Languages”)chatbot = gr.Chatbot()msg = gr.Textbox()clear = gr.Button(“Clear”)def user(user_message, history):
    return "", history + [[user_message, None]]

def bot(message,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

msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
    bot, chatbot, chatbot
)
clear.click(lambda: None, None, chatbot, queue=False)demo.queue()demo.launch()My question is how can i replace the example of random.choice(…)with my my my _translate_func function. that it accepts the language chosen and the input from the textbox…Thanks in advance.Henry
2023-05-31T21:31:49Z
I solve it by replacing the random with the translate function and as input the history[len(history)-1][0]
2023-06-01T03:23:48Z
Hi@hboen!Glad you figured it out. Yes the history is a list of lists. The first element of the list is the user message and the bot message is the second element. So you have the right idea!
2023-06-16T02:13:03Z
Hi@freddyaboulton, I am sorry to post here, but could you check my thread?How to implement chatbot streaming with a functionBeginnersHI everyone. 
I am trying to build a basicchatbot with streaming. 
from the documentation we have the following code. 
import gradio as gr
import random
import time

with gr.Blocks() as demo:
    chatbot = gr.Chatbot()
    msg = gr.Textbox()
    clear = gr.Button("Clear")

    def respond(message, chat_history):
        bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
        chat_history.append((message, bot_message))
        time.sleep(2)
        return "", chat_h…I am having a similar question to@hboen, but haven’t been able to figure how to make it work.Any comment is greatly appreciated.