Spaces:
Sleeping
Sleeping
added multiple images support
Browse files
app.py
CHANGED
@@ -32,21 +32,24 @@ def main():
|
|
32 |
|
33 |
goal = st.text_area("Goal", placeholder="Enter the goal here")
|
34 |
|
35 |
-
|
36 |
|
37 |
-
if
|
38 |
-
cols = st.columns(
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
41 |
|
42 |
|
43 |
if st.button("Submit"):
|
44 |
-
if not story or not goal or (entity_opt and not entity) or not
|
45 |
st.error("Please fill all the fields")
|
46 |
return
|
47 |
with col2:
|
48 |
with st.status("Generating response...", expanded=True):
|
49 |
-
response = get_gpt4V_response(story, goal, entity,
|
50 |
|
51 |
try:
|
52 |
response_json = get_str_to_json(response)
|
|
|
32 |
|
33 |
goal = st.text_area("Goal", placeholder="Enter the goal here")
|
34 |
|
35 |
+
images = st.file_uploader("Upload Image", type=['jpg', 'png'], accept_multiple_files=True)
|
36 |
|
37 |
+
if images:
|
38 |
+
cols = st.columns(len(images))
|
39 |
+
|
40 |
+
for i, image in enumerate(images):
|
41 |
+
with cols[i]:
|
42 |
+
image = Image.open(image)
|
43 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
44 |
|
45 |
|
46 |
if st.button("Submit"):
|
47 |
+
if not story or not goal or (entity_opt and not entity) or not images:
|
48 |
st.error("Please fill all the fields")
|
49 |
return
|
50 |
with col2:
|
51 |
with st.status("Generating response...", expanded=True):
|
52 |
+
response = get_gpt4V_response(story, goal, entity, images, temperature=temperature)
|
53 |
|
54 |
try:
|
55 |
response_json = get_str_to_json(response)
|
utils.py
CHANGED
@@ -68,10 +68,13 @@ data = {
|
|
68 |
}
|
69 |
|
70 |
|
71 |
-
def get_gpt4V_response(story, goal, entity,
|
72 |
# Convert image to base64
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
75 |
st.write("β
Image converted")
|
76 |
|
77 |
if entity:
|
@@ -87,12 +90,13 @@ def get_gpt4V_response(story, goal, entity, image, temperature=0.5):
|
|
87 |
|
88 |
st.write("β
Prompt created")
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
"
|
94 |
-
|
95 |
-
|
|
|
96 |
|
97 |
st.write("π Getting Response from GPT4V")
|
98 |
response = client.chat.completions.create(
|
|
|
68 |
}
|
69 |
|
70 |
|
71 |
+
def get_gpt4V_response(story, goal, entity, images, temperature=0.5):
|
72 |
# Convert image to base64
|
73 |
+
image_urls = []
|
74 |
+
for i, image in enumerate(images):
|
75 |
+
image_b64 = im_2_b64(image)
|
76 |
+
image_url = f"data:image/jpeg;base64,{image_b64.decode('utf-8')}"
|
77 |
+
image_urls.append(image_url)
|
78 |
st.write("β
Image converted")
|
79 |
|
80 |
if entity:
|
|
|
90 |
|
91 |
st.write("β
Prompt created")
|
92 |
|
93 |
+
for image_url in image_urls:
|
94 |
+
content.append({
|
95 |
+
"type": "image_url",
|
96 |
+
"image_url": {
|
97 |
+
"url": image_url,
|
98 |
+
},
|
99 |
+
})
|
100 |
|
101 |
st.write("π Getting Response from GPT4V")
|
102 |
response = client.chat.completions.create(
|