gokaygokay commited on
Commit
6686859
·
verified ·
1 Parent(s): 8559af0

Create llm_inference_video.py

Browse files
Files changed (1) hide show
  1. llm_inference_video.py +125 -0
llm_inference_video.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import random
3
+ from groq import Groq
4
+ from openai import OpenAI
5
+ from gradio_client import Client
6
+
7
+ class VideoLLMInferenceNode:
8
+ def __init__(self):
9
+ self.huggingface_token = os.getenv("HUGGINGFACE_TOKEN")
10
+ self.groq_api_key = os.getenv("GROQ_API_KEY")
11
+ self.sambanova_api_key = os.getenv("SAMBANOVA_API_KEY")
12
+
13
+ self.huggingface_client = OpenAI(
14
+ base_url="https://api-inference.huggingface.co/v1/",
15
+ api_key=self.huggingface_token,
16
+ )
17
+ self.groq_client = Groq(api_key=self.groq_api_key)
18
+ self.sambanova_client = OpenAI(
19
+ api_key=self.sambanova_api_key,
20
+ base_url="https://api.sambanova.ai/v1",
21
+ )
22
+
23
+ def generate_video_prompt(
24
+ self,
25
+ input_concept,
26
+ duration,
27
+ style,
28
+ camera_style,
29
+ pacing,
30
+ special_effects,
31
+ custom_elements,
32
+ provider="Hugging Face",
33
+ model=None
34
+ ):
35
+ try:
36
+ # Video prompt templates
37
+ prompt_templates = {
38
+ "cinematic": f"""Create a detailed cinematic prompt for a {duration}-second video. Include:
39
+ - 3-5 distinct scenes with smooth transitions
40
+ - Camera movements: {camera_style}
41
+ - Lighting design for {style} style
42
+ - Special effects: {special_effects}
43
+ - Color grading and film grain details
44
+ - Pacing: {pacing}
45
+ - Add {custom_elements if custom_elements else 'unique atmospheric elements'}
46
+ Format: Timestamped scene descriptions with shot types and transition notes.""",
47
+
48
+ "documentary": f"""Develop a documentary-style video prompt for {duration} seconds. Include:
49
+ - Interview setup with lighting and background
50
+ - B-roll sequences (3-5 locations)
51
+ - Archival footage integration
52
+ - Text overlay and info-graphics
53
+ - Narration style and tone
54
+ - {camera_style} camera work
55
+ - {pacing} rhythm for topic exploration
56
+ - {special_effects} for historical recreations""",
57
+
58
+ "animation": f"""Create a {style} animation prompt for {duration} seconds. Specify:
59
+ - Animation technique (2D/3D/stop-motion)
60
+ - Key action sequences (3-5)
61
+ - Character design elements
62
+ - Background art style
63
+ - Motion blur and frame rate considerations
64
+ - Camera zooms/pans for {pacing} pacing
65
+ - Special effects: {special_effects}
66
+ - {custom_elements if custom_elements else 'unique stylistic flourishes'}""",
67
+
68
+ "action": f"""Generate intense action sequence prompt ({duration} seconds). Include:
69
+ - 3 escalating action beats
70
+ - Camera angles for {style} impact
71
+ - Stunt choreography details
72
+ - Slow-motion/fast-cut ratios
73
+ - Explosion/sfx elements: {special_effects}
74
+ - Pacing structure: {pacing}
75
+ - {camera_style} camera movements
76
+ - Hero shot composition""",
77
+
78
+ "experimental": f"""Design avant-garde video prompt ({duration} seconds) with:
79
+ - Unconventional narrative structure
80
+ - {style} visual treatments
81
+ - Abstract transitions between {random.randint(5,8)} concepts
82
+ - Experimental sound/image relationships
83
+ - {camera_style} capture techniques
84
+ - {special_effects} digital manipulations
85
+ - Pacing: {pacing} with {custom_elements if custom_elements else 'temporal distortions'}"""
86
+ }
87
+
88
+ base_prompt = prompt_templates.get(style.lower(), prompt_templates["cinematic"])
89
+ system_message = """You are a professional video director and cinematography expert.
90
+ Generate rich, technical video prompts that include:
91
+ 1. Scene-by-scene breakdowns with timestamps
92
+ 2. Camera movements and lens specifications
93
+ 3. Lighting setups and color palettes
94
+ 4. Transition types and durations
95
+ 5. Special effects implementation
96
+ 6. Pacing and rhythm markers
97
+ 7. Technical specifications when relevant"""
98
+
99
+ # Select provider
100
+ if provider == "Hugging Face":
101
+ client = self.huggingface_client
102
+ model = model or "meta-llama/Meta-Llama-3.1-70B-Instruct"
103
+ elif provider == "Groq":
104
+ client = self.groq_client
105
+ model = model or "llama-3.1-70b-versatile"
106
+ elif provider == "SambaNova":
107
+ client = self.sambanova_client
108
+ model = model or "Meta-Llama-3.1-70B-Instruct"
109
+
110
+ response = client.chat.completions.create(
111
+ model=model,
112
+ messages=[
113
+ {"role": "system", "content": system_message},
114
+ {"role": "user", "content": f"{base_prompt}\nCore Concept: {input_concept}"}
115
+ ],
116
+ temperature=1.2,
117
+ max_tokens=1500,
118
+ top_p=0.95,
119
+ seed=random.randint(0, 10000)
120
+ )
121
+
122
+ return response.choices[0].message.content.strip()
123
+
124
+ except Exception as e:
125
+ return f"Error generating video prompt: {str(e)}"