Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -45,6 +45,29 @@ def llm_response(history,text,img):
|
|
45 |
history += [(None,response.text)]
|
46 |
return history
|
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
# Interface Code- Selector method
|
49 |
|
50 |
def sentence_builder(animal, place):
|
@@ -59,7 +82,7 @@ with gr.Blocks(theme='snehilsanyal/scikit-learn') as app1:
|
|
59 |
image_box = gr.Image(type="filepath")
|
60 |
|
61 |
outputbox = gr.Textbox(label="Output")
|
62 |
-
|
63 |
["what is in the image",
|
64 |
"provide alternative title for the image",
|
65 |
"how many birds can be seen in the picture?"],
|
@@ -67,11 +90,11 @@ with gr.Blocks(theme='snehilsanyal/scikit-learn') as app1:
|
|
67 |
)
|
68 |
|
69 |
btn = gr.Button("Submit")
|
70 |
-
clicked = btn.click(
|
71 |
-
[
|
72 |
outputbox
|
73 |
-
).then(
|
74 |
-
[
|
75 |
outputbox
|
76 |
)
|
77 |
gr.Markdown("""
|
|
|
45 |
history += [(None,response.text)]
|
46 |
return history
|
47 |
|
48 |
+
# Function that takes User Inputs and displays it on ChatUI
|
49 |
+
def output_query_message(txt,img):
|
50 |
+
if not img:
|
51 |
+
return txt
|
52 |
+
base64 = image_to_base64(img)
|
53 |
+
data_url = f"data:image/jpeg;base64,{base64}"
|
54 |
+
outputText = [(f"{txt} ![]({data_url})", None)]
|
55 |
+
return outputText
|
56 |
+
|
57 |
+
# Function that takes User Inputs, generates Response and displays on Chat UI
|
58 |
+
def output_llm_response(text,img):
|
59 |
+
if not img:
|
60 |
+
response = txt_model.generate_content(text)
|
61 |
+
history = [(None,response.text)]
|
62 |
+
return history
|
63 |
+
|
64 |
+
else:
|
65 |
+
img = PIL.Image.open(img)
|
66 |
+
response = vis_model.generate_content([text,img])
|
67 |
+
history = [(None,response.text)]
|
68 |
+
return history
|
69 |
+
|
70 |
+
|
71 |
# Interface Code- Selector method
|
72 |
|
73 |
def sentence_builder(animal, place):
|
|
|
82 |
image_box = gr.Image(type="filepath")
|
83 |
|
84 |
outputbox = gr.Textbox(label="Output")
|
85 |
+
text_box = gr.Dropdown(
|
86 |
["what is in the image",
|
87 |
"provide alternative title for the image",
|
88 |
"how many birds can be seen in the picture?"],
|
|
|
90 |
)
|
91 |
|
92 |
btn = gr.Button("Submit")
|
93 |
+
clicked = btn.click(output_query_message,
|
94 |
+
[text_box,image_box],
|
95 |
outputbox
|
96 |
+
).then(output_llm_response,
|
97 |
+
[text_box,image_box],
|
98 |
outputbox
|
99 |
)
|
100 |
gr.Markdown("""
|