Update app.py
Browse files
app.py
CHANGED
@@ -26,12 +26,9 @@ For example:
|
|
26 |
3- Notify Richard after shipment
|
27 |
"""
|
28 |
|
29 |
-
txt_display_1 = 'content of
|
30 |
-
|
31 |
import os
|
32 |
-
|
33 |
GOOGLE_API_KEY=os.getenv('GOOGLE_API_KEY')
|
34 |
-
|
35 |
genai.configure(api_key=GOOGLE_API_KEY)
|
36 |
|
37 |
# Image to Base 64 Converter
|
@@ -40,31 +37,6 @@ def image_to_base64(image_path):
|
|
40 |
encoded_string = base64.b64encode(img.read())
|
41 |
return encoded_string.decode('utf-8')
|
42 |
|
43 |
-
# Function that takes User Inputs and displays it on ChatUI
|
44 |
-
def app2_query(history,txt,img):
|
45 |
-
if not img:
|
46 |
-
history += [(txt,None)]
|
47 |
-
return history
|
48 |
-
base64 = image_to_base64(img)
|
49 |
-
data_url = f"data:image/jpeg;base64,{base64}"
|
50 |
-
history += [(f"{txt} ![]({data_url})", None)]
|
51 |
-
return history
|
52 |
-
|
53 |
-
# Function that takes User Inputs, generates Response and displays on Chat UI
|
54 |
-
def app2_response(history,text,img):
|
55 |
-
if not img:
|
56 |
-
response = txt_model.generate_content(text)
|
57 |
-
history += [(None,response.text)]
|
58 |
-
return history
|
59 |
-
|
60 |
-
else:
|
61 |
-
img = PIL.Image.open(img)
|
62 |
-
response = vis_model.generate_content([text,img])
|
63 |
-
history += [(None,response.text)]
|
64 |
-
return history
|
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
|
@@ -85,11 +57,6 @@ def app1_response(img):
|
|
85 |
return response.text
|
86 |
|
87 |
|
88 |
-
# Interface Code- Selector method
|
89 |
-
|
90 |
-
def sentence_builder(animal, place):
|
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:
|
@@ -113,40 +80,10 @@ with gr.Blocks(theme='snehilsanyal/scikit-learn') as app1:
|
|
113 |
- await LLM Bot (Gemini, in this case) response
|
114 |
- receive THREE actionable items
|
115 |
|
116 |
-
|
117 |
[demo](https://youtu.be/lJ4jIAEVRNY)
|
118 |
|
119 |
""")
|
120 |
|
121 |
-
with gr.Blocks(theme='snehilsanyal/scikit-learn') as app2:
|
122 |
-
gr.Markdown("check the image...")
|
123 |
-
with gr.Row():
|
124 |
-
image_box = gr.Image(type="filepath")
|
125 |
-
|
126 |
-
chatbot = gr.Chatbot(
|
127 |
-
scale = 2,
|
128 |
-
height=750
|
129 |
-
)
|
130 |
-
text_box = gr.Dropdown(
|
131 |
-
["what is in the image",
|
132 |
-
"provide alternative title for the image",
|
133 |
-
"how many parts can be seen in the picture?",
|
134 |
-
"check ID and expiration date"],
|
135 |
-
label="Select--",
|
136 |
-
info="ask Bot"
|
137 |
-
)
|
138 |
-
|
139 |
-
btn = gr.Button("Submit")
|
140 |
-
clicked = btn.click(app2_query,
|
141 |
-
[chatbot,text_box,image_box],
|
142 |
-
chatbot
|
143 |
-
).then(app2_response,
|
144 |
-
[chatbot,text_box],
|
145 |
-
chatbot
|
146 |
-
)
|
147 |
-
with gr.Blocks(theme='snehilsanyal/scikit-learn') as demo:
|
148 |
-
gr.Markdown("## Workflow Bot ##")
|
149 |
-
gr.TabbedInterface([app1, app2], ["Make a Plan!", "Check This!"])
|
150 |
|
151 |
-
|
152 |
-
|
|
|
26 |
3- Notify Richard after shipment
|
27 |
"""
|
28 |
|
29 |
+
txt_display_1 = 'content of the letter: '
|
|
|
30 |
import os
|
|
|
31 |
GOOGLE_API_KEY=os.getenv('GOOGLE_API_KEY')
|
|
|
32 |
genai.configure(api_key=GOOGLE_API_KEY)
|
33 |
|
34 |
# Image to Base 64 Converter
|
|
|
37 |
encoded_string = base64.b64encode(img.read())
|
38 |
return encoded_string.decode('utf-8')
|
39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
def app1_query(img):
|
41 |
if not img:
|
42 |
return txt_prompt_1
|
|
|
57 |
return response.text
|
58 |
|
59 |
|
|
|
|
|
|
|
|
|
|
|
60 |
# gradio block
|
61 |
|
62 |
with gr.Blocks(theme='snehilsanyal/scikit-learn') as app1:
|
|
|
80 |
- await LLM Bot (Gemini, in this case) response
|
81 |
- receive THREE actionable items
|
82 |
|
|
|
83 |
[demo](https://youtu.be/lJ4jIAEVRNY)
|
84 |
|
85 |
""")
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
+
app1.queue()
|
89 |
+
app1.launch()
|