ishworrsubedii commited on
Commit
ca63f09
·
1 Parent(s): c1b007c

add: logic for skipping necklace portion from the video

Browse files
Files changed (2) hide show
  1. app.py +12 -18
  2. src/components/each_necklace_video_gen.py +12 -14
app.py CHANGED
@@ -237,15 +237,15 @@ class EachNecklaceVideoGeneratorRequest(BaseModel):
237
  background_audio_path: str = "TraditionalIndianVlogMusic.mp3"
238
  image_display_duration: float = 2.5
239
  fps: int = 10
240
- necklace_title: List[str]
241
- nto_image_title: List[List[str]]
242
- nto_cto_image_title: List[List[str]]
243
- makeup_image_title: List[List[str]]
244
- necklace_images: List[str]
245
- necklace_try_on_output_images: List[List[str]]
246
- clothing_output_images: List[List[str]]
247
- makeup_output_images: List[List[str]]
248
- background_colors: list[tuple[int, int, int]]
249
  outro_title: str = "Reach out to us for more information"
250
  address: str = "123, ABC Street, XYZ City"
251
  phone_numbers: str = "1234567890"
@@ -254,6 +254,7 @@ class EachNecklaceVideoGeneratorRequest(BaseModel):
254
  transition_type: str = "None"
255
  direction: str = "left"
256
  outro_video_path: str = "JewelMirror_outro.mp4"
 
257
 
258
 
259
  @app.post("/createcombinedvideo/")
@@ -284,12 +285,6 @@ async def create_combined_video(request: EachNecklaceVideoGeneratorRequest):
284
  return all(verify_files(item) for item in files)
285
  return files is not None
286
 
287
- if not all(verify_files(files) for files in temp_files.values()):
288
- return JSONResponse(
289
- content={"status": "error", "message": "Failed to download all required images."},
290
- status_code=400
291
- )
292
-
293
  intro_path = f"{RESOURCES_DIR}/intro/{request.intro_video_path}"
294
  output_path = f"{TEMP_VIDEO_DIR}/video_{os.urandom(8).hex()}.mp4"
295
  font_path = f"{RESOURCES_DIR}/fonts/{request.font_path}"
@@ -297,7 +292,6 @@ async def create_combined_video(request: EachNecklaceVideoGeneratorRequest):
297
  outro_path = f"{RESOURCES_DIR}/outro/{request.outro_video_path}"
298
  try:
299
  model_name = request.necklace_try_on_output_images[0][0].split("/")[-1].split(".")[0].split("-")[1]
300
-
301
  except:
302
  model_name = "MOD"
303
 
@@ -324,7 +318,8 @@ async def create_combined_video(request: EachNecklaceVideoGeneratorRequest):
324
  transition_duration=request.transition_duration,
325
  transition_type=request.transition_type,
326
  direction=request.direction,
327
- outro_video_path=outro_path
 
328
 
329
  )
330
  logger.info("Creating video...")
@@ -364,7 +359,6 @@ async def create_combined_video(request: EachNecklaceVideoGeneratorRequest):
364
  return JSONResponse(content=response, status_code=200)
365
 
366
  except Exception as e:
367
- raise e
368
  return JSONResponse(content={"status": "error", "message": str(e)}, status_code=500)
369
 
370
 
 
237
  background_audio_path: str = "TraditionalIndianVlogMusic.mp3"
238
  image_display_duration: float = 2.5
239
  fps: int = 10
240
+ necklace_title: List[str] = None
241
+ nto_image_title: List[List[str]] = None
242
+ nto_cto_image_title: List[List[str]] = None
243
+ makeup_image_title: List[List[str]] = None
244
+ necklace_images: List[str] = None
245
+ necklace_try_on_output_images: List[List[str]] = None
246
+ clothing_output_images: List[List[str]] = None
247
+ makeup_output_images: List[List[str]] = None
248
+ background_colors: list[tuple[int, int, int]] = None
249
  outro_title: str = "Reach out to us for more information"
250
  address: str = "123, ABC Street, XYZ City"
251
  phone_numbers: str = "1234567890"
 
254
  transition_type: str = "None"
255
  direction: str = "left"
256
  outro_video_path: str = "JewelMirror_outro.mp4"
257
+ skip_necklace_video_portion: bool = False
258
 
259
 
260
  @app.post("/createcombinedvideo/")
 
285
  return all(verify_files(item) for item in files)
286
  return files is not None
287
 
 
 
 
 
 
 
288
  intro_path = f"{RESOURCES_DIR}/intro/{request.intro_video_path}"
289
  output_path = f"{TEMP_VIDEO_DIR}/video_{os.urandom(8).hex()}.mp4"
290
  font_path = f"{RESOURCES_DIR}/fonts/{request.font_path}"
 
292
  outro_path = f"{RESOURCES_DIR}/outro/{request.outro_video_path}"
293
  try:
294
  model_name = request.necklace_try_on_output_images[0][0].split("/")[-1].split(".")[0].split("-")[1]
 
