Tafar commited on
Commit
a521c82
·
1 Parent(s): 6d3f67b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+ import time
4
+
5
+ with gr.Blocks() as demo:
6
+ chatbot = gr.Chatbot()
7
+ msg = gr.Textbox()
8
+ clear = gr.Button("Clear")
9
+
10
+ def user(user_message, history):
11
+ return "", history + [[user_message, None]]
12
+
13
+ def bot(history):
14
+ bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
15
+ history[-1][1] = ""
16
+ for character in bot_message:
17
+ history[-1][1] += character
18
+ time.sleep(0.05)
19
+ yield history
20
+
21
+ msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
22
+ bot, chatbot, chatbot
23
+ )
24
+ clear.click(lambda: None, None, chatbot, queue=False)
25
+
26
+ demo.queue()
27
+ demo.launch()
28
+ #add code here
29
+
30
+
31
+ import gradio as gr
32
+
33
+ def greet(history, input):
34
+ return history + [(input, "Hello, " + input)]
35
+
36
+ def vote(data: gr.LikeData):
37
+ if data.liked:
38
+ print("You upvoted this response: " + data.value)
39
+ else:
40
+ print("You downvoted this response: " + data.value)
41
+
42
+
43
+ with gr.Blocks() as demo:
44
+ chatbot = gr.Chatbot()
45
+ textbox = gr.Textbox()
46
+ textbox.submit(greet, [chatbot, textbox], [chatbot])
47
+ chatbot.like(vote, None, None) # Adding this line causes the like/dislike icons to appear in your chatbot
48
+
49
+ demo.launch()
50
+ #add another code
51
+ def bot(history):
52
+ response = "**That's cool!**"
53
+ history[-1][1] = response
54
+ return history
55
+