File size: 2,405 Bytes
599abe6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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"]