Spaces:
Runtime error
Runtime error
| # import gradio as gr | |
| # import random | |
| # import time | |
| # with gr.Blocks() as demo: | |
| # chatbot = gr.Chatbot() | |
| # msg = gr.Textbox() | |
| # clear = gr.ClearButton([msg, chatbot]) | |
| # 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_history | |
| # msg.submit(respond, [msg, chatbot], [msg, chatbot]) | |
| # demo.launch() | |
| import gradio as gr | |
| import random | |
| import time | |
| css=""" | |
| .feedback {font-size: 24px !important;} | |
| .feedback textarea {font-size: 24px !important;} | |
| .rightx { position: relative !important; | |
| float: right !important; | |
| border: 2px solid #ff1100 !important; | |
| }""" | |
| with gr.Blocks(theme=gr.themes.Soft(), css=css) as demo: | |
| def vote(data: gr.LikeData): | |
| if data.liked: | |
| print("You upvoted this response: " + data.value) | |
| else: | |
| print("You downvoted this response: " + data.value) | |
| img = gr.Image(label=None, height=100, width=100, show_label=False, show_download_button=False, value="https://d2q79iu7y748jz.cloudfront.net/s/_squarelogo/256x256/0c7f916071ff42079edf5ce9e60321c1") | |
| chatbot = gr.Chatbot(label="Agent") | |
| chatbot.like(vote, None, None) # Adding this line causes the like/dislike icons to appear in your chatbot | |
| msg = gr.Textbox(label="Query") | |
| clear = gr.Button("Clear", min_width=20, scale=0) | |
| def user(user_message, history): | |
| return "", history + [[user_message, None]] | |
| def bot(history): | |
| bot_message = random.choice(["How are you?", "Thats really good", "I'm very hungry", "Do you extrude Aluminum?"]) | |
| 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() | |