Spaces:
Sleeping
Sleeping
Commit
·
a11a289
1
Parent(s):
36f6588
fix: add model name as suffix for video gen output
Browse files
app.py
CHANGED
@@ -13,7 +13,6 @@ from supabase import create_client
|
|
13 |
|
14 |
from src.components.each_necklace_video_gen import EachVideoCreator
|
15 |
from src.components.product_page_nto_cto_gen import ProductPageImageGeneration
|
16 |
-
from src.components.vidgen import VideoCreator
|
17 |
from src.utils.logs import logger
|
18 |
|
19 |
supabase_url = os.getenv('SUPABASE_URL')
|
@@ -36,11 +35,10 @@ RESOURCES_DIR = "/app/resources"
|
|
36 |
|
37 |
os.makedirs(RESOURCES_DIR, exist_ok=True)
|
38 |
TEMP_VIDEO_DIR = f"{RESOURCES_DIR}/temp_video"
|
39 |
-
|
40 |
os.environ['MOVIEPY_TEMP_DIR'] = '/tmp/moviepy'
|
41 |
|
42 |
|
43 |
-
def upload_to_supabase(video_path, bucket_name="JewelmirrorVideoGeneration"):
|
44 |
logger.info(f"Uploading video to Supabase: {video_path}")
|
45 |
|
46 |
try:
|
@@ -48,7 +46,7 @@ def upload_to_supabase(video_path, bucket_name="JewelmirrorVideoGeneration"):
|
|
48 |
raise FileNotFoundError(f"Video file not found: {video_path}")
|
49 |
|
50 |
content_type = mimetypes.guess_type(video_path)[0] or 'video/mp4'
|
51 |
-
file_name = os.path.basename(video_path)
|
52 |
|
53 |
options = {
|
54 |
"content-type": content_type,
|
@@ -101,104 +99,105 @@ def download_image(url):
|
|
101 |
return None
|
102 |
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
|
|
202 |
|
203 |
|
204 |
class EachNecklaceVideoGeneratorRequest(BaseModel):
|
@@ -265,6 +264,7 @@ async def create_combined_video(request: EachNecklaceVideoGeneratorRequest):
|
|
265 |
font_path = f"{RESOURCES_DIR}/fonts/{request.font_path}"
|
266 |
audio_path = f"{RESOURCES_DIR}/audio/{request.background_audio_path}"
|
267 |
outro_path = f"{RESOURCES_DIR}/outro/{request.outro_video_path}"
|
|
|
268 |
|
269 |
video_creator = EachVideoCreator(
|
270 |
intro_video_path=intro_path,
|
@@ -298,7 +298,7 @@ async def create_combined_video(request: EachNecklaceVideoGeneratorRequest):
|
|
298 |
video_creation_time = time.time() - start_time - file_download_time
|
299 |
logger.info("Video created successfully.")
|
300 |
|
301 |
-
url = upload_to_supabase(video_path=output_path)
|
302 |
supabase_upload_time = time.time() - start_time - file_download_time - video_creation_time
|
303 |
logger.info(f"Video uploaded to Supabase: {url}")
|
304 |
|
|
|
13 |
|
14 |
from src.components.each_necklace_video_gen import EachVideoCreator
|
15 |
from src.components.product_page_nto_cto_gen import ProductPageImageGeneration
|
|
|
16 |
from src.utils.logs import logger
|
17 |
|
18 |
supabase_url = os.getenv('SUPABASE_URL')
|
|
|
35 |
|
36 |
os.makedirs(RESOURCES_DIR, exist_ok=True)
|
37 |
TEMP_VIDEO_DIR = f"{RESOURCES_DIR}/temp_video"
|
|
|
38 |
os.environ['MOVIEPY_TEMP_DIR'] = '/tmp/moviepy'
|
39 |
|
40 |
|
41 |
+
def upload_to_supabase(video_path, bucket_name="JewelmirrorVideoGeneration", model_name="MOD"):
|
42 |
logger.info(f"Uploading video to Supabase: {video_path}")
|
43 |
|
44 |
try:
|
|
|
46 |
raise FileNotFoundError(f"Video file not found: {video_path}")
|
47 |
|
48 |
content_type = mimetypes.guess_type(video_path)[0] or 'video/mp4'
|
49 |
+
file_name = f"{os.path.basename(video_path)}-{model_name}"
|
50 |
|
51 |
options = {
|
52 |
"content-type": content_type,
|
|
|
99 |
return None
|
100 |
|
101 |
|
102 |
+
#
|
103 |
+
# class VideoGenerator(BaseModel):
|
104 |
+
# necklace_image: str
|
105 |
+
# necklace_try_on_output_images: list[str]
|
106 |
+
# clothing_output_images: list[str]
|
107 |
+
# makeup_output_images: list[str]
|
108 |
+
# intro_video_path: str = "JewelMirror_intro.mp4"
|
109 |
+
# background_audio_path: str = "TraditionalIndianVlogMusic.mp3"
|
110 |
+
# font_path: str = "PlayfairDisplay-VariableFont.ttf"
|
111 |
+
# image_display_duration: float = 2.5
|
112 |
+
# fps: int = 30
|
113 |
+
# necklace_title: str = "Necklace Try-On"
|
114 |
+
# clothing_title: str = "Clothing Try-On"
|
115 |
+
# makeup_title: str = "Makeup Try-On"
|
116 |
+
# necklace_image_title: str = "Necklace Preview"
|
117 |
+
# nto_image_title: str = "Necklace Try-On"
|
118 |
+
# nto_cto_image_title: str = "Clothing Try-On"
|
119 |
+
# makeup_image_title: str = "Makeup Try-On"
|
120 |
+
# transition_duration: float = 0.5
|
121 |
+
#
|
122 |
+
#
|
123 |
+
# @app.post("/createvideo/")
|
124 |
+
# async def create_video(request: VideoGenerator):
|
125 |
+
# logger.info(f"Creating video with request: {request.dict()}")
|
126 |
+
# start_time = time.time()
|
127 |
+
# try:
|
128 |
+
# logger.info("Downloading images...")
|
129 |
+
# temp_files = {
|
130 |
+
# 'necklace': download_image(request.necklace_image),
|
131 |
+
# 'necklace_tryon': [download_image(url) for url in request.necklace_try_on_output_images],
|
132 |
+
# 'clothing': [download_image(url) for url in request.clothing_output_images],
|
133 |
+
# 'makeup': [download_image(url) for url in request.makeup_output_images]
|
134 |
+
# }
|
135 |
+
# file_download_time = time.time() - start_time
|
136 |
+
#
|
137 |
+
# if any(file is None for files in temp_files.values() for file in
|
138 |
+
# (files if isinstance(files, list) else [files])):
|
139 |
+
# return JSONResponse(content={"status": "error", "message": "Failed to download all required images."},
|
140 |
+
# status_code=400)
|
141 |
+
#
|
142 |
+
# intro_path = f"{RESOURCES_DIR}/intro/{request.intro_video_path}"
|
143 |
+
# output_path = f"{TEMP_VIDEO_DIR}/video_{os.urandom(8).hex()}.mp4"
|
144 |
+
# font_path = f"{RESOURCES_DIR}/fonts/{request.font_path}"
|
145 |
+
# audio_path = f"{RESOURCES_DIR}/audio/{request.background_audio_path}"
|
146 |
+
# logger.info(f"Creating video with paths: {intro_path}, {output_path}, {font_path}, {audio_path}")
|
147 |
+
#
|
148 |
+
# video_creator = VideoCreator(
|
149 |
+
# intro_video_path=intro_path,
|
150 |
+
# necklace_image=temp_files['necklace'],
|
151 |
+
# nto_outputs=temp_files['necklace_tryon'],
|
152 |
+
# nto_cto_outputs=temp_files['clothing'],
|
153 |
+
# makeup_outputs=temp_files['makeup'],
|
154 |
+
# font_path=font_path,
|
155 |
+
# output_path=output_path,
|
156 |
+
# audio_path=audio_path,
|
157 |
+
# image_display_duration=request.image_display_duration,
|
158 |
+
# fps=request.fps,
|
159 |
+
# necklace_image_title=request.necklace_image_title,
|
160 |
+
# nto_image_title=request.nto_image_title,
|
161 |
+
# nto_cto_image_title=request.nto_cto_image_title,
|
162 |
+
# makeup_image_title=request.makeup_image_title,
|
163 |
+
# )
|
164 |
+
# logger.info("Creating video...")
|
165 |
+
#
|
166 |
+
# video_creator.create_final_video()
|
167 |
+
# video_creation_time = time.time() - start_time - file_download_time
|
168 |
+
#
|
169 |
+
# url = upload_to_supabase(video_path=output_path)
|
170 |
+
# logger.info(f"Video created successfully: {url}")
|
171 |
+
# supabase_upload_time = time.time() - start_time - file_download_time - video_creation_time
|
172 |
+
# logger.info(f"Video uploaded to Supabase: {url}")
|
173 |
+
#
|
174 |
+
# response = {
|
175 |
+
# "status": "success",
|
176 |
+
# "message": "Video created successfully.",
|
177 |
+
# "video_url": url,
|
178 |
+
# "timings": {
|
179 |
+
# "file_download_time": file_download_time,
|
180 |
+
# "video_creation_time": video_creation_time,
|
181 |
+
# "supabase_upload_time": supabase_upload_time
|
182 |
+
# }
|
183 |
+
# }
|
184 |
+
# logger.info(f"Response: {response}")
|
185 |
+
#
|
186 |
+
# for files in temp_files.values():
|
187 |
+
# if isinstance(files, list):
|
188 |
+
# for file in files:
|
189 |
+
# if os.path.exists(file):
|
190 |
+
# os.unlink(file)
|
191 |
+
# elif os.path.exists(files):
|
192 |
+
# os.unlink(files)
|
193 |
+
#
|
194 |
+
# os.remove(output_path)
|
195 |
+
# logger.info("Files cleaned up successfully.")
|
196 |
+
# return JSONResponse(content=response, status_code=200)
|
197 |
+
#
|
198 |
+
# except Exception as e:
|
199 |
+
# logger.error(f"Error creating video: {str(e)}")
|
200 |
+
# return JSONResponse(content={"status": "error", "message": str(e)}, status_code=500)
|
201 |
|
202 |
|
203 |
class EachNecklaceVideoGeneratorRequest(BaseModel):
|
|
|
264 |
font_path = f"{RESOURCES_DIR}/fonts/{request.font_path}"
|
265 |
audio_path = f"{RESOURCES_DIR}/audio/{request.background_audio_path}"
|
266 |
outro_path = f"{RESOURCES_DIR}/outro/{request.outro_video_path}"
|
267 |
+
model_name = request.necklace_try_on_output_images[0][0].split("/")[-1].split(".")[0].split("-")[1]
|
268 |
|
269 |
video_creator = EachVideoCreator(
|
270 |
intro_video_path=intro_path,
|
|
|
298 |
video_creation_time = time.time() - start_time - file_download_time
|
299 |
logger.info("Video created successfully.")
|
300 |
|
301 |
+
url = upload_to_supabase(video_path=output_path, model_name=model_name)
|
302 |
supabase_upload_time = time.time() - start_time - file_download_time - video_creation_time
|
303 |
logger.info(f"Video uploaded to Supabase: {url}")
|
304 |
|