Spaces:
Sleeping
Sleeping
priompt
Browse files- prompt/animation.md +1 -0
- services/gemini_job_worker.py +35 -1
prompt/animation.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Analyze this image and create a concise prompt for a video generation model to create a cinematic, loopable animation. Identify the most interesting moving element (e.g., flowing water, swaying trees, flickering light, clouds) and describe the motion. Output ONLY the description, under 30 words.
|
services/gemini_job_worker.py
CHANGED
|
@@ -150,10 +150,44 @@ class GeminiJobProcessor(JobProcessor[GeminiJob]):
|
|
| 150 |
|
| 151 |
async def _start_video(self, job: GeminiJob, session: AsyncSession, service: GeminiService, input_data: dict) -> GeminiJob:
|
| 152 |
"""Start async video generation."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
result = await service.start_video_generation(
|
| 154 |
base64_image=input_data.get("base64_image", ""),
|
| 155 |
mime_type=input_data.get("mime_type", "image/jpeg"),
|
| 156 |
-
prompt=
|
| 157 |
aspect_ratio=input_data.get("aspect_ratio", "16:9"),
|
| 158 |
resolution=input_data.get("resolution", "720p"),
|
| 159 |
number_of_videos=input_data.get("number_of_videos", 1)
|
|
|
|
| 150 |
|
| 151 |
async def _start_video(self, job: GeminiJob, session: AsyncSession, service: GeminiService, input_data: dict) -> GeminiJob:
|
| 152 |
"""Start async video generation."""
|
| 153 |
+
prompt = input_data.get("prompt", "")
|
| 154 |
+
|
| 155 |
+
# If prompt is missing, generate one using the animation template
|
| 156 |
+
if not prompt:
|
| 157 |
+
try:
|
| 158 |
+
import os
|
| 159 |
+
template_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "prompt", "animation.md")
|
| 160 |
+
if os.path.exists(template_path):
|
| 161 |
+
with open(template_path, "r") as f:
|
| 162 |
+
template_prompt = f.read().strip()
|
| 163 |
+
|
| 164 |
+
logger.info(f"Generating auto-prompt for job {job.job_id} using template")
|
| 165 |
+
prompt = await service.generate_animation_prompt(
|
| 166 |
+
base64_image=input_data.get("base64_image", ""),
|
| 167 |
+
mime_type=input_data.get("mime_type", "image/jpeg"),
|
| 168 |
+
custom_prompt=template_prompt
|
| 169 |
+
)
|
| 170 |
+
logger.info(f"Generated prompt for job {job.job_id}: {prompt}")
|
| 171 |
+
|
| 172 |
+
# Update input data with generated prompt for reference
|
| 173 |
+
input_data["prompt"] = prompt
|
| 174 |
+
job.input_data = input_data
|
| 175 |
+
# We need to commit this change to DB so it persists
|
| 176 |
+
# But session commit happens outside this method usually?
|
| 177 |
+
# Actually process() calls this, and process() returns job,
|
| 178 |
+
# but doesn't explicitly commit job changes until later?
|
| 179 |
+
# The worker loop commits after process() returns.
|
| 180 |
+
else:
|
| 181 |
+
logger.warning(f"Animation prompt template not found at {template_path}")
|
| 182 |
+
except Exception as e:
|
| 183 |
+
logger.error(f"Failed to generate auto-prompt: {e}")
|
| 184 |
+
# Fallback to empty prompt or error?
|
| 185 |
+
# Let's let it proceed with empty prompt which might fail at API level or use API default
|
| 186 |
+
|
| 187 |
result = await service.start_video_generation(
|
| 188 |
base64_image=input_data.get("base64_image", ""),
|
| 189 |
mime_type=input_data.get("mime_type", "image/jpeg"),
|
| 190 |
+
prompt=prompt,
|
| 191 |
aspect_ratio=input_data.get("aspect_ratio", "16:9"),
|
| 192 |
resolution=input_data.get("resolution", "720p"),
|
| 193 |
number_of_videos=input_data.get("number_of_videos", 1)
|