Spaces:
Running on Zero
Running on Zero
Download utils.py from TechKick/enterprise-ai-document-intelligence-platform: direct link, hf CLI and curl.
- Browser
- Download file 941 Bytes
-
https://huggingface.co/spaces/TechKick/enterprise-ai-document-intelligence-platform/resolve/main/utils.py
- Command line
-
hf download hf://spaces/TechKick/enterprise-ai-document-intelligence-platform/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/TechKick/enterprise-ai-document-intelligence-platform/resolve/main/utils.py
941 Bytes
| import os | |
| import shutil | |
| TEMP_DIR = "temp" | |
| os.makedirs(TEMP_DIR, exist_ok=True) | |
| def save_uploaded_file(file): | |
| if file is None: | |
| return None | |
| file_path = getattr(file, "name", file) | |
| if not os.path.exists(file_path): | |
| return None | |
| destination = os.path.join( | |
| TEMP_DIR, | |
| os.path.basename(file_path) | |
| ) | |
| shutil.copy(file_path, destination) | |
| return destination | |
| def cleanup_temp_files(): | |
| """Removes temporary files from temp/ directory.""" | |
| if os.path.exists(TEMP_DIR): | |
| for item in os.listdir(TEMP_DIR): | |
| if item != ".gitkeep": | |
| item_path = os.path.join(TEMP_DIR, item) | |
| try: | |
| if os.path.isfile(item_path): | |
| os.remove(item_path) | |
| elif os.path.isdir(item_path): | |
| shutil.rmtree(item_path) | |
| except Exception: | |
| pass | |