JuanMa360 commited on
Commit
fec45e6
β€’
1 Parent(s): 1838b80

multimodal

Browse files
Files changed (1) hide show
  1. app.py +55 -4
app.py CHANGED
@@ -1,7 +1,58 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import os
3
+ import time
4
 
5
+ def print_like_dislike(x: gr.LikeData):
6
+ print(x.index, x.value, x.liked)
7
 
8
+
9
+ def add_text(history, text):
10
+ history = history + [(text, None)]
11
+ return history, gr.Textbox(value="", interactive=False)
12
+
13
+
14
+ def add_file(history, file):
15
+ history = history + [((file.name,), None)]
16
+ return history
17
+
18
+
19
+ def bot(history):
20
+ response = "**That's cool!**"
21
+ history[-1][1] = ""
22
+ for character in response:
23
+ history[-1][1] += character
24
+ time.sleep(0.05)
25
+ yield history
26
+
27
+
28
+ with gr.Blocks() as demo:
29
+ chatbot = gr.Chatbot(
30
+ [],
31
+ elem_id="chatbot",
32
+ bubble_full_width=False,
33
+ avatar_images=(None, (os.path.join(os.path.abspath(''), "avatar.png"))),
34
+ )
35
+
36
+ with gr.Row():
37
+ txt = gr.Textbox(
38
+ scale=4,
39
+ show_label=False,
40
+ placeholder="Enter text and press enter, or upload an image",
41
+ container=False,
42
+ )
43
+ btn = gr.UploadButton("πŸ“", file_types=["image", "video", "audio"])
44
+
45
+ txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
46
+ bot, chatbot, chatbot, api_name="bot_response"
47
+ )
48
+ txt_msg.then(lambda: gr.Textbox(interactive=True), None, [txt], queue=False)
49
+ file_msg = btn.upload(add_file, [chatbot, btn], [chatbot], queue=False).then(
50
+ bot, chatbot, chatbot
51
+ )
52
+
53
+ chatbot.like(print_like_dislike, None, None)
54
+
55
+
56
+ demo.queue()
57
+ if __name__ == "__main__":
58
+ demo.launch()