factorstudios commited on
Commit
7fb3836
·
verified ·
1 Parent(s): b9bb17c

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +24 -24
server.py CHANGED
@@ -172,11 +172,11 @@ async def generate_video(
172
  files: List[UploadFile] = File(...)
173
  ):
174
  """
175
- Full pipeline: Upload candidates + manifest, get MP4 back.
176
 
177
  Form parameters:
178
  - manifest: JSON string with title and scenes
179
- - files: Uploaded image files for each scene
180
 
181
  Returns: MP4 video file
182
  """
@@ -185,41 +185,41 @@ async def generate_video(
185
  manifest_data = json.loads(manifest)
186
  manifest_req = ManifestRequest(**manifest_data)
187
 
188
- # Step 1: Clean and prepare upload directory
189
- upload_dir = BASE_DIR / "upload_candidates"
190
- if upload_dir.exists():
191
- shutil.rmtree(upload_dir)
192
- upload_dir.mkdir(exist_ok=True)
 
 
 
 
193
 
194
- # Step 2: Save uploaded files organized by scene index
195
- uploaded_count = 0
196
- for file in files:
197
  if file.filename:
198
- # Save to upload_candidates folder
199
- file_path = upload_dir / file.filename
200
  with open(file_path, "wb") as f:
201
- f.write(await file.read())
202
- uploaded_count += 1
203
 
204
- if uploaded_count != len(manifest_req.scenes):
 
 
205
  raise Exception(
206
- f"Expected {len(manifest_req.scenes)} files, received {uploaded_count}"
207
  )
208
 
209
- # Step 3: Select scenes (evaluate and copy to selected/)
210
- select_result = await _select_scenes(manifest_req, upload_dir)
211
- if select_result["status"] != "success":
212
- raise Exception(select_result.get("message", "Scene selection failed"))
213
-
214
- # Step 4: Compose video with manifest data
215
  compose_result = await _compose(manifest_req)
216
  if compose_result["status"] != "success":
217
  raise Exception(compose_result.get("message", "Composition failed"))
218
 
219
- # Step 5: Return the MP4 file
220
  output_file = Path(compose_result["output_path"])
221
  if not output_file.exists():
222
- raise Exception("Output file not found")
223
 
224
  return FileResponse(
225
  path=output_file,
 
172
  files: List[UploadFile] = File(...)
173
  ):
174
  """
175
+ Full pipeline: Upload images + manifest, compose MP4 and return it.
176
 
177
  Form parameters:
178
  - manifest: JSON string with title and scenes
179
+ - files: Uploaded image files for each scene (one per scene)
180
 
181
  Returns: MP4 video file
182
  """
 
185
  manifest_data = json.loads(manifest)
186
  manifest_req = ManifestRequest(**manifest_data)
187
 
188
+ if len(files) != len(manifest_req.scenes):
189
+ raise Exception(
190
+ f"Expected {len(manifest_req.scenes)} files, received {len(files)}"
191
+ )
192
+
193
+ # Clean and prepare selected directory
194
+ if SELECTED_DIR.exists():
195
+ shutil.rmtree(SELECTED_DIR)
196
+ SELECTED_DIR.mkdir(exist_ok=True)
197
 
198
+ # Save uploaded files directly to selected/ directory
199
+ for i, file in enumerate(files):
 
200
  if file.filename:
201
+ # Save with standard naming: scene_00.jpg, scene_01.jpg, etc.
202
+ file_path = SELECTED_DIR / f"scene_{i:02d}.jpg"
203
  with open(file_path, "wb") as f:
204
+ content = await file.read()
205
+ f.write(content)
206
 
207
+ # Verify all files were saved
208
+ selected_images = sorted(SELECTED_DIR.glob("scene_*.jpg"))
209
+ if len(selected_images) != len(manifest_req.scenes):
210
  raise Exception(
211
+ f"Failed to save all images. Expected {len(manifest_req.scenes)}, got {len(selected_images)}"
212
  )
213
 
214
+ # Compose video with manifest data
 
 
 
 
 
215
  compose_result = await _compose(manifest_req)
216
  if compose_result["status"] != "success":
217
  raise Exception(compose_result.get("message", "Composition failed"))
218
 
219
+ # Return the MP4 file
220
  output_file = Path(compose_result["output_path"])
221
  if not output_file.exists():
222
+ raise Exception("Output file not created")
223
 
224
  return FileResponse(
225
  path=output_file,