Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,5 @@
|
|
|
|
|
|
1 |
import PIL.Image
|
2 |
import gradio as gr
|
3 |
import base64
|
@@ -24,7 +26,7 @@ For example:
|
|
24 |
3- Notify Richard after shipment
|
25 |
"""
|
26 |
|
27 |
-
txt_display_1 = 'content of
|
28 |
|
29 |
import os
|
30 |
|
@@ -63,27 +65,24 @@ def app2_response(history,text,img):
|
|
63 |
|
64 |
# Function that takes User Inputs and displays it on ChatUI
|
65 |
|
66 |
-
def app1_query(
|
67 |
if not img:
|
68 |
-
|
69 |
-
return history
|
70 |
base64 = image_to_base64(img)
|
71 |
data_url = f"data:image/jpeg;base64,{base64}"
|
72 |
-
|
73 |
-
return
|
74 |
|
75 |
# Function that takes User Inputs, generates Response and displays on Chat UI
|
76 |
-
def app1_response(
|
77 |
if not img:
|
78 |
response = txt_model.generate_content(txt_prompt_1)
|
79 |
-
|
80 |
-
return history
|
81 |
|
82 |
else:
|
83 |
img = PIL.Image.open(img)
|
84 |
response = vis_model.generate_content([txt_prompt_1,img])
|
85 |
-
|
86 |
-
return history
|
87 |
|
88 |
|
89 |
# Interface Code- Selector method
|
@@ -92,22 +91,20 @@ def sentence_builder(animal, place):
|
|
92 |
return f"""how many {animal}s from the {place} are shown in the picture?"""
|
93 |
|
94 |
# gradio block
|
95 |
-
|
96 |
-
|
97 |
with gr.Blocks(theme='snehilsanyal/scikit-learn') as app1:
|
98 |
-
outputbox = gr.Textbox(label="here are the plans...")
|
99 |
-
|
100 |
with gr.Column():
|
101 |
-
image_box = gr.Image(type="filepath")
|
102 |
-
btn = gr.Button("Make a Plan")
|
103 |
-
clicked = btn.click(app1_query,
|
104 |
-
[image_box],
|
105 |
-
outputbox
|
106 |
-
).then(app1_response,
|
107 |
-
[image_box],
|
108 |
-
outputbox
|
109 |
-
)
|
110 |
outputbox = gr.Textbox(label="here are the plans...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
gr.Markdown("""
|
112 |
# Make a Plan #
|
113 |
|
|
|
1 |
+
# refer to repo https://github.com/gradio-app/gradio/blob/main/demo/chatbot_multimodal/run.ipynb for enhancement
|
2 |
+
|
3 |
import PIL.Image
|
4 |
import gradio as gr
|
5 |
import base64
|
|
|
26 |
3- Notify Richard after shipment
|
27 |
"""
|
28 |
|
29 |
+
txt_display_1 = 'content of email'
|
30 |
|
31 |
import os
|
32 |
|
|
|
65 |
|
66 |
# Function that takes User Inputs and displays it on ChatUI
|
67 |
|
68 |
+
def app1_query(img):
|
69 |
if not img:
|
70 |
+
return txt_prompt_1
|
|
|
71 |
base64 = image_to_base64(img)
|
72 |
data_url = f"data:image/jpeg;base64,{base64}"
|
73 |
+
outputText = [(f"{txt_display_1} ![]({data_url})", None)]
|
74 |
+
return outputText
|
75 |
|
76 |
# Function that takes User Inputs, generates Response and displays on Chat UI
|
77 |
+
def app1_response(img):
|
78 |
if not img:
|
79 |
response = txt_model.generate_content(txt_prompt_1)
|
80 |
+
return response
|
|
|
81 |
|
82 |
else:
|
83 |
img = PIL.Image.open(img)
|
84 |
response = vis_model.generate_content([txt_prompt_1,img])
|
85 |
+
return response.text
|
|
|
86 |
|
87 |
|
88 |
# Interface Code- Selector method
|
|
|
91 |
return f"""how many {animal}s from the {place} are shown in the picture?"""
|
92 |
|
93 |
# gradio block
|
94 |
+
|
|
|
95 |
with gr.Blocks(theme='snehilsanyal/scikit-learn') as app1:
|
|
|
|
|
96 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
outputbox = gr.Textbox(label="here are the plans...")
|
98 |
+
image_box = gr.Image(type="filepath")
|
99 |
+
|
100 |
+
btn = gr.Button("Make a Plan")
|
101 |
+
clicked = btn.click(app1_query,
|
102 |
+
[image_box],
|
103 |
+
outputbox
|
104 |
+
).then(app1_response,
|
105 |
+
[image_box],
|
106 |
+
outputbox
|
107 |
+
)
|
108 |
gr.Markdown("""
|
109 |
# Make a Plan #
|
110 |
|