ziyadsuper2017 commited on
Commit
aa719f7
1 Parent(s): 6e074fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -26
app.py CHANGED
@@ -78,29 +78,36 @@ conn.close()
78
  # Separate section for image uploading
79
  st.title("Image Description Generator")
80
 
81
- uploaded_file = st.file_uploader("Upload an image here", type=["png", "jpg", "jpeg"])
82
-
83
- # Text input for asking questions about the image
84
- image_question = st.text_input("Ask something about the image:")
85
-
86
- if uploaded_file and image_question:
87
- image_parts = [
88
- {
89
- "mime_type": uploaded_file.type,
90
- "data": uploaded_file.read()
91
- },
92
- ]
93
-
94
- prompt_parts = [
95
- image_question,
96
- image_parts[0],
97
- ]
98
-
99
- model = genai.GenerativeModel(
100
- model_name="gemini-pro-vision",
101
- generation_config=generation_config,
102
- safety_settings=safety_settings
103
- )
104
-
105
- response = model.generate_content(prompt_parts)
106
- st.markdown(f"**Model's answer:** {response.text}")
 
 
 
 
 
 
 
 
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)