Spaces:
Runtime error
Runtime error
Download Backend/utils/cloudinary_uploader.py from jinksQspider/ExamCraftAI: direct link, hf CLI and curl.
- Browser
- Download file 909 Bytes
-
https://huggingface.co/spaces/jinksQspider/ExamCraftAI/resolve/main/Backend/utils/cloudinary_uploader.py
- Command line
-
hf download hf://spaces/jinksQspider/ExamCraftAI/Backend/utils/cloudinary_uploader.py
-
curl -L -o cloudinary_uploader.py https://huggingface.co/spaces/jinksQspider/ExamCraftAI/resolve/main/Backend/utils/cloudinary_uploader.py
909 Bytes
| import os | |
| import mimetypes | |
| import cloudinary | |
| import cloudinary.uploader | |
| def _is_configured(): | |
| return bool(os.getenv("CLOUDINARY_URL")) | |
| def _resource_type_for(path): | |
| mime_type, _ = mimetypes.guess_type(path) | |
| if mime_type and mime_type.startswith("image/"): | |
| return "image" | |
| return "raw" | |
| def upload_file(path, folder="examcraft", public_id=None, tags=None): | |
| if not _is_configured(): | |
| return None | |
| resource_type = _resource_type_for(path) | |
| options = { | |
| "folder": folder, | |
| "resource_type": resource_type, | |
| } | |
| if public_id: | |
| options["public_id"] = public_id | |
| if tags: | |
| options["tags"] = tags | |
| result = cloudinary.uploader.upload(path, **options) | |
| return { | |
| "url": result.get("secure_url") or result.get("url"), | |
| "public_id": result.get("public_id"), | |
| "resource_type": result.get("resource_type"), | |
| } | |