Spaces:
Runtime error
Runtime error
Download file_utils.py from LeeHan23/nutribot-api: direct link, hf CLI and curl.
- Browser
- Download file 915 Bytes
-
https://huggingface.co/spaces/LeeHan23/nutribot-api/resolve/main/file_utils.py
- Command line
-
hf download hf://spaces/LeeHan23/nutribot-api/file_utils.py
-
curl -L -o file_utils.py https://huggingface.co/spaces/LeeHan23/nutribot-api/resolve/main/file_utils.py
915 Bytes
| import os | |
| from fastapi import UploadFile | |
| from uploader import save_uploaded_file_as_text | |
| BASE_INSTRUCTIONS_DIR = os.path.join("data", "instructions") | |
| def save_instruction_file(user_id: str, uploaded_file: UploadFile): | |
| """ | |
| Saves a user-uploaded file as their specific instruction text. | |
| """ | |
| if not user_id or not uploaded_file: | |
| print("Error: User ID and an uploaded file must be provided.") | |
| return None | |
| user_instructions_dir = os.path.join(BASE_INSTRUCTIONS_DIR, str(user_id)) | |
| os.makedirs(user_instructions_dir, exist_ok=True) | |
| try: | |
| saved_path = save_uploaded_file_as_text(uploaded_file, user_instructions_dir) | |
| print(f"Successfully saved new instructions for user '{user_id}' at: {saved_path}") | |
| return saved_path | |
| except Exception as e: | |
| print(f"Error saving instruction file for user '{user_id}': {e}") | |
| return None |