Spaces:
Running
Running
Commit
·
b42220b
1
Parent(s):
f324f16
updates
Browse files- app.py +3 -2
- vouchervision/utils_hf.py +24 -1
app.py
CHANGED
|
@@ -14,7 +14,7 @@ from vouchervision.vouchervision_main import voucher_vision
|
|
| 14 |
from vouchervision.general_utils import test_GPU, get_cfg_from_full_path, summarize_expense_report, validate_dir
|
| 15 |
from vouchervision.model_maps import ModelMaps
|
| 16 |
from vouchervision.API_validation import APIvalidation
|
| 17 |
-
from vouchervision.utils_hf import setup_streamlit_config, save_uploaded_file, save_uploaded_local, save_uploaded_file_local
|
| 18 |
from vouchervision.data_project import convert_pdf_to_jpg
|
| 19 |
from vouchervision.utils_LLM import check_system_gpus
|
| 20 |
from vouchervision.OCR_google_cloud_vision import SafetyCheck
|
|
@@ -266,7 +266,8 @@ def handle_image_upload_and_gallery_hf(uploaded_files):
|
|
| 266 |
|
| 267 |
if SAFE.check_for_inappropriate_content(uploaded_file):
|
| 268 |
clear_image_uploads()
|
| 269 |
-
|
|
|
|
| 270 |
return True
|
| 271 |
|
| 272 |
|
|
|
|
| 14 |
from vouchervision.general_utils import test_GPU, get_cfg_from_full_path, summarize_expense_report, validate_dir
|
| 15 |
from vouchervision.model_maps import ModelMaps
|
| 16 |
from vouchervision.API_validation import APIvalidation
|
| 17 |
+
from vouchervision.utils_hf import setup_streamlit_config, save_uploaded_file, save_uploaded_local, save_uploaded_file_local, report_violation
|
| 18 |
from vouchervision.data_project import convert_pdf_to_jpg
|
| 19 |
from vouchervision.utils_LLM import check_system_gpus
|
| 20 |
from vouchervision.OCR_google_cloud_vision import SafetyCheck
|
|
|
|
| 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 |
|
| 273 |
|
vouchervision/utils_hf.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import os, json, re
|
| 2 |
from googleapiclient.discovery import build
|
| 3 |
from googleapiclient.http import MediaFileUpload
|
| 4 |
from google.oauth2 import service_account
|
|
@@ -146,7 +146,30 @@ def check_prompt_yaml_filename(fname):
|
|
| 146 |
return True
|
| 147 |
else:
|
| 148 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
# Function to upload files to Google Drive
|
| 151 |
def upload_to_drive(filepath, filename, is_hf=True, cfg_private=None, do_upload = True):
|
| 152 |
if do_upload:
|
|
|
|
| 1 |
+
import os, json, re, datetime, tempfile, yaml
|
| 2 |
from googleapiclient.discovery import build
|
| 3 |
from googleapiclient.http import MediaFileUpload
|
| 4 |
from google.oauth2 import service_account
|
|
|
|
| 146 |
return True
|
| 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"
|
| 154 |
|
| 155 |
+
# Create a temporary YAML file
|
| 156 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.yaml') as temp_file:
|
| 157 |
+
# Example content - customize as needed
|
| 158 |
+
content = {
|
| 159 |
+
'violation_time': current_time,
|
| 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
|
| 174 |
def upload_to_drive(filepath, filename, is_hf=True, cfg_private=None, do_upload = True):
|
| 175 |
if do_upload:
|