Spaces:
Sleeping
Sleeping
Commit ·
c3b64dd
1
Parent(s): 1136fdb
add: music list, logger
Browse files- .gitignore +1 -0
- app.py +34 -2
- resources/audio/ChrisHaugenMirage.mp3 +3 -0
- resources/audio/ElectroIndianROYALASHUTOSH.mp3 +3 -0
- resources/audio/IndianElectronicFUSIONFLOWASHUTOSH.mp3 +3 -0
- resources/audio/IndianInstrumentalKeralaMandolin.mp3 +3 -0
- resources/audio/LoveIndianCinematicBGM.mp3 +3 -0
- resources/audio/SitarDholakIndianInstrumentalBackgroundMusic.mp3 +3 -0
- src/utils/logs.py +27 -0
.gitignore
CHANGED
|
@@ -2,3 +2,4 @@ resourcesssss
|
|
| 2 |
temp_video
|
| 3 |
__pycache__
|
| 4 |
.idea
|
|
|
|
|
|
| 2 |
temp_video
|
| 3 |
__pycache__
|
| 4 |
.idea
|
| 5 |
+
/logs
|
app.py
CHANGED
|
@@ -12,6 +12,7 @@ from supabase import create_client
|
|
| 12 |
|
| 13 |
from src.components.each_necklace_video_gen import EachVideoCreator
|
| 14 |
from src.components.vidgen import VideoCreator
|
|
|
|
| 15 |
|
| 16 |
supabase_url = os.getenv('SUPABASE_URL')
|
| 17 |
supabase_key = os.getenv('SUPABASE_KEY')
|
|
@@ -27,6 +28,8 @@ os.environ['MOVIEPY_TEMP_DIR'] = '/tmp/moviepy'
|
|
| 27 |
|
| 28 |
|
| 29 |
def upload_to_supabase(video_path, bucket_name="JewelmirrorVideoGeneration"):
|
|
|
|
|
|
|
| 30 |
try:
|
| 31 |
if not os.path.exists(video_path):
|
| 32 |
raise FileNotFoundError(f"Video file not found: {video_path}")
|
|
@@ -39,6 +42,7 @@ def upload_to_supabase(video_path, bucket_name="JewelmirrorVideoGeneration"):
|
|
| 39 |
"x-upsert": "true",
|
| 40 |
"cache-control": "max-age=3600"
|
| 41 |
}
|
|
|
|
| 42 |
|
| 43 |
with open(video_path, 'rb') as f:
|
| 44 |
file_data = f.read()
|
|
@@ -52,17 +56,21 @@ def upload_to_supabase(video_path, bucket_name="JewelmirrorVideoGeneration"):
|
|
| 52 |
public_url = supabase.storage.from_(bucket_name).get_public_url(file_name)
|
| 53 |
|
| 54 |
response = requests.head(public_url)
|
|
|
|
| 55 |
if response.status_code != 200:
|
|
|
|
| 56 |
raise Exception(f"Upload verification failed: {response.status_code}")
|
| 57 |
|
|
|
|
| 58 |
return public_url
|
| 59 |
|
| 60 |
except Exception as e:
|
| 61 |
-
|
| 62 |
return None
|
| 63 |
|
| 64 |
|
| 65 |
def download_image(url):
|
|
|
|
| 66 |
try:
|
| 67 |
response = requests.get(url, stream=True)
|
| 68 |
response.raise_for_status()
|
|
@@ -71,8 +79,11 @@ def download_image(url):
|
|
| 71 |
with open(temp_file.name, 'wb') as f:
|
| 72 |
for chunk in response.iter_content(chunk_size=8192):
|
| 73 |
f.write(chunk)
|
|
|
|
|
|
|
| 74 |
return temp_file.name
|
| 75 |
except Exception as e:
|
|
|
|
| 76 |
print(f"Error downloading image from {url}: {str(e)}")
|
| 77 |
return None
|
| 78 |
|
|
@@ -98,8 +109,10 @@ class VideoGenerator(BaseModel):
|
|
| 98 |
|
| 99 |
@app.post("/createvideo/")
|
| 100 |
async def create_video(request: VideoGenerator):
|
|
|
|
| 101 |
start_time = time.time()
|
| 102 |
try:
|
|
|
|
| 103 |
temp_files = {
|
| 104 |
'necklace': download_image(request.necklace_image),
|
| 105 |
'necklace_tryon': [download_image(url) for url in request.necklace_try_on_output_images],
|
|
@@ -117,6 +130,7 @@ async def create_video(request: VideoGenerator):
|
|
| 117 |
output_path = f"{TEMP_VIDEO_DIR}/video_{os.urandom(8).hex()}.mp4"
|
| 118 |
font_path = f"{RESOURCES_DIR}/fonts/{request.font_path}"
|
| 119 |
audio_path = f"{RESOURCES_DIR}/audio/{request.background_audio_path}"
|
|
|
|
| 120 |
|
| 121 |
video_creator = VideoCreator(
|
| 122 |
intro_video_path=intro_path,
|
|
@@ -135,12 +149,15 @@ async def create_video(request: VideoGenerator):
|
|
| 135 |
makeup_image_title=request.makeup_image_title
|
| 136 |
|
| 137 |
)
|
|
|
|
| 138 |
|
| 139 |
video_creator.create_final_video()
|
| 140 |
video_creation_time = time.time() - start_time - file_download_time
|
| 141 |
|
| 142 |
url = upload_to_supabase(video_path=output_path)
|
|
|
|
| 143 |
supabase_upload_time = time.time() - start_time - file_download_time - video_creation_time
|
|
|
|
| 144 |
|
| 145 |
response = {
|
| 146 |
"status": "success",
|
|
@@ -152,6 +169,7 @@ async def create_video(request: VideoGenerator):
|
|
| 152 |
"supabase_upload_time": supabase_upload_time
|
| 153 |
}
|
| 154 |
}
|
|
|
|
| 155 |
|
| 156 |
for files in temp_files.values():
|
| 157 |
if isinstance(files, list):
|
|
@@ -162,9 +180,11 @@ async def create_video(request: VideoGenerator):
|
|
| 162 |
os.unlink(files)
|
| 163 |
|
| 164 |
os.remove(output_path)
|
|
|
|
| 165 |
return JSONResponse(content=response, status_code=200)
|
| 166 |
|
| 167 |
except Exception as e:
|
|
|
|
| 168 |
return JSONResponse(content={"status": "error", "message": str(e)}, status_code=500)
|
| 169 |
|
| 170 |
|
|
@@ -186,8 +206,11 @@ class EachNecklaceVideoGeneratorRequest(BaseModel):
|
|
| 186 |
|
| 187 |
@app.post("/createcombinedvideo/")
|
| 188 |
async def create_video(request: EachNecklaceVideoGeneratorRequest):
|
|
|
|
| 189 |
start_time = time.time()
|
| 190 |
try:
|
|
|
|
|
|
|
| 191 |
def process_images(image_list):
|
| 192 |
if isinstance(image_list, list):
|
| 193 |
return [process_images(item) for item in image_list]
|
|
@@ -202,6 +225,7 @@ async def create_video(request: EachNecklaceVideoGeneratorRequest):
|
|
| 202 |
file_download_time = time.time() - start_time
|
| 203 |
|
| 204 |
def verify_files(files):
|
|
|
|
| 205 |
if isinstance(files, list):
|
| 206 |
return all(verify_files(item) for item in files) # Recurse for nested lists
|
| 207 |
return files is not None # Check single file
|
|
@@ -236,14 +260,17 @@ async def create_video(request: EachNecklaceVideoGeneratorRequest):
|
|
| 236 |
makeup_title=request.makeup_image_title
|
| 237 |
|
| 238 |
)
|
|
|
|
| 239 |
|
| 240 |
# Generate video
|
| 241 |
video_creator.create_final_video()
|
| 242 |
video_creation_time = time.time() - start_time - file_download_time
|
| 243 |
-
|
| 244 |
# Upload video to Supabase
|
|
|
|
| 245 |
url = upload_to_supabase(video_path=output_path)
|
| 246 |
supabase_upload_time = time.time() - start_time - file_download_time - video_creation_time
|
|
|
|
| 247 |
|
| 248 |
response = {
|
| 249 |
"status": "success",
|
|
@@ -255,6 +282,7 @@ async def create_video(request: EachNecklaceVideoGeneratorRequest):
|
|
| 255 |
"supabase_upload_time": supabase_upload_time
|
| 256 |
}
|
| 257 |
}
|
|
|
|
| 258 |
|
| 259 |
def cleanup_files(files):
|
| 260 |
if isinstance(files, list):
|
|
@@ -266,6 +294,8 @@ async def create_video(request: EachNecklaceVideoGeneratorRequest):
|
|
| 266 |
if os.path.exists(output_path):
|
| 267 |
os.remove(output_path)
|
| 268 |
|
|
|
|
|
|
|
| 269 |
return JSONResponse(content=response, status_code=200)
|
| 270 |
|
| 271 |
except Exception as e:
|
|
@@ -274,9 +304,11 @@ async def create_video(request: EachNecklaceVideoGeneratorRequest):
|
|
| 274 |
|
| 275 |
@app.get("/resources")
|
| 276 |
async def get_infromation():
|
|
|
|
| 277 |
music = os.listdir(RESOURCES_DIR + "/audio")
|
| 278 |
fonts = os.listdir(RESOURCES_DIR + "/fonts")
|
| 279 |
intro = os.listdir(RESOURCES_DIR + "/intro")
|
|
|
|
| 280 |
|
| 281 |
json = {"music": music, "fonts": fonts, "intro": intro}
|
| 282 |
return JSONResponse(content=json, status_code=200)
|
|
|
|
| 12 |
|
| 13 |
from src.components.each_necklace_video_gen import EachVideoCreator
|
| 14 |
from src.components.vidgen import VideoCreator
|
| 15 |
+
from src.utils.logs import logger
|
| 16 |
|
| 17 |
supabase_url = os.getenv('SUPABASE_URL')
|
| 18 |
supabase_key = os.getenv('SUPABASE_KEY')
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
def upload_to_supabase(video_path, bucket_name="JewelmirrorVideoGeneration"):
|
| 31 |
+
logger.info(f"Uploading video to Supabase: {video_path}")
|
| 32 |
+
|
| 33 |
try:
|
| 34 |
if not os.path.exists(video_path):
|
| 35 |
raise FileNotFoundError(f"Video file not found: {video_path}")
|
|
|
|
| 42 |
"x-upsert": "true",
|
| 43 |
"cache-control": "max-age=3600"
|
| 44 |
}
|
| 45 |
+
logger.info(f"Uploading video to Supabase: {video_path}")
|
| 46 |
|
| 47 |
with open(video_path, 'rb') as f:
|
| 48 |
file_data = f.read()
|
|
|
|
| 56 |
public_url = supabase.storage.from_(bucket_name).get_public_url(file_name)
|
| 57 |
|
| 58 |
response = requests.head(public_url)
|
| 59 |
+
|
| 60 |
if response.status_code != 200:
|
| 61 |
+
logger.error(f"Upload verification failed: {response.status_code}")
|
| 62 |
raise Exception(f"Upload verification failed: {response.status_code}")
|
| 63 |
|
| 64 |
+
logger.info(f"Video uploaded successfully: {public_url}")
|
| 65 |
return public_url
|
| 66 |
|
| 67 |
except Exception as e:
|
| 68 |
+
logger.error(f"Error uploading to Supabase: {str(e)}")
|
| 69 |
return None
|
| 70 |
|
| 71 |
|
| 72 |
def download_image(url):
|
| 73 |
+
logger.info(f"Downloading image from {url}")
|
| 74 |
try:
|
| 75 |
response = requests.get(url, stream=True)
|
| 76 |
response.raise_for_status()
|
|
|
|
| 79 |
with open(temp_file.name, 'wb') as f:
|
| 80 |
for chunk in response.iter_content(chunk_size=8192):
|
| 81 |
f.write(chunk)
|
| 82 |
+
|
| 83 |
+
logger.info(f"Image downloaded successfully: {temp_file.name}")
|
| 84 |
return temp_file.name
|
| 85 |
except Exception as e:
|
| 86 |
+
logger.error(f"Error downloading image from {url}: {str(e)}")
|
| 87 |
print(f"Error downloading image from {url}: {str(e)}")
|
| 88 |
return None
|
| 89 |
|
|
|
|
| 109 |
|
| 110 |
@app.post("/createvideo/")
|
| 111 |
async def create_video(request: VideoGenerator):
|
| 112 |
+
logger.info(f"Creating video with request: {request.dict()}")
|
| 113 |
start_time = time.time()
|
| 114 |
try:
|
| 115 |
+
logger.info("Downloading images...")
|
| 116 |
temp_files = {
|
| 117 |
'necklace': download_image(request.necklace_image),
|
| 118 |
'necklace_tryon': [download_image(url) for url in request.necklace_try_on_output_images],
|
|
|
|
| 130 |
output_path = f"{TEMP_VIDEO_DIR}/video_{os.urandom(8).hex()}.mp4"
|
| 131 |
font_path = f"{RESOURCES_DIR}/fonts/{request.font_path}"
|
| 132 |
audio_path = f"{RESOURCES_DIR}/audio/{request.background_audio_path}"
|
| 133 |
+
logger.info(f"Creating video with paths: {intro_path}, {output_path}, {font_path}, {audio_path}")
|
| 134 |
|
| 135 |
video_creator = VideoCreator(
|
| 136 |
intro_video_path=intro_path,
|
|
|
|
| 149 |
makeup_image_title=request.makeup_image_title
|
| 150 |
|
| 151 |
)
|
| 152 |
+
logger.info("Creating video...")
|
| 153 |
|
| 154 |
video_creator.create_final_video()
|
| 155 |
video_creation_time = time.time() - start_time - file_download_time
|
| 156 |
|
| 157 |
url = upload_to_supabase(video_path=output_path)
|
| 158 |
+
logger.info(f"Video created successfully: {url}")
|
| 159 |
supabase_upload_time = time.time() - start_time - file_download_time - video_creation_time
|
| 160 |
+
logger.info(f"Video uploaded to Supabase: {url}")
|
| 161 |
|
| 162 |
response = {
|
| 163 |
"status": "success",
|
|
|
|
| 169 |
"supabase_upload_time": supabase_upload_time
|
| 170 |
}
|
| 171 |
}
|
| 172 |
+
logger.info(f"Response: {response}")
|
| 173 |
|
| 174 |
for files in temp_files.values():
|
| 175 |
if isinstance(files, list):
|
|
|
|
| 180 |
os.unlink(files)
|
| 181 |
|
| 182 |
os.remove(output_path)
|
| 183 |
+
logger.info("Files cleaned up successfully.")
|
| 184 |
return JSONResponse(content=response, status_code=200)
|
| 185 |
|
| 186 |
except Exception as e:
|
| 187 |
+
logger.error(f"Error creating video: {str(e)}")
|
| 188 |
return JSONResponse(content={"status": "error", "message": str(e)}, status_code=500)
|
| 189 |
|
| 190 |
|
|
|
|
| 206 |
|
| 207 |
@app.post("/createcombinedvideo/")
|
| 208 |
async def create_video(request: EachNecklaceVideoGeneratorRequest):
|
| 209 |
+
logger.info(f"Creating video with request: {request.dict()}")
|
| 210 |
start_time = time.time()
|
| 211 |
try:
|
| 212 |
+
logger.info("Downloading images...")
|
| 213 |
+
|
| 214 |
def process_images(image_list):
|
| 215 |
if isinstance(image_list, list):
|
| 216 |
return [process_images(item) for item in image_list]
|
|
|
|
| 225 |
file_download_time = time.time() - start_time
|
| 226 |
|
| 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) # Recurse for nested lists
|
| 231 |
return files is not None # Check single file
|
|
|
|
| 260 |
makeup_title=request.makeup_image_title
|
| 261 |
|
| 262 |
)
|
| 263 |
+
logger.info("Creating video...")
|
| 264 |
|
| 265 |
# Generate video
|
| 266 |
video_creator.create_final_video()
|
| 267 |
video_creation_time = time.time() - start_time - file_download_time
|
| 268 |
+
logger.info("Video created successfully.")
|
| 269 |
# Upload video to Supabase
|
| 270 |
+
|
| 271 |
url = upload_to_supabase(video_path=output_path)
|
| 272 |
supabase_upload_time = time.time() - start_time - file_download_time - video_creation_time
|
| 273 |
+
logger.info(f"Video uploaded to Supabase: {url}")
|
| 274 |
|
| 275 |
response = {
|
| 276 |
"status": "success",
|
|
|
|
| 282 |
"supabase_upload_time": supabase_upload_time
|
| 283 |
}
|
| 284 |
}
|
| 285 |
+
logger.info(f"Response: {response}")
|
| 286 |
|
| 287 |
def cleanup_files(files):
|
| 288 |
if isinstance(files, list):
|
|
|
|
| 294 |
if os.path.exists(output_path):
|
| 295 |
os.remove(output_path)
|
| 296 |
|
| 297 |
+
logger.info("Files cleaned up successfully.")
|
| 298 |
+
|
| 299 |
return JSONResponse(content=response, status_code=200)
|
| 300 |
|
| 301 |
except Exception as e:
|
|
|
|
| 304 |
|
| 305 |
@app.get("/resources")
|
| 306 |
async def get_infromation():
|
| 307 |
+
logger.info("Getting resources information")
|
| 308 |
music = os.listdir(RESOURCES_DIR + "/audio")
|
| 309 |
fonts = os.listdir(RESOURCES_DIR + "/fonts")
|
| 310 |
intro = os.listdir(RESOURCES_DIR + "/intro")
|
| 311 |
+
logger.info(f"Resources: {music}, {fonts}, {intro}")
|
| 312 |
|
| 313 |
json = {"music": music, "fonts": fonts, "intro": intro}
|
| 314 |
return JSONResponse(content=json, status_code=200)
|
resources/audio/ChrisHaugenMirage.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:230d11502724a50fe8d3b5d9d7e2c43d8432f970e6d185e8bfbfe7cac6d3e6fc
|
| 3 |
+
size 7170226
|
resources/audio/ElectroIndianROYALASHUTOSH.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:68127acdea914d66eca0e1e0bff00f4d525c64d7407b8cceaf3d3596dde90230
|
| 3 |
+
size 8547402
|
resources/audio/IndianElectronicFUSIONFLOWASHUTOSH.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b90760624a483fcafa661626abe9553e03271cc96ea01823098663e5e5ec5091
|
| 3 |
+
size 6686439
|
resources/audio/IndianInstrumentalKeralaMandolin.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e06e32f7af96a3be67e21f2ee925822af2bbecaf39c1fde7a61943c545263ec8
|
| 3 |
+
size 5045949
|
resources/audio/LoveIndianCinematicBGM.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:70707dedb298f220ebbc8869fb8cc9e49a3e72473808e3a20f17cc053e2f5a59
|
| 3 |
+
size 11458488
|
resources/audio/SitarDholakIndianInstrumentalBackgroundMusic.mp3
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c66b23af609df9f54444b38b81343d46736e18ef76bccf29ae9a008d722b962e
|
| 3 |
+
size 5053263
|
src/utils/logs.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
project @ images_to_video
|
| 3 |
+
created @ 2024-12-18
|
| 4 |
+
author @ github.com/ishworrsubedii
|
| 5 |
+
"""
|
| 6 |
+
import logging
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
+
logger.setLevel(logging.INFO)
|
| 11 |
+
|
| 12 |
+
log_dir = os.path.join(os.getcwd(), "logs")
|
| 13 |
+
os.makedirs(log_dir, exist_ok=True)
|
| 14 |
+
|
| 15 |
+
LOG_FILE = os.path.join(log_dir, "running_logs.log")
|
| 16 |
+
|
| 17 |
+
logFormat = "[%(asctime)s: %(levelname)s: %(module)s: %(message)s]"
|
| 18 |
+
logFormatter = logging.Formatter(fmt=logFormat, style="%")
|
| 19 |
+
|
| 20 |
+
streamHandler = logging.StreamHandler()
|
| 21 |
+
streamHandler.setFormatter(logFormatter)
|
| 22 |
+
|
| 23 |
+
fileHandler = logging.FileHandler(filename=LOG_FILE)
|
| 24 |
+
fileHandler.setFormatter(logFormatter)
|
| 25 |
+
|
| 26 |
+
logger.addHandler(streamHandler)
|
| 27 |
+
logger.addHandler(fileHandler)
|