Spaces:
Sleeping
Sleeping
Commit
·
0ed501e
1
Parent(s):
68b40f6
add: font, transition list
Browse files- app.py +19 -4
- resources/fonts/Cinzel-VariableFont.ttf +3 -0
- resources/fonts/Lora-VariableFont.ttf +3 -0
- resources/fonts/MerriweatherSans-VariableFont.ttf +3 -0
- resources/fonts/{PlayfairDisplay-VariableFont_wght.ttf → PlayfairDisplay-VariableFont.ttf} +0 -0
- resources/fonts/Quicksand-VariableFont.ttf +3 -0
- resources/fonts/Roboto-Medium.ttf +3 -0
- src/components/each_necklace_video_gen.py +45 -4
- src/components/imgs_video.py +1 -1
- src/components/main.py +1 -1
- video_73a69e732a48e5e2TEMP_MPY_wvf_snd.mp4 +3 -0
app.py
CHANGED
@@ -95,7 +95,7 @@ class VideoGenerator(BaseModel):
|
|
95 |
makeup_output_images: list[str]
|
96 |
intro_video_path: str = "JewelMirror_intro.mp4"
|
97 |
background_audio_path: str = "TraditionalIndianVlogMusic.mp3"
|
98 |
-
font_path: str = "PlayfairDisplay-
|
99 |
image_display_duration: float = 2.5
|
100 |
fps: int = 30
|
101 |
necklace_title: str = "Necklace Try-On"
|
@@ -105,6 +105,7 @@ class VideoGenerator(BaseModel):
|
|
105 |
nto_image_title: str = "Necklace Try-On"
|
106 |
nto_cto_image_title: str = "Clothing Try-On"
|
107 |
makeup_image_title: str = "Makeup Try-On"
|
|
|
108 |
|
109 |
|
110 |
@app.post("/createvideo/")
|
@@ -190,7 +191,7 @@ async def create_video(request: VideoGenerator):
|
|
190 |
|
191 |
class EachNecklaceVideoGeneratorRequest(BaseModel):
|
192 |
intro_video_path: str = "JewelMirror_intro.mp4"
|
193 |
-
font_path: str = "PlayfairDisplay-
|
194 |
background_audio_path: str = "TraditionalIndianVlogMusic.mp3"
|
195 |
image_display_duration: float = 2.5
|
196 |
fps: int = 10
|
@@ -207,6 +208,9 @@ class EachNecklaceVideoGeneratorRequest(BaseModel):
|
|
207 |
address: str = "123, ABC Street, XYZ City"
|
208 |
phone_numbers: str = "1234567890"
|
209 |
logo_url: str = "https://lvuhhlrkcuexzqtsbqyu.supabase.co/storage/v1/object/public/MagicMirror/FullImages/default.png"
|
|
|
|
|
|
|
210 |
|
211 |
|
212 |
@app.post("/createcombinedvideo/")
|
@@ -267,7 +271,10 @@ async def create_combined_video(request: EachNecklaceVideoGeneratorRequest):
|
|
267 |
outro_title=request.outro_title,
|
268 |
address=request.address,
|
269 |
phone_numbers=request.phone_numbers,
|
270 |
-
logo_image=temp_files['logo']
|
|
|
|
|
|
|
271 |
|
272 |
)
|
273 |
logger.info("Creating video...")
|
@@ -310,8 +317,16 @@ async def create_combined_video(request: EachNecklaceVideoGeneratorRequest):
|
|
310 |
return JSONResponse(content={"status": "error", "message": str(e)}, status_code=500)
|
311 |
|
312 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
313 |
@app.get("/resources")
|
314 |
-
async def
|
315 |
logger.info("Getting resources information")
|
316 |
music = os.listdir(RESOURCES_DIR + "/audio")
|
317 |
fonts = os.listdir(RESOURCES_DIR + "/fonts")
|
|
|
95 |
makeup_output_images: list[str]
|
96 |
intro_video_path: str = "JewelMirror_intro.mp4"
|
97 |
background_audio_path: str = "TraditionalIndianVlogMusic.mp3"
|
98 |
+
font_path: str = "PlayfairDisplay-VariableFont.ttf"
|
99 |
image_display_duration: float = 2.5
|
100 |
fps: int = 30
|
101 |
necklace_title: str = "Necklace Try-On"
|
|
|
105 |
nto_image_title: str = "Necklace Try-On"
|
106 |
nto_cto_image_title: str = "Clothing Try-On"
|
107 |
makeup_image_title: str = "Makeup Try-On"
|
108 |
+
transition_duration: float = 0.5
|
109 |
|
110 |
|
111 |
@app.post("/createvideo/")
|
|
|
191 |
|
192 |
class EachNecklaceVideoGeneratorRequest(BaseModel):
|
193 |
intro_video_path: str = "JewelMirror_intro.mp4"
|
194 |
+
font_path: str = "PlayfairDisplay-VariableFont.ttf"
|
195 |
background_audio_path: str = "TraditionalIndianVlogMusic.mp3"
|
196 |
image_display_duration: float = 2.5
|
197 |
fps: int = 10
|
|
|
208 |
address: str = "123, ABC Street, XYZ City"
|
209 |
phone_numbers: str = "1234567890"
|
210 |
logo_url: str = "https://lvuhhlrkcuexzqtsbqyu.supabase.co/storage/v1/object/public/MagicMirror/FullImages/default.png"
|
211 |
+
transition_duration: float = 0.5
|
212 |
+
transition_type: str = "None"
|
213 |
+
direction: str = "left"
|
214 |
|
215 |
|
216 |
@app.post("/createcombinedvideo/")
|
|
|
271 |
outro_title=request.outro_title,
|
272 |
address=request.address,
|
273 |
phone_numbers=request.phone_numbers,
|
274 |
+
logo_image=temp_files['logo'],
|
275 |
+
transition_duration=request.transition_duration,
|
276 |
+
transition_type=request.transition_type,
|
277 |
+
direction=request.direction
|
278 |
|
279 |
)
|
280 |
logger.info("Creating video...")
|
|
|
317 |
return JSONResponse(content={"status": "error", "message": str(e)}, status_code=500)
|
318 |
|
319 |
|
320 |
+
@app.get("/transition_list")
|
321 |
+
async def get_transitions():
|
322 |
+
response = {
|
323 |
+
"transitions": ["crossfadein", "slidein", "crossfaidout", "slideout"]
|
324 |
+
}
|
325 |
+
return JSONResponse(content=response, status_code=200)
|
326 |
+
|
327 |
+
|
328 |
@app.get("/resources")
|
329 |
+
async def get_information():
|
330 |
logger.info("Getting resources information")
|
331 |
music = os.listdir(RESOURCES_DIR + "/audio")
|
332 |
fonts = os.listdir(RESOURCES_DIR + "/fonts")
|
resources/fonts/Cinzel-VariableFont.ttf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e7093fd80b66eeb7bf1c7614fa229331ebf72865eeaea1e1059473c1871a6178
|
3 |
+
size 124700
|
resources/fonts/Lora-VariableFont.ttf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:89ca16201126fe2df3f5d95ca381e705f48852b73b04adabf67f9b83c8dac0ac
|
3 |
+
size 210884
|
resources/fonts/MerriweatherSans-VariableFont.ttf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3c16eb5e2feec96e3106a585863a096e72bf60431685be049f206576bcacb26a
|
3 |
+
size 267396
|
resources/fonts/{PlayfairDisplay-VariableFont_wght.ttf → PlayfairDisplay-VariableFont.ttf}
RENAMED
File without changes
|
resources/fonts/Quicksand-VariableFont.ttf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d232fd1509a079af3cccf654f11e42de91f15427fbd88373e3d849228dfda496
|
3 |
+
size 124196
|
resources/fonts/Roboto-Medium.ttf
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0de679de4d3d236c4a60e13bd2cd16d0f93368e9f6ba848385a8023c2e53c202
|
3 |
+
size 168644
|
src/components/each_necklace_video_gen.py
CHANGED
@@ -10,6 +10,7 @@ from moviepy.audio.io.AudioFileClip import AudioFileClip
|
|
10 |
from moviepy.video.VideoClip import ImageClip, ColorClip, TextClip
|
11 |
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
|
12 |
from moviepy.video.compositing.concatenate import concatenate_videoclips
|
|
|
13 |
from moviepy.video.fx.all import resize
|
14 |
from moviepy.video.io.VideoFileClip import VideoFileClip
|
15 |
|
@@ -21,7 +22,7 @@ class EachVideoCreator:
|
|
21 |
nto_cto_outputs=None, makeup_outputs=None, font_path=None, output_path=None,
|
22 |
audio_path=None, image_display_duration=2.5, box_color=(131, 42, 48), box_opacity=0.8,
|
23 |
font_size=28, text_color="white", fps=1, outro_title=None, logo_image=None, address=None,
|
24 |
-
phone_numbers=None):
|
25 |
self.intro_video_path = intro_video_path
|
26 |
self.necklace_images = necklace_image if necklace_image else []
|
27 |
self.nto_outputs = nto_outputs if nto_outputs else []
|
@@ -45,6 +46,9 @@ class EachVideoCreator:
|
|
45 |
self.logo_image = logo_image
|
46 |
self.address = address
|
47 |
self.phone_numbers = phone_numbers
|
|
|
|
|
|
|
48 |
|
49 |
def create_necklace_clips(self, necklace_image, index, label):
|
50 |
if not necklace_image:
|
@@ -117,6 +121,25 @@ class EachVideoCreator:
|
|
117 |
|
118 |
return final_clip
|
119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
def create_final_video(self):
|
121 |
try:
|
122 |
print("Starting video creation...")
|
@@ -179,7 +202,27 @@ class EachVideoCreator:
|
|
179 |
|
180 |
final_clips = []
|
181 |
for clip in clips:
|
182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
clips = final_clips
|
184 |
|
185 |
if not clips:
|
@@ -189,7 +232,6 @@ class EachVideoCreator:
|
|
189 |
print(f"Total clips to concatenate: {len(clips)}")
|
190 |
final_video = concatenate_videoclips(clips, method="compose")
|
191 |
|
192 |
-
# Step 4: Add Background Audio
|
193 |
if self.audio_path and os.path.exists(self.audio_path):
|
194 |
print(f"Adding background audio from path: {self.audio_path}")
|
195 |
try:
|
@@ -200,7 +242,6 @@ class EachVideoCreator:
|
|
200 |
else:
|
201 |
print("Skipping background audio: Path not provided or invalid.")
|
202 |
|
203 |
-
# Step 5: Export Final Video
|
204 |
print("Rendering final video...")
|
205 |
final_video.write_videofile(
|
206 |
self.output_video_path,
|
|
|
10 |
from moviepy.video.VideoClip import ImageClip, ColorClip, TextClip
|
11 |
from moviepy.video.compositing.CompositeVideoClip import CompositeVideoClip
|
12 |
from moviepy.video.compositing.concatenate import concatenate_videoclips
|
13 |
+
from moviepy.video.compositing.transitions import slide_in, crossfadein, make_loopable, crossfadeout, slide_out
|
14 |
from moviepy.video.fx.all import resize
|
15 |
from moviepy.video.io.VideoFileClip import VideoFileClip
|
16 |
|
|
|
22 |
nto_cto_outputs=None, makeup_outputs=None, font_path=None, output_path=None,
|
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='crossfade', direction='left'):
|
26 |
self.intro_video_path = intro_video_path
|
27 |
self.necklace_images = necklace_image if necklace_image else []
|
28 |
self.nto_outputs = nto_outputs if nto_outputs else []
|
|
|
46 |
self.logo_image = logo_image
|
47 |
self.address = address
|
48 |
self.phone_numbers = phone_numbers
|
49 |
+
self.transition_duration = transition_duration
|
50 |
+
self.transition_type = transition_type
|
51 |
+
self.direction = direction
|
52 |
|
53 |
def create_necklace_clips(self, necklace_image, index, label):
|
54 |
if not necklace_image:
|
|
|
121 |
|
122 |
return final_clip
|
123 |
|
124 |
+
def apply_slideout_transition(self, clip, direction='left'):
|
125 |
+
if direction == 'left':
|
126 |
+
return slide_in(clip, duration=self.transition_duration, side='right')
|
127 |
+
return slide_in(clip, duration=self.transition_duration, side='left')
|
128 |
+
|
129 |
+
def apply_slidein_transition(self, clip, direction='left'):
|
130 |
+
if direction == 'left':
|
131 |
+
return slide_out(clip, duration=self.transition_duration, side='right')
|
132 |
+
return slide_out(clip, duration=self.transition_duration, side='left')
|
133 |
+
|
134 |
+
def apply_loopable_transition(self, clip):
|
135 |
+
return make_loopable(clip, duration=self.transition_duration)
|
136 |
+
|
137 |
+
def apply_crossfadein_transition(self, clip):
|
138 |
+
return crossfadein(clip, self.transition_duration)
|
139 |
+
|
140 |
+
def apply_crossfadeout_transition(self, clip):
|
141 |
+
return crossfadeout(clip, self.transition_duration)
|
142 |
+
|
143 |
def create_final_video(self):
|
144 |
try:
|
145 |
print("Starting video creation...")
|
|
|
202 |
|
203 |
final_clips = []
|
204 |
for clip in clips:
|
205 |
+
clip = clip.set_duration(self.image_display_duration)
|
206 |
+
try:
|
207 |
+
|
208 |
+
if self.transition_type == 'crossfadein':
|
209 |
+
clip_with_transition = self.apply_crossfadein_transition(clip)
|
210 |
+
elif self.transition_type == 'crossfadeout':
|
211 |
+
clip_with_transition = self.apply_crossfadeout_transition(clip)
|
212 |
+
elif self.transition_type == 'slideout':
|
213 |
+
clip_with_transition = self.apply_slideout_transition(clip, self.direction)
|
214 |
+
elif self.transition_type == 'slidein':
|
215 |
+
clip_with_transition = self.apply_slidein_transition(clip, self.direction)
|
216 |
+
elif self.transition_type == 'loop':
|
217 |
+
clip_with_transition = self.apply_loopable_transition(clip)
|
218 |
+
else:
|
219 |
+
clip_with_transition = clip
|
220 |
+
|
221 |
+
final_clips.append(clip_with_transition)
|
222 |
+
|
223 |
+
except Exception as e:
|
224 |
+
print(f"Error applying transition: {e}")
|
225 |
+
final_clips.append(clip)
|
226 |
clips = final_clips
|
227 |
|
228 |
if not clips:
|
|
|
232 |
print(f"Total clips to concatenate: {len(clips)}")
|
233 |
final_video = concatenate_videoclips(clips, method="compose")
|
234 |
|
|
|
235 |
if self.audio_path and os.path.exists(self.audio_path):
|
236 |
print(f"Adding background audio from path: {self.audio_path}")
|
237 |
try:
|
|
|
242 |
else:
|
243 |
print("Skipping background audio: Path not provided or invalid.")
|
244 |
|
|
|
245 |
print("Rendering final video...")
|
246 |
final_video.write_videofile(
|
247 |
self.output_video_path,
|
src/components/imgs_video.py
CHANGED
@@ -25,7 +25,7 @@
|
|
25 |
# "nto_cto_images_dir": "/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/02_medium_long_haram/nto_cto_output",
|
26 |
# "makeup_images_dir": "/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/02_medium_long_haram/makeup",
|
27 |
# "output_video_path": f"/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/02_medium_long_haram/output/{self.current_date}_jewelmirror_cjm.mp4",
|
28 |
-
# "font_path": "/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/font/PlayfairDisplay-
|
29 |
# "necklace_image": "/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/01_lean_short_necklace/necklace_image/KAR2201CR001.png",
|
30 |
# "audio_path": "/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/audio/TraditionalIndianVlogMusic.mp3",
|
31 |
# "transition_duration": 1.0,
|
|
|
25 |
# "nto_cto_images_dir": "/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/02_medium_long_haram/nto_cto_output",
|
26 |
# "makeup_images_dir": "/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/02_medium_long_haram/makeup",
|
27 |
# "output_video_path": f"/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/02_medium_long_haram/output/{self.current_date}_jewelmirror_cjm.mp4",
|
28 |
+
# "font_path": "/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/font/PlayfairDisplay-VariableFont.ttf",
|
29 |
# "necklace_image": "/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/01_lean_short_necklace/necklace_image/KAR2201CR001.png",
|
30 |
# "audio_path": "/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/audio/TraditionalIndianVlogMusic.mp3",
|
31 |
# "transition_duration": 1.0,
|
src/components/main.py
CHANGED
@@ -17,7 +17,7 @@
|
|
17 |
# "intro_video_url": "",
|
18 |
# "outro_video_url": "",
|
19 |
# "output_video_path": f"/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/output/{self.current_date}_jewelmirror_cjm.mp4",
|
20 |
-
# "font_path": "/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/font/PlayfairDisplay-
|
21 |
# "audio_url": "",
|
22 |
# "transition_duration": 1.0,
|
23 |
# "image_display_duration": 2.5,
|
|
|
17 |
# "intro_video_url": "",
|
18 |
# "outro_video_url": "",
|
19 |
# "output_video_path": f"/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/output/{self.current_date}_jewelmirror_cjm.mp4",
|
20 |
+
# "font_path": "/home/ishwor/Desktop/TCP/Virtual_Makeup/images_to_video/resourcesssss/font/PlayfairDisplay-VariableFont.ttf",
|
21 |
# "audio_url": "",
|
22 |
# "transition_duration": 1.0,
|
23 |
# "image_display_duration": 2.5,
|
video_73a69e732a48e5e2TEMP_MPY_wvf_snd.mp4
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5b96c1b6b6f8307fea957e03d3662739877babdadb60604e262b19d20fc35e70
|
3 |
+
size 489694
|