gokaygokay commited on
Commit
c558dca
·
1 Parent(s): b1c0860
Files changed (1) hide show
  1. llm_inference_video.py +107 -38
llm_inference_video.py CHANGED
@@ -113,49 +113,118 @@ class VideoLLMInferenceNode:
113
  if not concept:
114
  return "Please enter a concept for the video."
115
 
116
- # Build the prompt
117
- system_message = """You are a professional video prompt generator. Your task is to create detailed, technical, and creative video prompts based on user inputs.
118
- The prompts should be suitable for text-to-video AI models and include specific technical details that match the requested style, camera movement, pacing, and effects.
119
- Focus on creating high-quality, cohesive prompts that could be used to generate impressive AI videos."""
120
-
121
- # Set prompt length guidelines
122
- length_guide = {
123
- "Short": "Create a concise prompt of 2-3 sentences.",
124
- "Medium": "Create a detailed prompt of 4-6 sentences.",
125
- "Long": "Create an extensive prompt with 7-10 sentences covering all details."
126
- }
127
-
128
- # Put together options for the prompt
129
- options = []
130
- if style and style != "None":
131
- options.append(f"Style: {style}")
132
- if camera_style and camera_style != "None":
133
- options.append(f"Camera Movement Style: {camera_style}")
134
- if camera_direction and camera_direction != "None":
135
- options.append(f"Camera Direction: {camera_direction}")
136
- if pacing and pacing != "None":
137
- options.append(f"Pacing Rhythm: {pacing}")
138
- if special_effects and special_effects != "None":
139
- options.append(f"Special Effects: {special_effects}")
140
- if custom_elements:
141
- options.append(f"Custom Elements: {custom_elements}")
142
-
143
- options_text = "\n".join(options)
144
-
145
- user_message = f"""Create a video prompt based on the following concept and specifications:
146
 
147
- CONCEPT: {concept}
 
 
 
 
 
 
 
 
148
 
149
- SPECIFICATIONS:
150
- {options_text}
151
 
152
- {length_guide.get(prompt_length, length_guide["Medium"])}
153
 
154
- The prompt should be detailed and technical, specifically mentioning camera angles, movements, lighting, transitions, and other visual elements that would create an impressive AI-generated video.
155
- """
156
 
157
- # Call the appropriate API based on provider
158
- try:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  if provider == "SambaNova":
160
  if self.sambanova_client:
161
  return self._call_sambanova_client(system_message, user_message, model)
 
113
  if not concept:
114
  return "Please enter a concept for the video."
115
 
116
+ try:
117
+ # Helper function to format optional elements
118
+ def format_element(element, element_type):
119
+ if element == "None" or not element:
120
+ return ""
121
+
122
+ element_prefixes = {
123
+ "camera": "utilizing",
124
+ "direction": "with",
125
+ "pacing": "with",
126
+ "effects": "incorporating"
127
+ }
128
+
129
+ return f" {element_prefixes.get(element_type, '')} {element}"
130
+
131
+ # Format camera movement combination
132
+ camera_movement = ""
133
+ if camera_style != "None" and camera_direction != "None":
134
+ camera_movement = f"{camera_style} {camera_direction}"
135
+ elif camera_style != "None":
136
+ camera_movement = camera_style
137
+ elif camera_direction != "None":
138
+ camera_movement = camera_direction
 
 
 
 
 
 
 
139
 
