Spaces:
Sleeping
Sleeping
import requests | |
import traceback | |
from typing import Optional | |
def upload_to_freeimage(file_path: str, status_tracker) -> str: | |
""" | |
Upload a file to freeimage.host and return the direct image URL. | |
Args: | |
file_path: Path to the file to upload | |
status_tracker: StatusTracker instance for progress updates | |
Returns: | |
str: Direct URL for the uploaded image | |
Raises: | |
Exception: If upload fails for any reason | |
""" | |
try: | |
# API endpoint | |
url = 'https://freeimage.host/api/1/upload' | |
# Read image file | |
with open(file_path, 'rb') as image_file: | |
# Prepare the files and data for upload | |
files = { | |
'source': image_file | |
} | |
data = { | |
'key': '6d207e02198a847aa98d0a2a901485a5' # Free API key from freeimage.host | |
} | |
status_tracker.update_message("Uploading image to CDN...", 0.05) | |
# Make the request | |
response = requests.post(url, files=files, data=data, timeout=30) | |
response.raise_for_status() | |
# Get the direct image URL from response | |
result = response.json() | |
if result.get('status_code') == 200: | |
image_url = result['image']['url'] | |
status_tracker.add_step("Image uploaded to CDN", 0.08) | |
return image_url | |
else: | |
raise Exception(f"Upload failed: {result.get('error', 'Unknown error')}") | |
except requests.Timeout: | |
raise Exception("CDN is taking a coffee break (timeout)") | |
except requests.ConnectionError: | |
raise Exception("Can't reach CDN (is the internet on vacation?)") | |
except Exception as e: | |
print(f"CDN upload error: {str(e)}") | |
print(traceback.format_exc()) | |
raise Exception(f"CDN upload failed: {str(e)}") | |
def get_camera_motions() -> list: | |
""" | |
Get list of available camera motions from LumaAI. | |
Returns: | |
list: List of camera motion options | |
""" | |
try: | |
from lumaai import LumaAI | |
client = LumaAI() | |
motions = client.generations.camera_motion.list() | |
return ["None"] + motions | |
except: | |
return ["None", "camera orbit left", "camera orbit right", "camera dolly in", "camera dolly out"] | |