|
4 | 4 | import requests
|
5 | 5 | import json
|
6 | 6 | from daras_ai_v2.exceptions import UserError
|
7 |
| -from daras_ai_v2.gpu_server import call_celery_task_outfile |
8 | 7 | from daras_ai_v2.pydantic_validation import OptionalHttpUrlStr
|
9 | 8 |
|
10 | 9 |
|
@@ -100,169 +99,10 @@ def generate_video(
|
100 | 99 | seed=seed,
|
101 | 100 | )
|
102 | 101 | )
|
103 |
| - case VideoGenerationModels.openai_sora: |
104 |
| - return _generate_sora_video( |
105 |
| - prompt=prompt, |
106 |
| - duration=duration, |
107 |
| - reference_image=reference_image, |
108 |
| - aspect_ratio=aspect_ratio, |
109 |
| - resolution=resolution, |
110 |
| - frames_per_second=frames_per_second, |
111 |
| - seed=seed, |
112 |
| - ) |
113 |
| - case VideoGenerationModels.google_veo_3: |
114 |
| - return _generate_veo3_video( |
115 |
| - prompt=prompt, |
116 |
| - duration=duration, |
117 |
| - reference_image=reference_image, |
118 |
| - aspect_ratio=aspect_ratio, |
119 |
| - resolution=resolution, |
120 |
| - frames_per_second=frames_per_second, |
121 |
| - seed=seed, |
122 |
| - ) |
123 |
| - case VideoGenerationModels.runway_gen_3: |
124 |
| - return _generate_runway_video( |
125 |
| - prompt=prompt, |
126 |
| - duration=duration, |
127 |
| - reference_image=reference_image, |
128 |
| - aspect_ratio=aspect_ratio, |
129 |
| - resolution=resolution, |
130 |
| - frames_per_second=frames_per_second, |
131 |
| - seed=seed, |
132 |
| - ) |
133 |
| - case VideoGenerationModels.pika_labs: |
134 |
| - return _generate_pika_video( |
135 |
| - prompt=prompt, |
136 |
| - duration=duration, |
137 |
| - reference_image=reference_image, |
138 |
| - aspect_ratio=aspect_ratio, |
139 |
| - resolution=resolution, |
140 |
| - frames_per_second=frames_per_second, |
141 |
| - negative_prompt=negative_prompt, |
142 |
| - seed=seed, |
143 |
| - ) |
144 | 102 | case _:
|
145 | 103 | raise UserError(f"Unsupported video generation model: {model}")
|
146 | 104 |
|
147 | 105 |
|
148 |
| -def _generate_sora_video( |
149 |
| - prompt: str, |
150 |
| - duration: int, |
151 |
| - reference_image: str = None, |
152 |
| - aspect_ratio: str = "16:9", |
153 |
| - resolution: str = "1080p", |
154 |
| - frames_per_second: int = 30, |
155 |
| - seed: int = None, |
156 |
| -) -> OptionalHttpUrlStr: |
157 |
| - """Generate video using OpenAI Sora""" |
158 |
| - return call_celery_task_outfile( |
159 |
| - "sora_video_generation", |
160 |
| - pipeline=dict( |
161 |
| - model_id=video_model_ids[VideoGenerationModels.openai_sora], |
162 |
| - resolution=resolution, |
163 |
| - frames_per_second=frames_per_second, |
164 |
| - ), |
165 |
| - inputs=dict( |
166 |
| - prompt=prompt, |
167 |
| - duration=duration, |
168 |
| - reference_image=reference_image, |
169 |
| - aspect_ratio=aspect_ratio, |
170 |
| - seed=seed, |
171 |
| - ), |
172 |
| - content_type="video/mp4", |
173 |
| - filename=f"sora_video_{prompt[:50]}.mp4", |
174 |
| - )[0] |
175 |
| - |
176 |
| - |
177 |
| -def _generate_veo3_video( |
178 |
| - prompt: str, |
179 |
| - duration: int, |
180 |
| - reference_image: str = None, |
181 |
| - aspect_ratio: str = "16:9", |
182 |
| - resolution: str = "1080p", |
183 |
| - frames_per_second: int = 30, |
184 |
| - seed: int = None, |
185 |
| -) -> OptionalHttpUrlStr: |
186 |
| - """Generate video using Google Veo 3""" |
187 |
| - return call_celery_task_outfile( |
188 |
| - "veo3_video_generation", |
189 |
| - pipeline=dict( |
190 |
| - model_id=video_model_ids[VideoGenerationModels.google_veo_3], |
191 |
| - resolution=resolution, |
192 |
| - frames_per_second=frames_per_second, |
193 |
| - ), |
194 |
| - inputs=dict( |
195 |
| - prompt=prompt, |
196 |
| - duration=duration, |
197 |
| - reference_image=reference_image, |
198 |
| - aspect_ratio=aspect_ratio, |
199 |
| - seed=seed, |
200 |
| - ), |
201 |
| - content_type="video/mp4", |
202 |
| - filename=f"veo3_video_{prompt[:50]}.mp4", |
203 |
| - )[0] |
204 |
| - |
205 |
| - |
206 |
| -def _generate_runway_video( |
207 |
| - prompt: str, |
208 |
| - duration: int, |
209 |
| - reference_image: str = None, |
210 |
| - aspect_ratio: str = "16:9", |
211 |
| - resolution: str = "1080p", |
212 |
| - frames_per_second: int = 30, |
213 |
| - seed: int = None, |
214 |
| -) -> OptionalHttpUrlStr: |
215 |
| - """Generate video using Runway Gen-3""" |
216 |
| - return call_celery_task_outfile( |
217 |
| - "runway_video_generation", |
218 |
| - pipeline=dict( |
219 |
| - model_id=video_model_ids[VideoGenerationModels.runway_gen_3], |
220 |
| - resolution=resolution, |
221 |
| - frames_per_second=frames_per_second, |
222 |
| - ), |
223 |
| - inputs=dict( |
224 |
| - prompt=prompt, |
225 |
| - duration=duration, |
226 |
| - reference_image=reference_image, |
227 |
| - aspect_ratio=aspect_ratio, |
228 |
| - seed=seed, |
229 |
| - ), |
230 |
| - content_type="video/mp4", |
231 |
| - filename=f"runway_video_{prompt[:50]}.mp4", |
232 |
| - )[0] |
233 |
| - |
234 |
| - |
235 |
| -def _generate_pika_video( |
236 |
| - prompt: str, |
237 |
| - duration: int, |
238 |
| - reference_image: str = None, |
239 |
| - aspect_ratio: str = "16:9", |
240 |
| - resolution: str = "1080p", |
241 |
| - frames_per_second: int = 30, |
242 |
| - negative_prompt: str = None, |
243 |
| - seed: int = None, |
244 |
| -) -> OptionalHttpUrlStr: |
245 |
| - """Generate video using Pika Labs""" |
246 |
| - return call_celery_task_outfile( |
247 |
| - "pika_video_generation", |
248 |
| - pipeline=dict( |
249 |
| - model_id=video_model_ids[VideoGenerationModels.pika_labs], |
250 |
| - resolution=resolution, |
251 |
| - frames_per_second=frames_per_second, |
252 |
| - ), |
253 |
| - inputs=dict( |
254 |
| - prompt=prompt, |
255 |
| - duration=duration, |
256 |
| - reference_image=reference_image, |
257 |
| - aspect_ratio=aspect_ratio, |
258 |
| - negative_prompt=negative_prompt, |
259 |
| - seed=seed, |
260 |
| - ), |
261 |
| - content_type="video/mp4", |
262 |
| - filename=f"pika_video_{prompt[:50]}.mp4", |
263 |
| - )[0] |
264 |
| - |
265 |
| - |
266 | 106 | def _generate_fal_wan_video(
|
267 | 107 | prompt: str,
|
268 | 108 | duration: int,
|
|
0 commit comments