140
+ # Video prompt templates
141
+ default_style = "simple" # Changed from "cinematic" to "simple" as default
142
+
143
+ prompt_templates = {
144
+ "minimalist": f"""Create an elegantly sparse video description focusing on {concept}.
145
+ {format_element(camera_movement, 'camera')}
146
+ {format_element(pacing, 'pacing')}
147
+ {format_element(special_effects, 'effects')}
148
+ {' with ' + custom_elements if custom_elements else ''}.""",
149
 
150
+ "dynamic": f"""Craft an energetic, fast-paced paragraph showcasing {concept} in constant motion. Utilize bold {camera_style} movements and {pacing} rhythm to create momentum. Layer {special_effects} effects and {custom_elements if custom_elements else 'powerful visual elements'} to maintain high energy throughout.""",
 
151
 
152
+ "simple": f"""Create a straightforward, easy-to-understand paragraph describing a video about {concept}. Use {camera_style} camera work and {pacing} pacing. Keep the visuals clear and uncomplicated, incorporating {special_effects} effects and {custom_elements if custom_elements else 'basic visual elements'} in an accessible way.""",
153
 
154
+ "detailed": f"""Construct a meticulous, technically precise paragraph outlining a video about {concept}. Incorporate specific details about {camera_style} cinematography, {pacing} timing, and {special_effects} effects. Include {custom_elements if custom_elements else 'precise technical elements'} while maintaining clarity and depth.""",
 
155
 
156
+ "descriptive": f"""Write a richly descriptive paragraph for a video exploring {concept}. Paint a vivid picture using sensory details, incorporating {camera_style} movement, {pacing} flow, and {special_effects} effects. Emphasize texture, color, and atmosphere, enhanced by {custom_elements if custom_elements else 'evocative visual elements'}.""",
157
+
158
+ "cinematic": f"""Create a single, detailed paragraph describing a cinematic video that captures {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.""",
159
+
160
+ "documentary": f"""Write a comprehensive paragraph for a documentary-style video exploring {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'}.""",
161
+
162
+ "animation": f"""Compose a vivid paragraph describing a {style} animated video showcasing {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.""",
163
+
164
+ "action": f"""Craft an energetic paragraph describing an action sequence centered on {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.""",
165
+
166
+ "experimental": f"""Create an avant-garde paragraph describing an experimental video exploring {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."""
167
+ }
168
+
169
+ # Get the template with a more neutral default
170
+ selected_style = style.lower()
171
+ if selected_style not in prompt_templates:
172
+ print(f"Warning: Style '{style}' not found, using '{default_style}' template")
173
+ selected_style = default_style
174
+
175
+ base_prompt = prompt_templates[selected_style]
176
+
177
+ # Configure length requirements
178
+ length_config = {
179
+ "Short": {
180
+ "guidance": "Create exactly very short, ONE impactful sentence that captures the essence of the video. Be concise but descriptive.",
181
+ "structure": "Combine all elements into a single, powerful sentence."
182
+ },
183
+ "Medium": {
184
+ "guidance": "Create 2-3 flowing sentences that paint a picture of the video.",
185
+ "structure": "First sentence should set the scene, followed by 1-2 sentences developing the concept."
186
+ },
187
+ "Long": {
188
+ "guidance": "Create 4-5 detailed sentences that thoroughly describe the video.",
189
+ "structure": "Begin with the setting, develop the action/movement, and conclude with impact."
190
+ }
191
+ }
192
+
193
+ config = length_config[prompt_length]
194
+
195
+ system_message = f"""You are a visionary video director and creative storyteller. {config['guidance']}
196
+
197
+ Structure: {config['structure']}
198
+
199
+ Focus on these elements while maintaining the specified sentence count:
200
+ 1. Visual atmosphere and mood
201
+ 2. Camera movement and cinematography
202
+ 3. Narrative flow
203
+ 4. Style and aesthetic choices
204
+ 5. Key moments
205
+ 6. Emotional impact
206
+
207
+ IMPORTANT REQUIREMENTS:
208
+ - Deliver exactly the specified number of sentences
209
+ - Short: ONE sentence
210
+ - Medium: TWO to THREE sentences
211
+ - Long: FOUR to FIVE sentences
212
+ - If camera movements are specified, you MUST incorporate them into the description
213
+ - Keep everything in a single paragraph format
214
+ - Avoid technical specifications or shot lists
215
+ - Avoid talking about 'video' or 'videos'. Do not start with 'The video opens with...' or 'The video starts with...' and do not include 'in this video' or 'focus of this video'. kind of terms"""
216
+
217
+ # Format the user prompt with style guidance and camera movement
218
+ user_message = f"""Style Guide: {selected_style.capitalize()} Style
219
+ {prompt_templates[selected_style]}
220
+
221
+ Camera Movement: {camera_movement if camera_movement else 'No specific camera movement'}
222
+ Core Concept: {concept}
223
+
224
+ Please create a {prompt_length.lower()}-length description incorporating these elements into a cohesive narrative.
225
+ Avoid talking about 'video' or 'videos'. Do not start with 'The video opens with...' or 'The video starts with...' and do not include 'in this video' or 'focus of this video'. kind of terms"""
226
+
227
+ # Call the appropriate API based on provider
228
  if provider == "SambaNova":
229
  if self.sambanova_client:
230
  return self._call_sambanova_client(system_message, user_message, model)