Spaces:
Paused
Paused
| import os | |
| import os.path | |
| import cloudinary | |
| import cloudinary.uploader | |
| import cloudinary.api | |
| # Import the CloudinaryImage and CloudinaryVideo methods for the simplified syntax used in this guide | |
| from cloudinary import CloudinaryImage | |
| from cloudinary import CloudinaryVideo | |
| from facefusion.filesystem import is_image, is_video | |
| cloudinary.config( | |
| cloud_name = os.environ.get('CLOUDINARY_CLOUD_NAME'), | |
| api_key = os.environ.get('CLOUDINARY_API_KEY'), | |
| api_secret = os.environ.get('CLOUDINARY_API_SECRET'), | |
| secure = True | |
| ) | |
| def is_large_file(file_path : str) -> bool: | |
| return os.path.getsize(file_path) > 100*1*1024*1024 | |
| def upload_file(file_path : str): | |
| file_resource_type = '' | |
| if is_image(file_path): | |
| file_resource_type = 'image' | |
| if is_video(file_path): | |
| file_resource_type = 'video' | |
| if is_large_file(file_path): | |
| return cloudinary.uploader.upload_large(file_path, | |
| folder = os.environ.get('CLOUDINARY_UPLOAD_FOLDER'), | |
| overwrite = True, | |
| resource_type = file_resource_type) | |
| else: | |
| return cloudinary.uploader.upload(file_path, | |
| folder = os.environ.get('CLOUDINARY_UPLOAD_FOLDER'), | |
| overwrite = True, | |
| resource_type = file_resource_type) |