chenjoya commited on
Commit
38b9924
·
verified ·
1 Parent(s): 44236ba

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def general_chat(text: str, gr_history: list):
4
+ yield text
5
+
6
+ def online_chat(gr_webcam_image, gr_history: list):
7
+ if gr_webcam_image:
8
+ query = {"role": "user", "content": (gr_webcam_image, )}
9
+ response = {"role": "assistant", "content": 'this is a frame.'}
10
+ gr_history.extend([query, response])
11
+ yield gr_history
12
+
13
+ with gr.Blocks() as demo:
14
+ gr.Markdown("## Simple Streaming Record and Response")
15
+ with gr.Row():
16
+ with gr.Column():
17
+ gr_webcam_image = gr.Image(
18
+ label='WebCam',
19
+ sources="webcam",
20
+ height=250,
21
+ type='filepath')
22
+ gr_chatinterface_ol = gr.ChatInterface(
23
+ fn=general_chat,
24
+ type="messages",
25
+ multimodal=True,
26
+ )
27
+ gr_webcam_image.stream(
28
+ fn=online_chat,
29
+ inputs=[gr_webcam_image, gr_chatinterface_ol.chatbot],
30
+ outputs=[gr_chatinterface_ol.chatbot],
31
+ stream_every=1,
32
+ concurrency_limit=30,
33
+ )
34
+ demo.queue(default_concurrency_limit=100, max_size=100).launch(share=True,
35
+ max_threads=100,
36
+ ssr_mode=False)