Spaces:
Paused
Paused
File size: 7,906 Bytes
6686859 1e26e1c 9499f0c 6686859 098905a 6686859 098905a d6e9a60 4269cb2 6686859 4269cb2 6686859 4269cb2 6686859 4269cb2 6686859 9499f0c 98a22d3 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 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 |
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:
# Helper function to format optional elements
def format_element(element, element_type):
if element == "None" or not element:
return ""
element_prefixes = {
"camera": "utilizing",
"pacing": "with",
"effects": "incorporating"
}
return f" {element_prefixes.get(element_type, '')} {element}"
# Video prompt templates
prompt_templates = {
"minimalist": f"""Create an elegantly sparse video description focusing on {input_concept}.
{format_element(camera_style, 'camera')}
{format_element(pacing, 'pacing')}
{format_element(special_effects, 'effects')}
{' with ' + custom_elements if custom_elements else ''}.""",
"dynamic": f"""Craft an energetic, fast-paced paragraph showcasing {input_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.""",
"simple": f"""Create a straightforward, easy-to-understand paragraph describing a video about {input_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.""",
"detailed": f"""Construct a meticulous, technically precise paragraph outlining a video about {input_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.""",
"descriptive": f"""Write a richly descriptive paragraph for a video exploring {input_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'}.""",
"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 very short, 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)}" |