Spaces:
Sleeping
Sleeping
Commit
·
44d5e00
1
Parent(s):
c3b64dd
update: logging and dynamic background color
Browse files- app.py +8 -6
- src/components/each_necklace_video_gen.py +13 -8
app.py
CHANGED
@@ -19,7 +19,7 @@ supabase_key = os.getenv('SUPABASE_KEY')
|
|
19 |
supabase = create_client(supabase_url, supabase_key)
|
20 |
app = FastAPI()
|
21 |
|
22 |
-
RESOURCES_DIR = "
|
23 |
|
24 |
os.makedirs(RESOURCES_DIR, exist_ok=True)
|
25 |
TEMP_VIDEO_DIR = f"{RESOURCES_DIR}/temp_video"
|
@@ -202,12 +202,14 @@ class EachNecklaceVideoGeneratorRequest(BaseModel):
|
|
202 |
necklace_try_on_output_images: List[List[str]]
|
203 |
clothing_output_images: List[List[str]]
|
204 |
makeup_output_images: List[List[str]]
|
|
|
205 |
|
206 |
|
207 |
@app.post("/createcombinedvideo/")
|
208 |
-
async def
|
209 |
logger.info(f"Creating video with request: {request.dict()}")
|
210 |
start_time = time.time()
|
|
|
211 |
try:
|
212 |
logger.info("Downloading images...")
|
213 |
|
@@ -227,8 +229,8 @@ async def create_video(request: EachNecklaceVideoGeneratorRequest):
|
|
227 |
def verify_files(files):
|
228 |
logger.info(f"Verifying files: {files}")
|
229 |
if isinstance(files, list):
|
230 |
-
return all(verify_files(item) for item in files)
|
231 |
-
return files is not None
|
232 |
|
233 |
if not all(verify_files(files) for files in temp_files.values()):
|
234 |
return JSONResponse(
|
@@ -236,7 +238,6 @@ async def create_video(request: EachNecklaceVideoGeneratorRequest):
|
|
236 |
status_code=400
|
237 |
)
|
238 |
|
239 |
-
# Prepare paths
|
240 |
intro_path = f"{RESOURCES_DIR}/intro/{request.intro_video_path}"
|
241 |
output_path = f"{TEMP_VIDEO_DIR}/video_{os.urandom(8).hex()}.mp4"
|
242 |
font_path = f"{RESOURCES_DIR}/fonts/{request.font_path}"
|
@@ -257,7 +258,8 @@ async def create_video(request: EachNecklaceVideoGeneratorRequest):
|
|
257 |
nto_title=request.nto_image_title,
|
258 |
|
259 |
cto_title=request.nto_cto_image_title,
|
260 |
-
makeup_title=request.makeup_image_title
|
|
|
261 |
|
262 |
)
|
263 |
logger.info("Creating video...")
|
|
|
19 |
supabase = create_client(supabase_url, supabase_key)
|
20 |
app = FastAPI()
|
21 |
|
22 |
+
RESOURCES_DIR = "resources"
|
23 |
|
24 |
os.makedirs(RESOURCES_DIR, exist_ok=True)
|
25 |
TEMP_VIDEO_DIR = f"{RESOURCES_DIR}/temp_video"
|
|
|
202 |
necklace_try_on_output_images: List[List[str]]
|
203 |
clothing_output_images: List[List[str]]
|
204 |
makeup_output_images: List[List[str]]
|
205 |
+
background_colors: list[tuple[int, int, int]]
|
206 |
|
207 |
|
208 |
@app.post("/createcombinedvideo/")
|
209 |
+
async def create_combined_video(request: EachNecklaceVideoGeneratorRequest):
|
210 |
logger.info(f"Creating video with request: {request.dict()}")
|
211 |
start_time = time.time()
|
212 |
+
background_ = request.background_colors
|
213 |
try:
|
214 |
logger.info("Downloading images...")
|
215 |
|
|
|
229 |
def verify_files(files):
|
230 |
logger.info(f"Verifying files: {files}")
|
231 |
if isinstance(files, list):
|
232 |
+
return all(verify_files(item) for item in files)
|
233 |
+
return files is not None
|
234 |
|
235 |
if not all(verify_files(files) for files in temp_files.values()):
|
236 |
return JSONResponse(
|
|
|
238 |
status_code=400
|
239 |
)
|
240 |
|
|
|
241 |
intro_path = f"{RESOURCES_DIR}/intro/{request.intro_video_path}"
|
242 |
output_path = f"{TEMP_VIDEO_DIR}/video_{os.urandom(8).hex()}.mp4"
|
243 |
font_path = f"{RESOURCES_DIR}/fonts/{request.font_path}"
|
|
|
258 |
nto_title=request.nto_image_title,
|
259 |
|
260 |
cto_title=request.nto_cto_image_title,
|
261 |
+
makeup_title=request.makeup_image_title,
|
262 |
+
backgrounds=background_
|
263 |
|
264 |
)
|
265 |
logger.info("Creating video...")
|
src/components/each_necklace_video_gen.py
CHANGED
@@ -14,11 +14,12 @@ from moviepy.video.io.VideoFileClip import VideoFileClip
|
|
14 |
|
15 |
|
16 |
class EachVideoCreator:
|
17 |
-
def __init__(self, necklace_title, nto_title, cto_title, makeup_title,
|
|
|
18 |
nto_outputs=None,
|
19 |
nto_cto_outputs=None, makeup_outputs=None, font_path=None, output_path=None,
|
20 |
audio_path=None, image_display_duration=2.5, box_color=(131, 42, 48), box_opacity=0.8,
|
21 |
-
font_size=28, text_color="white", fps=1):
|
22 |
self.intro_video_path = intro_video_path
|
23 |
self.necklace_images = necklace_image if necklace_image else []
|
24 |
self.nto_outputs = nto_outputs if nto_outputs else []
|
@@ -37,19 +38,23 @@ class EachVideoCreator:
|
|
37 |
self.nto_title = nto_title
|
38 |
self.cto_title = cto_title
|
39 |
self.makeup_title = makeup_title
|
|
|
|
|
|
|
40 |
|
41 |
def create_necklace_clips(self, necklace_image, index, label):
|
42 |
if not necklace_image:
|
43 |
print(f"Skipping necklace {index + 1}: No image provided.")
|
44 |
return []
|
45 |
|
46 |
-
backgrounds = [
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
]
|
|
|
51 |
necklace_clips = []
|
52 |
-
for bg_color in backgrounds:
|
53 |
bg_clip = ColorClip((1080, 1080), col=bg_color, duration=self.image_display_duration)
|
54 |
necklace = resize(ImageClip(necklace_image), width=650)
|
55 |
necklace = necklace.set_duration(self.image_display_duration).set_position('center')
|
|
|
14 |
|
15 |
|
16 |
class EachVideoCreator:
|
17 |
+
def __init__(self, necklace_title, backgrounds: list[tuple], nto_title, cto_title, makeup_title,
|
18 |
+
intro_video_path=None, necklace_image=None,
|
19 |
nto_outputs=None,
|
20 |
nto_cto_outputs=None, makeup_outputs=None, font_path=None, output_path=None,
|
21 |
audio_path=None, image_display_duration=2.5, box_color=(131, 42, 48), box_opacity=0.8,
|
22 |
+
font_size=28, text_color="white", fps=1, ):
|
23 |
self.intro_video_path = intro_video_path
|
24 |
self.necklace_images = necklace_image if necklace_image else []
|
25 |
self.nto_outputs = nto_outputs if nto_outputs else []
|
|
|
38 |
self.nto_title = nto_title
|
39 |
self.cto_title = cto_title
|
40 |
self.makeup_title = makeup_title
|
41 |
+
self.backgrounds = backgrounds
|
42 |
+
|
43 |
+
|
44 |
|
45 |
def create_necklace_clips(self, necklace_image, index, label):
|
46 |
if not necklace_image:
|
47 |
print(f"Skipping necklace {index + 1}: No image provided.")
|
48 |
return []
|
49 |
|
50 |
+
# backgrounds = [
|
51 |
+
# (245, 245, 245), # Soft White
|
52 |
+
# (220, 245, 245), # Light Blue
|
53 |
+
# (230, 230, 235) # Pearl Gray
|
54 |
+
# ]
|
55 |
+
|
56 |
necklace_clips = []
|
57 |
+
for bg_color in self.backgrounds:
|
58 |
bg_clip = ColorClip((1080, 1080), col=bg_color, duration=self.image_display_duration)
|
59 |
necklace = resize(ImageClip(necklace_image), width=650)
|
60 |
necklace = necklace.set_duration(self.image_display_duration).set_position('center')
|