File size: 2,091 Bytes
66602d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# 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()