fomext commited on
Commit
fec4e43
·
verified ·
1 Parent(s): 8930151

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -16
app.py CHANGED
@@ -87,32 +87,46 @@ async def smart_crop(
87
  "aspect": aspect
88
  }
89
 
90
-
91
  @app.post("/edit")
92
  async def edit_video(
93
  file: UploadFile = File(...),
94
- prompt: str = Form(...)
95
  ):
96
- path = os.path.join(UPLOAD_DIR, file.filename)
97
- with open(path, "wb") as f:
 
 
 
 
98
  f.write(await file.read())
99
 
100
- # Extract first frame
101
- subprocess.run([
102
- "ffmpeg", "-i", path, "-frames:v", "1",
103
- "frame.png"
104
- ])
 
 
 
 
 
 
 
105
 
106
  from PIL import Image
107
- img = Image.open("frame.png").resize((512, 512))
 
 
 
 
 
 
 
 
108
 
109
- frames = svd(
110
- image=img,
111
- prompt=prompt,
112
- num_frames=16
113
- ).frames
114
 
115
  return {
116
- "prompt": prompt,
117
  "frames_generated": len(frames)
118
  }
 
87
  "aspect": aspect
88
  }
89
 
 
90
  @app.post("/edit")
91
  async def edit_video(
92
  file: UploadFile = File(...),
93
+ prompt: str = Form(...) # keep prompt for future use
94
  ):
95
+ uid = uuid.uuid4().hex
96
+ video_path = os.path.join(UPLOAD_DIR, f"{uid}.mp4")
97
+ frame_path = os.path.join(OUTPUT_DIR, f"{uid}.png")
98
+
99
+ # Save video
100
+ with open(video_path, "wb") as f:
101
  f.write(await file.read())
102
 
103
+ # Extract first frame safely
104
+ subprocess.run(
105
+ [
106
+ "ffmpeg",
107
+ "-y",
108
+ "-i", video_path,
109
+ "-vf", "scale=512:512:force_original_aspect_ratio=decrease",
110
+ "-frames:v", "1",
111
+ frame_path
112
+ ],
113
+ check=True
114
+ )
115
 
116
  from PIL import Image
117
+ img = Image.open(frame_path).convert("RGB")
118
+
119
+ # IMPORTANT: SVD does NOT take prompt
120
+ with torch.no_grad():
121
+ output = svd(
122
+ image=img,
123
+ num_frames=16,
124
+ decode_chunk_size=8
125
+ )
126
 
127
+ frames = output.frames
 
 
 
 
128
 
129
  return {
130
+ "prompt_received_but_unused": prompt,
131
  "frames_generated": len(frames)
132
  }