File size: 5,712 Bytes
69b845c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6757240
 
d595b97
69b845c
d595b97
 
 
69b845c
d595b97
 
 
 
 
 
 
 
 
 
 
 
 
 
69b845c
 
 
 
 
 
 
 
 
 
 
 
 
6757240
 
 
 
82229f9
 
 
 
 
 
69b845c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82229f9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Main application script
document.addEventListener('DOMContentLoaded', function() {
    // Initialize all feather icons
    feather.replace();
    
    // Slider value display update
    const sliders = document.querySelectorAll('input[type="range"]');
    sliders.forEach(slider => {
        const updateValue = () => {
            const label = slider.previousElementSibling;
            const valueSpan = label.querySelector('span');
            if (valueSpan) {
                valueSpan.textContent = slider.value;
            }
        };
        
        slider.addEventListener('input', updateValue);
        updateValue(); // Initial call
    });
    
    // File upload interaction
    const uploadArea = document.querySelector('.border-dashed');
    const fileInput = uploadArea.querySelector('input[type="file"]');
    
    uploadArea.addEventListener('click', () => {
        fileInput.click();
    });
    
    fileInput.addEventListener('change', function(e) {
        if (this.files && this.files[0]) {
            const reader = new FileReader();
            
            reader.onload = function(e) {
                uploadArea.innerHTML = `
                    <div class="flex flex-col items-center">
                        <img src="${e.target.result}" alt="Preview" class="max-h-48 rounded-lg">
                        <p class="mt-2 text-sm">${this.files[0].name}</p>
                    </div>
                `;
            }
            
            reader.readAsDataURL(this.files[0]);
        }
    });
    // Handle LoRA selection
    const loraSelector = document.getElementById('loraSelector');
    
    // Generate button interaction
    const generateBtn = document.getElementById('generateBtn');
    const videoPreview = document.getElementById('videoPreview');
    
    generateBtn.addEventListener('click', function() {
        // Validate inputs
        const fileInput = document.querySelector('input[type="file"]');
        const promptTextarea = document.querySelector('textarea[placeholder="Describe the video you want to create..."]');
        
        if (!fileInput.files.length) {
            alert('Please upload an image first.');
            return;
        }
        
        if (!promptTextarea.value.trim()) {
            alert('Please enter a prompt.');
            return;
        }
        
        // Add loading state
        const originalText = this.innerHTML;
        this.innerHTML = `
            <div class="flex items-center justify-center">
                <svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
                    <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle>
                    <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path>
                </svg>
                Generating...
            </div>
        `;
        this.disabled = true;
        
        // Get selected LoRA model
        const selectedLora = loraSelector.selectedValue;
        console.log('Selected LoRA:', selectedLora);
        
        // Optimize prompt based on selected LoRA
        const originalPrompt = promptTextarea.value;
        const optimizedPrompt = optimizePromptForLora(originalPrompt, selectedLora.trigger);
        promptTextarea.value = optimizedPrompt;
        console.log('Optimized prompt:', optimizedPrompt);
        
        // Simulate processing time
        setTimeout(() => {
            // Reset button
            this.innerHTML = originalText;
            this.disabled = false;
            
            // Show result in video preview area
            videoPreview.innerHTML = `
                <video controls class="w-full h-full rounded-lg">
                    <source src="http://static.photos/technology/1200x630/123" type="video/mp4">
                    Your browser does not support the video tag.
                </video>
            `;
        }, 3000);
    });
});

function optimizePromptForLora(basePrompt, loraTrigger) {
    if (!loraTrigger) return basePrompt;
    
    // Base model optimizations
    const baseOptimizations = [
        "high quality, detailed, sharp focus",
        "professional lighting, cinematic composition",
        "8k resolution, ultra detailed",
        "masterpiece, best quality"
    ];
    
    // Motion-specific enhancements
    const motionEnhancements = [
        "smooth camera motion",
        "dynamic movement",
        "fluid animation",
        "cinematic pan"
    ];
    
    // Combine all elements
    const allElements = [...baseOptimizations, ...motionEnhancements];
    
    // Check if base prompt already contains optimization keywords
    const hasQualityKeywords = baseOptimizations.some(keyword => 
        basePrompt.toLowerCase().includes(keyword.split(',')[0].toLowerCase())
    );
    
    const hasMotionKeywords = motionEnhancements.some(keyword => 
        basePrompt.toLowerCase().includes(keyword.split(',')[0].toLowerCase())
    );
    
    // Add missing optimizations
    let optimizedPrompt = basePrompt;
    
    if (!hasQualityKeywords) {
        optimizedPrompt = `${allElements.slice(0, 2).join(', ')}, ${optimizedPrompt}`;
    }
    
    if (!hasMotionKeywords) {
        optimizedPrompt = `${optimizedPrompt}, ${motionEnhancements.slice(0, 2).join(', ')}`;
    }
    
    // Add LoRA trigger word
    if (loraTrigger && !basePrompt.toLowerCase().includes(loraTrigger.toLowerCase())) {
        optimizedPrompt = `${optimizedPrompt}, ${loraTrigger}`;
    }
    
    return optimizedPrompt;
}