Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
2022eac
1
Parent(s):
dfc83f9
add init
Browse files- llm_inference_video.py +29 -1
llm_inference_video.py
CHANGED
@@ -90,7 +90,9 @@ class VideoLLMInferenceNode:
|
|
90 |
custom_elements: str = "",
|
91 |
provider: str = "SambaNova",
|
92 |
model: str = "Meta-Llama-3.1-70B-Instruct",
|
93 |
-
prompt_length: str = "Medium"
|
|
|
|
|
94 |
) -> str:
|
95 |
"""
|
96 |
Generate a video prompt using the specified LLM provider
|
@@ -106,6 +108,8 @@ class VideoLLMInferenceNode:
|
|
106 |
provider: LLM provider (SambaNova or Groq)
|
107 |
model: Model name
|
108 |
prompt_length: Desired prompt length
|
|
|
|
|
109 |
|
110 |
Returns:
|
111 |
str: Generated video prompt
|
@@ -114,6 +118,24 @@ class VideoLLMInferenceNode:
|
|
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:
|
@@ -203,6 +225,9 @@ Focus on these elements while maintaining the specified sentence count:
|
|
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
|
@@ -220,8 +245,11 @@ IMPORTANT REQUIREMENTS:
|
|
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. Do not say "Here is your video prompt" or "Here is your video description" or anything like that. Just give the prompt."""
|
226 |
|
227 |
# Call the appropriate API based on provider
|
|
|
90 |
custom_elements: str = "",
|
91 |
provider: str = "SambaNova",
|
92 |
model: str = "Meta-Llama-3.1-70B-Instruct",
|
93 |
+
prompt_length: str = "Medium",
|
94 |
+
image_path: str = "",
|
95 |
+
video_path: str = ""
|
96 |
) -> str:
|
97 |
"""
|
98 |
Generate a video prompt using the specified LLM provider
|
|
|
108 |
provider: LLM provider (SambaNova or Groq)
|
109 |
model: Model name
|
110 |
prompt_length: Desired prompt length
|
111 |
+
image_path: Optional path to an image for VLM description
|
112 |
+
video_path: Optional path to a video for VLM description
|
113 |
|
114 |
Returns:
|
115 |
str: Generated video prompt
|
|
|
118 |
return "Please enter a concept for the video."
|
119 |
|
120 |
try:
|
121 |
+
# Get VLM descriptions if image or video paths are provided
|
122 |
+
image_description = ""
|
123 |
+
video_description = ""
|
124 |
+
|
125 |
+
if image_path:
|
126 |
+
try:
|
127 |
+
image_description = self.analyze_image(image_path, "Describe this image in detail for a video creator.")
|
128 |
+
print(f"Generated image description: {image_description}")
|
129 |
+
except Exception as e:
|
130 |
+
print(f"Error generating image description: {str(e)}")
|
131 |
+
|
132 |
+
if video_path:
|
133 |
+
try:
|
134 |
+
video_description = self.analyze_video(video_path)
|
135 |
+
print(f"Generated video description: {video_description}")
|
136 |
+
except Exception as e:
|
137 |
+
print(f"Error generating video description: {str(e)}")
|
138 |
+
|
139 |
# Helper function to format optional elements
|
140 |
def format_element(element, element_type):
|
141 |
if element == "None" or not element:
|
|
|
225 |
4. Style and aesthetic choices
|
226 |
5. Key moments
|
227 |
6. Emotional impact
|
228 |
+
{'' if not image_description and not video_description else '7. Elements from the provided image/video descriptions'}
|
229 |
+
|
230 |
+
{'' if not image_description and not video_description else 'If image or video descriptions are provided, incorporate their key visual elements and content into your description to ensure accuracy and relevance.'}
|
231 |
|
232 |
IMPORTANT REQUIREMENTS:
|
233 |
- Deliver exactly the specified number of sentences
|
|
|
245 |
|
246 |
Camera Movement: {camera_movement if camera_movement else 'No specific camera movement'}
|
247 |
Core Concept: {concept}
|
248 |
+
{f'Reference Image Description: {image_description}' if image_description else ''}
|
249 |
+
{f'Reference Video Description: {video_description}' if video_description else ''}
|
250 |
|
251 |
Please create a {prompt_length.lower()}-length description incorporating these elements into a cohesive narrative.
|
252 |
+
{'' if not image_description and not video_description else 'Use the provided image/video descriptions as reference to inform your prompt creation.'}
|
253 |
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. Do not say "Here is your video prompt" or "Here is your video description" or anything like that. Just give the prompt."""
|
254 |
|
255 |
# Call the appropriate API based on provider
|