phyloforfun commited on
Commit
b6a03e8
·
1 Parent(s): ce2a599

downgrade mistralai temporarily

Browse files
Files changed (2) hide show
  1. app.py +9 -0
  2. vouchervision/utils_hf.py +7 -8
app.py CHANGED
@@ -269,6 +269,15 @@ def handle_image_upload_and_gallery_hf(uploaded_files):
269
  report_violation(uploaded_file.name, is_hf=st.session_state['is_hf'])
270
  st.error("Warning: You uploaded an image that violates our terms of service.")
271
  return True
 
 
 
 
 
 
 
 
 
272
 
273
  # Save the uploaded file (PDF or image)
274
  file_path = save_uploaded_file(st.session_state['dir_uploaded_images'], uploaded_file)
 
269
  report_violation(uploaded_file.name, is_hf=st.session_state['is_hf'])
270
  st.error("Warning: You uploaded an image that violates our terms of service.")
271
  return True
272
+
273
+ # Print out details of the uploaded file for debugging
274
+ st.write(f"Uploaded file: {uploaded_file.name}")
275
+ st.write(f"File size: {len(uploaded_file.getvalue())} bytes")
276
+
277
+ # Check if the uploaded file is not empty
278
+ if len(uploaded_file.getvalue()) == 0:
279
+ st.error(f"The uploaded file {uploaded_file.name} is empty.")
280
+ continue
281
 
282
  # Save the uploaded file (PDF or image)
283
  file_path = save_uploaded_file(st.session_state['dir_uploaded_images'], uploaded_file)
vouchervision/utils_hf.py CHANGED
@@ -77,18 +77,17 @@ def save_uploaded_file(directory, uploaded_file, image=None):
77
 
78
  # Handle PDF and Image files differently
79
  if uploaded_file.name.lower().endswith('.pdf'):
 
 
 
 
 
80
  # Save PDF file
81
  try:
82
  with open(full_path, 'wb') as out_file:
83
- if hasattr(uploaded_file, 'read'):
84
- # This is a file-like object
85
- out_file.write(uploaded_file.read())
86
- else:
87
- # If uploaded_file is a path string
88
- with open(uploaded_file, 'rb') as fd:
89
- out_file.write(fd.read())
90
  if os.path.getsize(full_path) == 0:
91
- raise ValueError(f"The file {uploaded_file.name} is empty.")
92
  return full_path
93
  except Exception as e:
94
  st.error(f"Failed to save PDF file {uploaded_file.name}. Error: {e}")
 
77
 
78
  # Handle PDF and Image files differently
79
  if uploaded_file.name.lower().endswith('.pdf'):
80
+ # Check if the uploaded file has content
81
+ if len(uploaded_file.getvalue()) == 0:
82
+ st.error(f"The uploaded PDF file {uploaded_file.name} is empty.")
83
+ return None
84
+
85
  # Save PDF file
86
  try:
87
  with open(full_path, 'wb') as out_file:
88
+ out_file.write(uploaded_file.getvalue())
 
 
 
 
 
 
89
  if os.path.getsize(full_path) == 0:
90
+ raise ValueError(f"The file {uploaded_file.name} is empty after saving.")
91
  return full_path
92
  except Exception as e:
93
  st.error(f"Failed to save PDF file {uploaded_file.name}. Error: {e}")