Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -170,16 +170,23 @@ 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 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 |
-
|
179 |
-
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
|
182 |
-
#
|
183 |
cloudinary_result = upload_to_cloudinary(temp_image_path, correct_grade)
|
184 |
|
185 |
if isinstance(cloudinary_result, dict):
|
@@ -188,7 +195,7 @@ def main():
|
|
188 |
else:
|
189 |
st.error(cloudinary_result)
|
190 |
|
191 |
-
#
|
192 |
os.remove(temp_image_path)
|
193 |
|
194 |
except Exception as e:
|
|
|
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 |
try:
|
174 |
+
# Đọc tệp từ `st.session_state.uploaded_image`
|
175 |
+
uploaded_file = st.session_state.uploaded_image
|
176 |
+
|
177 |
+
# Kiểm tra nếu uploaded_file đã là PIL Image
|
178 |
+
if isinstance(uploaded_file, Image.Image):
|
179 |
+
resized_image = uploaded_file.resize((512, 512))
|
180 |
+
else:
|
181 |
+
# Nếu là file-like object, mở bằng Pillow
|
182 |
+
uploaded_image = Image.open(uploaded_file)
|
183 |
+
resized_image = uploaded_image.resize((512, 512))
|
184 |
+
|
185 |
+
# Lưu tệp ảnh resize tạm thời
|
186 |
+
temp_image_path = f"temp_image_{hash(uploaded_file.name) if hasattr(uploaded_file, 'name') else 'unknown'}.png"
|
187 |
+
resized_image.save(temp_image_path)
|
188 |
|
189 |
+
# Tải ảnh lên Cloudinary
|
190 |
cloudinary_result = upload_to_cloudinary(temp_image_path, correct_grade)
|
191 |
|
192 |
if isinstance(cloudinary_result, dict):
|
|
|
195 |
else:
|
196 |
st.error(cloudinary_result)
|
197 |
|
198 |
+
# Xóa tệp tạm
|
199 |
os.remove(temp_image_path)
|
200 |
|
201 |
except Exception as e:
|