Spaces:
Paused
Paused
Create cloudinary.py
Browse files- cloudinary.py +38 -0
cloudinary.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import os.path
|
| 3 |
+
import cloudinary
|
| 4 |
+
import cloudinary.uploader
|
| 5 |
+
import cloudinary.api
|
| 6 |
+
|
| 7 |
+
# Import the CloudinaryImage and CloudinaryVideo methods for the simplified syntax used in this guide
|
| 8 |
+
from cloudinary import CloudinaryImage
|
| 9 |
+
from cloudinary import CloudinaryVideo
|
| 10 |
+
|
| 11 |
+
from facefusion.filesystem import is_image, is_video
|
| 12 |
+
|
| 13 |
+
cloudinary.config(
|
| 14 |
+
cloud_name = os.environ.get('CLOUDINARY_CLOUD_NAME'),
|
| 15 |
+
api_key = os.environ.get('CLOUDINARY_API_KEY'),
|
| 16 |
+
api_secret = os.environ.get('CLOUDINARY_API_SECRET'),
|
| 17 |
+
secure = True
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
def is_large_file(file_path : str) -> bool:
|
| 21 |
+
return os.path.getsize(file_path) > 100*1*1024*1024
|
| 22 |
+
|
| 23 |
+
def upload_file(file_path : str):
|
| 24 |
+
file_resource_type = ''
|
| 25 |
+
if is_image(file_path):
|
| 26 |
+
file_resource_type = 'image'
|
| 27 |
+
if is_video(file_path):
|
| 28 |
+
file_resource_type = 'video'
|
| 29 |
+
if is_large_file(file_path):
|
| 30 |
+
return cloudinary.uploader.upload_large(file_path,
|
| 31 |
+
folder = os.environ.get('CLOUDINARY_UPLOAD_FOLDER'),
|
| 32 |
+
overwrite = True,
|
| 33 |
+
resource_type = file_resource_type)
|
| 34 |
+
else:
|
| 35 |
+
return cloudinary.uploader.upload(file_path,
|
| 36 |
+
folder = os.environ.get('CLOUDINARY_UPLOAD_FOLDER'),
|
| 37 |
+
overwrite = True,
|
| 38 |
+
resource_type = file_resource_type)
|