Chroma-Extra / llm_inference_video.py
gokaygokay's picture
fix models
1e26e1c
raw
history blame
4.61 kB
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
):
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"])
system_message = """You are a visionary video director and creative storyteller. Create a single, richly detailed paragraph that paints a complete picture of the video concept. Focus on:
1. Overall visual atmosphere and mood
2. Narrative flow and story progression
3. Distinctive visual style and aesthetic choices
4. Key moments and visual highlights
5. Emotional impact and audience experience
Avoid technical specifications or shot-by-shot breakdowns. Instead, create a flowing, descriptive narrative that captures the essence of the video."""
# 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,
max_tokens=1500,
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)}"