Spaces:
Runtime error
Runtime error
ziyadsuper2017
commited on
Commit
•
aa719f7
1
Parent(s):
6e074fc
Update app.py
Browse files
app.py
CHANGED
@@ -78,29 +78,36 @@ conn.close()
|
|
78 |
# Separate section for image uploading
|
79 |
st.title("Image Description Generator")
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
# Separate section for image uploading
|
79 |
st.title("Image Description Generator")
|
80 |
|
81 |
+
# Change the file_uploader to accept multiple files
|
82 |
+
uploaded_files = st.file_uploader("Upload one or more images here", type=["png", "jpg", "jpeg"], accept_multiple_files=True)
|
83 |
+
|
84 |
+
# Text input for asking questions about the images
|
85 |
+
image_question = st.text_input("Ask something about the images:")
|
86 |
+
|
87 |
+
# Check if the user has entered a question
|
88 |
+
if image_question:
|
89 |
+
# Create a list of image parts from the uploaded files
|
90 |
+
image_parts = []
|
91 |
+
for uploaded_file in uploaded_files:
|
92 |
+
image_parts.append({
|
93 |
+
"mime_type": uploaded_file.type,
|
94 |
+
"data": uploaded_file.read()
|
95 |
+
})
|
96 |
+
|
97 |
+
# Create a prompt parts list with the question and the image parts
|
98 |
+
prompt_parts = [image_question] + image_parts
|
99 |
+
|
100 |
+
# Use the gemini-pro-vision model to generate a response
|
101 |
+
model = genai.GenerativeModel(
|
102 |
+
model_name="gemini-pro-vision",
|
103 |
+
generation_config=generation_config,
|
104 |
+
safety_settings=safety_settings
|
105 |
+
)
|
106 |
+
|
107 |
+
response = model.generate_content(prompt_parts)
|
108 |
+
st.markdown(f"**Model's answer:** {response.text}")
|
109 |
+
|
110 |
+
# Loop through the uploaded files and display them
|
111 |
+
for uploaded_file in uploaded_files:
|
112 |
+
# Display the image
|
113 |
+
st.image(uploaded_file)
|