295
  except:
296
  model_name = "MOD"
297
 
 
318
  transition_duration=request.transition_duration,
319
  transition_type=request.transition_type,
320
  direction=request.direction,
321
+ outro_video_path=outro_path,
322
+ skip_necklace_video_portion=request.skip_necklace_video_portion
323
 
324
  )
325
  logger.info("Creating video...")
 
359
  return JSONResponse(content=response, status_code=200)
360
 
361
  except Exception as e:
 
362
  return JSONResponse(content={"status": "error", "message": str(e)}, status_code=500)
363
 
364
 
src/components/each_necklace_video_gen.py CHANGED
@@ -23,7 +23,7 @@ class EachVideoCreator:
23
  audio_path=None, image_display_duration=2.5, box_color=(131, 42, 48), box_opacity=0.8,
24
  font_size=28, text_color="white", fps=1, outro_title=None, logo_image=None, address=None,
25
  phone_numbers=None, transition_duration=0.5, transition_type='None', direction='left',
26
- outro_video_path: str = ""):
27
  self.intro_video_path = intro_video_path
28
  self.necklace_images = necklace_image if necklace_image else []
29
  self.nto_outputs = nto_outputs if nto_outputs else []
@@ -51,6 +51,7 @@ class EachVideoCreator:
51
  self.transition_type = transition_type
52
  self.direction = direction
53
  self.outro_video_path = outro_video_path
 
54
 
55
  def create_necklace_clips(self, necklace_image, index, label):
56
  if not necklace_image:
@@ -156,14 +157,18 @@ class EachVideoCreator:
156
  print("Skipping intro video: Path not provided or invalid.")
157
 
158
  # Step 2: Process Necklaces and Associated Outputs
 
159
  for idx, necklace_image in enumerate(self.necklace_images):
160
- print(f"Processing Necklace {idx + 1}...")
161
- # Necklace preview clips
162
- necklace_clips = self.create_necklace_clips(necklace_image, idx, self.necklace_title[idx])
163
- if necklace_clips:
164
- clips.extend(necklace_clips)
165
  else:
166
- print(f"Skipping Necklace {idx + 1} preview: No valid clips created.")
 
 
 
 
 
 
167
 
168
  # NTO outputs
169
  if idx < len(self.nto_outputs):
@@ -202,13 +207,6 @@ class EachVideoCreator:
202
  outro_clip = resize(VideoFileClip(self.outro_video_path), (1080, 1080))
203
  clips.append(outro_clip)
204
 
205
- # if self.logo_image or self.address or self.phone_numbers is not None:
206
- # outro_clip = self.create_last_clip(title=self.outro_title, logo_image=self.logo_image,
207
- # address=self.address,
208
- # phone_numbers=self.phone_numbers,
209
- # font_path=self.font_path)
210
- # clips.extend([outro_clip])
211
-
212
  final_clips = []
213
  for clip in clips:
214
  clip = clip.set_duration(self.image_display_duration)
 
23
  audio_path=None, image_display_duration=2.5, box_color=(131, 42, 48), box_opacity=0.8,
24
  font_size=28, text_color="white", fps=1, outro_title=None, logo_image=None, address=None,
25
  phone_numbers=None, transition_duration=0.5, transition_type='None', direction='left',
26
+ outro_video_path: str = "", skip_necklace_video_portion=False):
27
  self.intro_video_path = intro_video_path
28
  self.necklace_images = necklace_image if necklace_image else []
29
  self.nto_outputs = nto_outputs if nto_outputs else []
 
51
  self.transition_type = transition_type
52
  self.direction = direction
53
  self.outro_video_path = outro_video_path
54
+ self.skip_necklace_video_portion = skip_necklace_video_portion
55
 
56
  def create_necklace_clips(self, necklace_image, index, label):
57
  if not necklace_image:
 
157
  print("Skipping intro video: Path not provided or invalid.")
158
 
159
  # Step 2: Process Necklaces and Associated Outputs
160
+
161
  for idx, necklace_image in enumerate(self.necklace_images):
162
+ if self.skip_necklace_video_portion:
163
+ pass
 
 
 
164
  else:
165
+ print(f"Processing Necklace {idx + 1}...")
166
+ # Necklace preview clips
167
+ necklace_clips = self.create_necklace_clips(necklace_image, idx, self.necklace_title[idx])
168
+ if necklace_clips:
169
+ clips.extend(necklace_clips)
170
+ else:
171
+ print(f"Skipping Necklace {idx + 1} preview: No valid clips created.")
172
 
173
  # NTO outputs
174
  if idx < len(self.nto_outputs):
 
207
  outro_clip = resize(VideoFileClip(self.outro_video_path), (1080, 1080))
208
  clips.append(outro_clip)
209
 
 
 
 
 
 
 
 
210
  final_clips = []
211
  for clip in clips:
212
  clip = clip.set_duration(self.image_display_duration)