File size: 5,598 Bytes
6686859
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e26e1c
9499f0c
 
6686859
 
 
 
4269cb2
 
 
6686859
4269cb2
6686859
4269cb2
6686859
 
4269cb2
6686859
 
 
9499f0c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6686859
 
1e26e1c
6686859
dd8afa8
1e26e1c
6686859
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import random
from groq import Groq
from openai import OpenAI
from gradio_client import Client

class VideoLLMInferenceNode:
    def __init__(self):
        self.groq_api_key = os.getenv("GROQ_API_KEY")
        self.sambanova_api_key = os.getenv("SAMBANOVA_API_KEY")
        
        self.groq_client = Groq(api_key=self.groq_api_key)
        self.sambanova_client = OpenAI(
            api_key=self.sambanova_api_key,
            base_url="https://api.sambanova.ai/v1",
        )

    def generate_video_prompt(
        self,
        input_concept,
        style,
        camera_style,
        pacing,
        special_effects,
        custom_elements,
        provider="SambaNova",
        model=None,
        prompt_length="Medium"
    ):
        try:
            # Video prompt templates
            prompt_templates = {
                "cinematic": f"""Create a single, detailed paragraph describing a cinematic video that captures {input_concept}. Focus on creating a cohesive narrative that incorporates {style} visual aesthetics, {camera_style} camera work, {pacing} pacing, and {special_effects} effects. Include atmospheric elements like {custom_elements if custom_elements else 'mood lighting and environmental details'} to enhance the storytelling. Describe the visual journey without technical timestamps or shot lists.""",

                "documentary": f"""Write a comprehensive paragraph for a  documentary-style video exploring {input_concept}. Blend observational footage with {camera_style} cinematography, incorporating {pacing} editorial rhythm and {special_effects} visual treatments. Focus on creating an immersive narrative that educates and engages, enhanced by {custom_elements if custom_elements else 'authentic moments and natural lighting'}.""",

                "animation": f"""Compose a vivid paragraph describing a {style} animated video showcasing {input_concept}. Detail the unique visual style, character movements, and world-building elements, incorporating {camera_style} perspectives and {pacing} story flow. Include {special_effects} animation effects and {custom_elements if custom_elements else 'signature artistic elements'} to create a memorable visual experience.""",

                "action": f"""Craft an energetic paragraph describing an action sequence centered on {input_concept}. Emphasize the dynamic flow of action using {camera_style} cinematography, {pacing} rhythm, and {special_effects} visual effects. Incorporate {style} stylistic choices and {custom_elements if custom_elements else 'impactful moments'} to create an adrenaline-pumping experience.""",


                "experimental": f"""Create an avant-garde paragraph describing an experimental video exploring {input_concept}. Embrace unconventional storytelling through {style} aesthetics, {camera_style} techniques, and {pacing} temporal flow. Incorporate {special_effects} digital manipulations and {custom_elements if custom_elements else 'abstract visual metaphors'} to challenge traditional narrative structures."""
            }

            base_prompt = prompt_templates.get(style.lower(), prompt_templates["cinematic"])

            # Configure length requirements
            length_config = {
                "Short": {
                    "guidance": "Create exactly ONE impactful sentence that captures the essence of the video. Be concise but descriptive.",
                    "structure": "Combine all elements into a single, powerful sentence."
                },
                "Medium": {
                    "guidance": "Create 2-3 flowing sentences that paint a picture of the video.",
                    "structure": "First sentence should set the scene, followed by 1-2 sentences developing the concept."
                },
                "Long": {
                    "guidance": "Create 4-5 detailed sentences that thoroughly describe the video.",
                    "structure": "Begin with the setting, develop the action/movement, and conclude with impact."
                }
            }
            
            config = length_config[prompt_length]
            
            system_message = f"""You are a visionary video director and creative storyteller. {config['guidance']}

Structure: {config['structure']}

Focus on these elements while maintaining the specified sentence count:
1. Visual atmosphere and mood
2. Narrative flow
3. Style and aesthetic choices
4. Key moments
5. Emotional impact

Important: Deliver exactly the specified number of sentences:
- Short: ONE sentence
- Medium: TWO to THREE sentences
- Long: FOUR to FIVE sentences

Keep everything in a single paragraph format. Avoid technical specifications or shot lists."""

            # Select provider
            if provider == "Groq":
                client = self.groq_client
                model = model or "llama-3.3-70b-versatile"
            else:  # SambaNova as default
                client = self.sambanova_client
                model = model or "Meta-Llama-3.1-70B-Instruct"

            response = client.chat.completions.create(
                model=model,
                messages=[
                    {"role": "system", "content": system_message},
                    {"role": "user", "content": f"{base_prompt}\nCore Concept: {input_concept}"}
                ],
                temperature=1.2,
                top_p=0.95,
                seed=random.randint(0, 10000)
            )

            return response.choices[0].message.content.strip()

        except Exception as e:
            return f"Error generating video prompt: {str(e)}"