Simba commited on
Commit
6244fb2
1 Parent(s): 41ef24e
Files changed (2) hide show
  1. app.py +9 -45
  2. app_old.py +51 -0
app.py CHANGED
@@ -1,51 +1,15 @@
1
- import os
2
- import cv2
3
- import uuid
4
-
5
  import gradio as gr
6
- import numpy as np
7
-
8
- import neovision
9
-
10
- MARKDOWN = """
11
- # neovision 💬 + 📸
12
-
13
- This is a demo of neovision, a tool that allows you to chat with your webcamusinf GTP Vision.
14
- """
15
-
16
- connector = neovision.OpanAIConnector()
17
-
18
-
19
- def save_image_to_drive(image: np.ndarray) -> str:
20
- image_filename = f"{uuid.uuid4()}.jpeg"
21
- image_directory = "data"
22
- os.makedirs(image_directory, exist_ok=True)
23
- image_path = os.path.join(image_directory, image_filename)
24
- cv2.imwrite(image_path, image)
25
- return image_path
26
-
27
-
28
 
29
- def respond(image: np.ndarray, prompt: str, chat_history):
30
- image = np.fliplr(image)
31
- image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
32
- image_path = save_image_to_drive(image)
33
- response = connector.simple_prompt(image=image, prompt=prompt)
34
- chat_history.append(((image_path,), None))
35
- chat_history.append((prompt, response))
36
- return "", chat_history
37
 
 
 
38
 
39
- with gr.Blocks() as demo:
40
- gr.Markdown(MARKDOWN)
41
- with gr.Row():
42
- # webcam = gr.Image(source="webcam", streaming=True)
43
- webcam = gr.Webcam(mirror_webcam=True, streaming=True)
44
- with gr.Column():
45
- chatbot = gr.Chatbot(height=500)
46
- message = gr.Textbox()
47
- clear_button = gr.ClearButton([message, chatbot])
48
 
49
- message.submit(respond, [webcam, message, chatbot], [message, chatbot])
 
 
 
 
50
 
51
- demo.launch(debug=False, show_error=True)
 
 
 
 
 
 
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
 
 
 
 
 
 
 
 
3
 
4
+ def snap(image, video):
5
+ return [image, video]
6
 
 
 
 
 
 
 
 
 
 
7
 
8
+ demo = gr.Interface(
9
+ snap,
10
+ [gr.Image(sources=["webcam"]), gr.Video(sources=["webcam"])],
11
+ ["image", "video"],
12
+ )
13
 
14
+ if __name__ == "__main__":
15
+ demo.launch()
app_old.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import cv2
3
+ import uuid
4
+
5
+ import gradio as gr
6
+ import numpy as np
7
+
8
+ import neovision
9
+
10
+ MARKDOWN = """
11
+ # neovision 💬 + 📸
12
+
13
+ This is a demo of neovision, a tool that allows you to chat with your webcamusinf GTP Vision.
14
+ """
15
+
16
+ connector = neovision.OpanAIConnector()
17
+
18
+
19
+ def save_image_to_drive(image: np.ndarray) -> str:
20
+ image_filename = f"{uuid.uuid4()}.jpeg"
21
+ image_directory = "data"
22
+ os.makedirs(image_directory, exist_ok=True)
23
+ image_path = os.path.join(image_directory, image_filename)
24
+ cv2.imwrite(image_path, image)
25
+ return image_path
26
+
27
+
28
+
29
+ def respond(image: np.ndarray, prompt: str, chat_history):
30
+ image = np.fliplr(image)
31
+ image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
32
+ image_path = save_image_to_drive(image)
33
+ response = connector.simple_prompt(image=image, prompt=prompt)
34
+ chat_history.append(((image_path,), None))
35
+ chat_history.append((prompt, response))
36
+ return "", chat_history
37
+
38
+
39
+ with gr.Blocks() as demo:
40
+ gr.Markdown(MARKDOWN)
41
+ with gr.Row():
42
+ # webcam = gr.Image(source="webcam", streaming=True)
43
+ webcam = gr.Webcam(mirror_webcam=True, streaming=True)
44
+ with gr.Column():
45
+ chatbot = gr.Chatbot(height=500)
46
+ message = gr.Textbox()
47
+ clear_button = gr.ClearButton([message, chatbot])
48
+
49
+ message.submit(respond, [webcam, message, chatbot], [message, chatbot])
50
+
51
+ demo.launch(debug=False, show_error=True)