File size: 2,519 Bytes
9451ca9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import google.generativeai as genai
from config.settings import PROCESSING_CONFIG

class PromptGenerator:
    def __init__(self):
        self.model = None
        self.gemini_key = None
    
    def set_api_key(self, key):
        if key and key.strip():
            try:
                genai.configure(api_key=key.strip())
                self.model = genai.GenerativeModel('gemini-1.5-flash')
                self.gemini_key = key.strip()
            except:
                self.model = None
    
    def generate_video_prompt(self, analysis, target_duration):
        if not self.model or not analysis:
            return self._fallback_prompt(analysis)
        
        try:
            context = f"""
Video Analysis:
- Duration: {analysis.get('duration', 0):.1f}s
- Transcript: {analysis.get('transcript', 'No audio')}
- Scene type: {analysis.get('scene_type', 'unknown')}
- Colors: {', '.join(analysis.get('dominant_colors', [])[:3])}

Target: {target_duration}s commercial

Generate a creative prompt for Stable Video Diffusion to extend this commercial.
Keep it under 100 words, focus on visual elements, camera movement, and commercial appeal.
"""
            
            response = self.model.generate_content(context)
            prompt = response.text.strip()
            
            if len(prompt) > 20:
                return prompt
            else:
                return self._fallback_prompt(analysis)
                
        except Exception as e:
            return self._fallback_prompt(analysis)
    
    def _fallback_prompt(self, analysis):
        if not analysis:
            return "professional commercial product showcase, smooth camera movement, high quality, cinematic lighting"
        
        scene_type = analysis.get('scene_type', 'product')
        transcript = analysis.get('transcript', '').lower()
        
        prompts = {
            'lifestyle': "vibrant lifestyle commercial, people enjoying, dynamic movement, warm lighting",
            'tech': "sleek tech commercial, modern interface, clean design, professional lighting", 
            'product': "premium product showcase, elegant presentation, studio lighting"
        }
        
        base_prompt = prompts.get(scene_type, prompts['product'])
        
        if 'outdoor' in transcript:
            base_prompt += ", outdoor setting"
        elif 'indoor' in transcript:
            base_prompt += ", indoor environment"
            
        return base_prompt + ", commercial quality, smooth transitions"