Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -170,29 +170,33 @@ def main():
|
|
170 |
# Upload button
|
171 |
if st.button("Tải lên Hình ảnh để sửa chữa"):
|
172 |
if correct_grade and st.session_state.uploaded_image:
|
173 |
-
# Save the image temporarily
|
174 |
temp_image_path = f"temp_image_{hash(uploaded_file.name)}.png"
|
175 |
-
|
176 |
-
|
177 |
try:
|
|
|
|
|
|
|
|
|
178 |
# Upload to Cloudinary
|
179 |
cloudinary_result = upload_to_cloudinary(temp_image_path, correct_grade)
|
180 |
-
|
181 |
if isinstance(cloudinary_result, dict):
|
182 |
st.success(f"Hình ảnh đã được tải lên thành công cho màu {correct_grade}")
|
183 |
st.write(f"URL công khai: {cloudinary_result['upload_result']['secure_url']}")
|
184 |
else:
|
185 |
st.error(cloudinary_result)
|
186 |
-
|
187 |
# Clean up temporary file
|
188 |
os.remove(temp_image_path)
|
189 |
-
|
190 |
except Exception as e:
|
191 |
st.error(f"Tải lên thất bại: {str(e)}")
|
192 |
else:
|
193 |
st.warning("Vui lòng chọn màu đúng trước khi tải lên.")
|
194 |
-
|
195 |
-
|
196 |
|
197 |
st.markdown("---")
|
198 |
st.markdown("Tạo bởi ❤️ với Streamlit")
|
|
|
170 |
# Upload button
|
171 |
if st.button("Tải lên Hình ảnh để sửa chữa"):
|
172 |
if correct_grade and st.session_state.uploaded_image:
|
173 |
+
# Save the uploaded image temporarily and resize it
|
174 |
temp_image_path = f"temp_image_{hash(uploaded_file.name)}.png"
|
175 |
+
|
176 |
+
# Resize image to 256x256
|
177 |
try:
|
178 |
+
uploaded_image = Image.open(st.session_state.uploaded_image)
|
179 |
+
resized_image = uploaded_image.resize((256, 256)) # Resize to 256x256
|
180 |
+
resized_image.save(temp_image_path) # Save the resized image
|
181 |
+
|
182 |
# Upload to Cloudinary
|
183 |
cloudinary_result = upload_to_cloudinary(temp_image_path, correct_grade)
|
184 |
+
|
185 |
if isinstance(cloudinary_result, dict):
|
186 |
st.success(f"Hình ảnh đã được tải lên thành công cho màu {correct_grade}")
|
187 |
st.write(f"URL công khai: {cloudinary_result['upload_result']['secure_url']}")
|
188 |
else:
|
189 |
st.error(cloudinary_result)
|
190 |
+
|
191 |
# Clean up temporary file
|
192 |
os.remove(temp_image_path)
|
193 |
+
|
194 |
except Exception as e:
|
195 |
st.error(f"Tải lên thất bại: {str(e)}")
|
196 |
else:
|
197 |
st.warning("Vui lòng chọn màu đúng trước khi tải lên.")
|
198 |
+
else:
|
199 |
+
st.info("Tải lên hình ảnh để xem các dự đoán.")
|
200 |
|
201 |
st.markdown("---")
|
202 |
st.markdown("Tạo bởi ❤️ với Streamlit")
|