phyloforfun commited on
Commit
3ef828a
1 Parent(s): b6a03e8

downgrade mistralai temporarily

Browse files
Files changed (1) hide show
  1. vouchervision/utils_hf.py +11 -11
vouchervision/utils_hf.py CHANGED
@@ -73,24 +73,24 @@ def save_uploaded_file(directory, uploaded_file, image=None):
73
  if not os.path.exists(directory):
74
  os.makedirs(directory)
75
 
76
- full_path = os.path.join(directory, uploaded_file.name)
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}")
94
  return None
95
  else:
96
  # Handle image files
 
73
  if not os.path.exists(directory):
74
  os.makedirs(directory)
75
 
76
+ # Check if we're working with an UploadedFile or just a file path
77
+ if isinstance(uploaded_file, str):
78
+ full_path = os.path.join(directory, os.path.basename(uploaded_file))
79
+ else:
80
+ full_path = os.path.join(directory, uploaded_file.name)
81
+
82
  # Handle PDF and Image files differently
83
+ if uploaded_file.name.lower().endswith('.pdf') if not isinstance(uploaded_file, str) else full_path.lower().endswith('.pdf'):
 
 
 
 
 
84
  # Save PDF file
85
  try:
86
+ if not isinstance(uploaded_file, str):
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 if not isinstance(uploaded_file, str) else full_path}. Error: {e}")
94
  return None
95
  else:
96
  # Handle image files