phyloforfun commited on
Commit
8aa7838
1 Parent(s): b42220b
Files changed (2) hide show
  1. app.py +1 -1
  2. vouchervision/utils_hf.py +8 -7
app.py CHANGED
@@ -266,7 +266,7 @@ def handle_image_upload_and_gallery_hf(uploaded_files):
266
 
267
  if SAFE.check_for_inappropriate_content(uploaded_file):
268
  clear_image_uploads()
269
- report_violation(uploaded_file.name.lower(), 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
 
 
266
 
267
  if SAFE.check_for_inappropriate_content(uploaded_file):
268
  clear_image_uploads()
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
 
vouchervision/utils_hf.py CHANGED
@@ -147,7 +147,7 @@ def check_prompt_yaml_filename(fname):
147
  else:
148
  return False
149
 
150
- def report_violation(file_name, is_hf=True, cfg_private=None, do_upload=True):
151
  # Format the current date and time
152
  current_time = datetime.datetime.now().strftime("%Y_%m_%d__%H_%M_%S")
153
  file_name = f"violation_{current_time}.yaml"
@@ -160,14 +160,15 @@ def report_violation(file_name, is_hf=True, cfg_private=None, do_upload=True):
160
  'notes': 'This is an autogenerated violation report.',
161
  'name_of_file': file_name,
162
  }
 
163
  yaml.dump(content, temp_file, default_flow_style=False)
164
- temp_file_path = temp_file.name # Save the temp file path to use after closing
165
 
166
- # Now, upload the temporary file
167
- try:
168
- upload_to_drive(temp_file_path, file_name, is_hf=is_hf, cfg_private=cfg_private, do_upload=do_upload)
169
- finally:
170
- os.remove(temp_file_path) # Ensure the temporary file is deleted after uploading
171
 
172
 
173
  # Function to upload files to Google Drive
 
147
  else:
148
  return False
149
 
150
+ def report_violation(file_name, is_hf=True):
151
  # Format the current date and time
152
  current_time = datetime.datetime.now().strftime("%Y_%m_%d__%H_%M_%S")
153
  file_name = f"violation_{current_time}.yaml"
 
160
  'notes': 'This is an autogenerated violation report.',
161
  'name_of_file': file_name,
162
  }
163
+ # Write the content to the temporary YAML file in text mode
164
  yaml.dump(content, temp_file, default_flow_style=False)
165
+ temp_filepath = temp_file.name
166
 
167
+ # Now upload the temporary file
168
+ upload_to_drive(temp_filepath, file_name, is_hf=is_hf)
169
+
170
+ # Optionally, delete the temporary file if you don't want it to remain on disk after uploading
171
+ os.remove(temp_filepath)
172
 
173
 
174
  # Function to upload files to Google Drive