Hi,
I am just starting with gradio and copied a code from gradio
import gradio as gr
import random
import time
from googletrans import Translator
translator = Translator()
def my _translate_func(response, translate_to):
return translator.translate(response,dest=translate_to).text
#gradio chat1.py demo.app
with 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