Spaces:
Sleeping
Sleeping
Download lib/cloudinary_service.py from thesis-sd3a/digital-art-api: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/thesis-sd3a/digital-art-api/resolve/refs%2Fpr%2F1/lib/cloudinary_service.py
- Command line
-
hf download hf://spaces/thesis-sd3a/digital-art-api@refs/pr/1/lib/cloudinary_service.py
-
curl -L -o cloudinary_service.py https://huggingface.co/spaces/thesis-sd3a/digital-art-api/resolve/refs%2Fpr%2F1/lib/cloudinary_service.py
1.02 kB
| import cloudinary | |
| import cloudinary.uploader | |
| import os | |
| from dotenv import load_dotenv | |
| from fastapi import HTTPException, UploadFile, File | |
| load_dotenv() | |
| cloudinary.config( | |
| cloud_name=os.getenv("CLOUDINARY_NAME"), | |
| api_key=os.getenv("CLOUDINARY_KEY"), | |
| api_secret=os.getenv("CLOUDINARY_SECRET"), | |
| ) | |
| def cloudinary_uploader(image_file: UploadFile = File(...)): | |
| try: | |
| image_file.file.seek(0) | |
| response = cloudinary.uploader.upload( | |
| image_file.file, | |
| resource_type="image", | |
| folder="temp_plag_scans", | |
| ) | |
| return response | |
| except Exception as e: | |
| raise HTTPException(status_code=400, detail=str(e)) | |
| def delete_image(public_id): | |
| try: | |
| result = cloudinary.uploader.destroy( | |
| public_id, | |
| invalidate=True, | |
| ) | |
| if result.get("result") == "ok": | |
| return True | |
| else: | |
| return False | |
| except Exception as e: | |
| raise HTTPException(status_code=400, detail=str(e)) |