Update app.py
Browse files
app.py
CHANGED
@@ -64,7 +64,6 @@ def adjust_aspect_ratio(clip, option):
|
|
64 |
width, height = clip.size
|
65 |
current_ratio = width / height
|
66 |
|
67 |
-
# ์์์ด ๋๋ฌด ๋๋ค๋ฉด ๊ฐ๋ก๋ฅผ, ๋๋ฌด ๋๋ค๋ฉด ์ธ๋ก๋ฅผ ํฌ๋กญํฉ๋๋ค.
|
68 |
if current_ratio > target_ratio:
|
69 |
new_width = int(height * target_ratio)
|
70 |
new_height = height
|
@@ -77,11 +76,11 @@ def adjust_aspect_ratio(clip, option):
|
|
77 |
def process_video(video,
|
78 |
start_time_str,
|
79 |
end_time_str,
|
80 |
-
platform_option,
|
81 |
-
frame_rate_factor,
|
82 |
speed_factor,
|
83 |
repeat_count,
|
84 |
-
resolution_scale):
|
85 |
"""
|
86 |
๋์์์ GIF๋ก ๋ณํํ๋ ํจ์
|
87 |
"""
|
@@ -90,7 +89,7 @@ def process_video(video,
|
|
90 |
|
91 |
add_log("[LOG 1] ๋น๋์ค ์
๋ก๋ ๋ฐ ์ฒ๋ฆฌ ์์")
|
92 |
|
93 |
-
# video ํ๋ผ๋ฏธํฐ์์ ํ์ผ ๊ฒฝ๋ก ์ถ์ถ
|
94 |
video_path = video if isinstance(video, str) else video.name
|
95 |
|
96 |
add_log("[LOG 2] ๋น๋์ค ๋ก๋ ์ค...")
|
@@ -121,11 +120,10 @@ def process_video(video,
|
|
121 |
add_log("[LOG 6] ์์ ์๋ฅด๊ธฐ ์์
์งํ...")
|
122 |
clip = input_video.subclip(start_sec, end_sec)
|
123 |
|
124 |
-
# ํ๋ซํผ๋ณ ํด์๋(๋น์จ) ์กฐ์
|
125 |
add_log(f"[LOG 7] ํ๋ซํผ ๋น์จ ์กฐ์ : {platform_option}")
|
126 |
clip = adjust_aspect_ratio(clip, platform_option)
|
127 |
|
128 |
-
# ์ถ๋ ฅ ํด์๋ ์ถ์
|
129 |
if abs(resolution_scale - 1.0) > 1e-3:
|
130 |
add_log(f"[LOG 7-1] ์ถ๋ ฅ ํด์๋ ์ถ์: {resolution_scale*100:.0f}%")
|
131 |
clip = clip.resize(resolution_scale)
|
@@ -135,13 +133,12 @@ def process_video(video,
|
|
135 |
add_log(f"[LOG 8] ์ฌ์์๋ {speed_factor}๋ฐฐ๋ก ์กฐ์ ์ค...")
|
136 |
clip = clip.fx(mp.vfx.speedx, speed_factor)
|
137 |
|
138 |
-
# FPS ์กฐ์
|
139 |
original_fps = clip.fps
|
140 |
target_fps = original_fps * frame_rate_factor
|
141 |
add_log(f"[LOG 9] ์ต์ข
์ถ๋ ฅ FPS: {target_fps:.2f} (์๋ณธ FPS: {original_fps})")
|
142 |
clip = clip.set_fps(target_fps)
|
143 |
|
144 |
-
# ๋ฐ๋ณต ํ์
|
145 |
add_log(f"[LOG 10] GIF ๋ฐ๋ณต ํ์ ์ค์ : {repeat_count} (0์ด๋ฉด ๋ฌดํ๋ฐ๋ณต)")
|
146 |
final_clip = clip
|
147 |
|
@@ -149,19 +146,17 @@ def process_video(video,
|
|
149 |
output_filename = f"temp_{uuid.uuid4().hex}.gif"
|
150 |
try:
|
151 |
loop_param = 0 if int(repeat_count) == 0 else int(repeat_count)
|
152 |
-
# ImageMagick๋ก GIF ์์ฑ (loop ์ ์ฉ)
|
153 |
final_clip.write_gif(output_filename, fps=target_fps, loop=loop_param)
|
154 |
add_log(f"[LOG 12] GIF ์์ฑ ์๋ฃ! ํ์ผ๋ช
: {output_filename}, loop={loop_param}")
|
155 |
except Exception as e:
|
156 |
add_log(f"[ERROR] GIF ์์ฑ ์คํจ: {e}")
|
157 |
return None, None, "\n".join(global_logs)
|
158 |
|
159 |
-
# ๊ฒฐ๊ณผ ๋ฐํ (๋ฏธ๋ฆฌ๋ณด๊ธฐ์ฉ ๊ฒฝ๋ก, ๋ค์ด๋ก๋์ฉ ๊ฒฝ๋ก, ๋ก๊ทธ)
|
160 |
return output_filename, output_filename, "\n".join(global_logs)
|
161 |
|
162 |
def update_thumbnails(video, start_time_str, end_time_str):
|
163 |
"""
|
164 |
-
์์/๋ ์ธ๋ค์ผ์
|
165 |
"""
|
166 |
video_path = video if isinstance(video, str) else video.name
|
167 |
|
@@ -188,185 +183,180 @@ def update_thumbnails(video, start_time_str, end_time_str):
|
|
188 |
|
189 |
return start_thumb, end_thumb
|
190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
# ------------------------------
|
192 |
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ (Blocks)
|
193 |
# ------------------------------
|
194 |
-
with gr.Blocks() as demo:
|
195 |
-
#
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
body, h1, h2, h3, h4, p, div, span {
|
202 |
-
margin: 0; padding: 0; box-sizing: border-box;
|
203 |
-
font-family: "Noto Sans", sans-serif;
|
204 |
-
}
|
205 |
-
|
206 |
-
/* ๋ฐฐ๊ฒฝ์, ๋ง์ง ๋ฑ ๊ธฐ๋ณธ ์ค์ */
|
207 |
-
body {
|
208 |
-
background: #fefefe;
|
209 |
-
color: #333;
|
210 |
-
padding: 20px;
|
211 |
-
}
|
212 |
-
|
213 |
-
/* ํฐ ํ์ดํ */
|
214 |
-
.main-title {
|
215 |
-
font-size: 2.0rem;
|
216 |
-
text-align: center;
|
217 |
-
margin: 0.5em 0;
|
218 |
-
color: #e67e22; /* ์ค๋ ์ง ํค */
|
219 |
-
font-weight: bold;
|
220 |
-
}
|
221 |
-
|
222 |
-
/* ์๋ด ๋ฌธ๊ตฌ (์ฌ์ฉ ๊ฐ์ด๋ ๋ฑ) */
|
223 |
-
.guide-text {
|
224 |
-
font-size: 1rem;
|
225 |
-
color: #555;
|
226 |
-
margin-bottom: 1.5em;
|
227 |
-
text-align: center;
|
228 |
-
line-height: 1.4em;
|
229 |
-
}
|
230 |
-
|
231 |
-
.emoji-title {
|
232 |
-
font-size: 1.3rem;
|
233 |
-
margin-bottom: 0.5em;
|
234 |
-
text-align: center;
|
235 |
-
color: #2ecc71; /* ๊ทธ๋ฆฐ ํค */
|
236 |
-
}
|
237 |
-
|
238 |
-
/* ์ปจํ
์ด๋๋ฅผ ์ข์ฐ๋ก ๋ฐฐ์น */
|
239 |
-
.row-container {
|
240 |
-
display: flex;
|
241 |
-
flex-direction: row;
|
242 |
-
justify-content: space-between;
|
243 |
-
margin-bottom: 1.5em;
|
244 |
-
gap: 1em;
|
245 |
-
}
|
246 |
-
|
247 |
-
/* 2๊ฐ์ ๋ฐ์ค๋ฅผ ๊ฐ๊ฐ ๋ฐ์ผ๋ก ๋๋์ด ๋ฐฐ์น */
|
248 |
-
.box {
|
249 |
-
width: 50%;
|
250 |
-
background-color: #ffffff;
|
251 |
-
border: 2px solid #ddd;
|
252 |
-
border-radius: 15px;
|
253 |
-
padding: 1em;
|
254 |
-
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
255 |
-
}
|
256 |
-
|
257 |
-
/* 1๊ฐ์ ๋ฐ์ค ์ ์ฒด ๋๋น */
|
258 |
-
.single-box {
|
259 |
-
width: 100%;
|
260 |
-
background-color: #ffffff;
|
261 |
-
border: 2px solid #ddd;
|
262 |
-
border-radius: 15px;
|
263 |
-
padding: 1em;
|
264 |
-
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
|
265 |
-
margin-bottom: 1.5em;
|
266 |
-
}
|
267 |
-
|
268 |
-
/* ์น์
๋ด๋ถ ํค๋ ์คํ์ผ */
|
269 |
-
.section-title {
|
270 |
-
font-size: 1.2rem;
|
271 |
-
margin-bottom: 0.5em;
|
272 |
-
font-weight: bold;
|
273 |
-
color: #3498db; /* ๋ธ๋ฃจ ํค */
|
274 |
-
}
|
275 |
-
|
276 |
-
/* ์ปดํฌ๋ํธ ๋ฐฐ์น ์ํ ๋ด๋ถ ๋ํผ */
|
277 |
-
.component-wrapper {
|
278 |
-
margin-bottom: 0.8em;
|
279 |
-
}
|
280 |
-
|
281 |
-
/* "GIF ์์ฑํ๊ธฐ" ๋ฒํผ ์คํ์ผ(์ฝ๊ฐ ํฌ๊ฒ) */
|
282 |
-
.big-button {
|
283 |
-
display: block;
|
284 |
-
width: 100%;
|
285 |
-
padding: 0.8em;
|
286 |
-
background-color: #e74c3c;
|
287 |
-
color: #fff;
|
288 |
-
border: none;
|
289 |
-
border-radius: 8px;
|
290 |
-
font-size: 1.1rem;
|
291 |
-
font-weight: bold;
|
292 |
-
cursor: pointer;
|
293 |
-
margin-top: 1em;
|
294 |
-
}
|
295 |
-
.big-button:hover {
|
296 |
-
background-color: #c0392b;
|
297 |
-
}
|
298 |
-
</style>
|
299 |
-
"""
|
300 |
-
|
301 |
-
gr.HTML(custom_css) # ์ปค์คํ
CSS๋ฅผ ์ฝ์
|
302 |
-
|
303 |
-
# 2) ์ ๋ชฉ ๋ฐ ๊ฐ๋จ ์ค๋ช
|
304 |
-
gr.HTML(
|
305 |
"""
|
306 |
-
|
307 |
-
|
308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
</div>
|
310 |
"""
|
311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
elem_id="platform_option"
|
324 |
-
)
|
325 |
-
resolution_scale_slider = gr.Slider(
|
326 |
-
label="์ถ๋ ฅ ํด์๋ ์ถ์ ๋น์จ (0.1 ~ 1.0)",
|
327 |
-
minimum=0.1, maximum=1.0, step=0.1, value=1.0,
|
328 |
-
elem_id="resolution_scale"
|
329 |
-
)
|
330 |
-
frame_rate_slider = gr.Slider(
|
331 |
-
label="ํ๋ ์ ๋ ์ดํธ ๋ฐฐ์จ ์กฐ์ (0.1 ~ 1.0)",
|
332 |
-
minimum=0.1, maximum=1.0, step=0.1, value=1.0,
|
333 |
-
elem_id="frame_rate"
|
334 |
-
)
|
335 |
-
speed_slider = gr.Slider(
|
336 |
-
label="์ฌ์ ์๋ ์กฐ์ (0.5 ~ 5.0)",
|
337 |
-
minimum=0.5, maximum=5.0, step=0.1, value=1.0,
|
338 |
-
elem_id="speed_factor"
|
339 |
-
)
|
340 |
-
repeat_slider = gr.Slider(
|
341 |
-
label="GIF ๋ฐ๋ณต ํ์ (0: ๋ฌดํ๋ฐ๋ณต, 1~10: ๋ฐ๋ณต ํ์)",
|
342 |
-
minimum=0, maximum=10, step=1, value=0,
|
343 |
-
elem_id="repeat_count"
|
344 |
-
)
|
345 |
-
gr.HTML("</div>") # ์ข์ธก ์
๋ ฅ๋ถ ๋ฐ์ค ๋
|
346 |
-
|
347 |
-
gr.HTML("<div class='box'>") # ์ฐ์ธก ์ถ๋ ฅ๋ถ ๋ฐ์ค ์์
|
348 |
-
gr.HTML("<div class='emoji-title'>๐ ์ถ๋ ฅ๋ถ</div>")
|
349 |
-
gif_preview_output = gr.Image(label="GIF ๊ฒฐ๊ณผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ", elem_id="gif_preview")
|
350 |
-
download_output = gr.File(label="GIF ๋ค์ด๋ก๋", elem_id="gif_download")
|
351 |
-
gr.HTML("</div>") # ์ฐ์ธก ์ถ๋ ฅ๋ถ ๋ฐ์ค ๋
|
352 |
-
gr.HTML("</div>") # ์ฒซ ๋ฒ์งธ ์ค(row-container) ์ข
๋ฃ
|
353 |
-
|
354 |
-
# 4) ๋ ๋ฒ์งธ ์ค: ์ธ๋ค์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ
|
355 |
-
gr.HTML("<div class='single-box'>")
|
356 |
-
gr.HTML("<div class='emoji-title'>๐ ์์
์ธ๋ค์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ</div>")
|
357 |
-
start_thumb_output = gr.Image(label="์์ ์ธ๋ค์ผ", elem_id="start_thumb")
|
358 |
-
end_thumb_output = gr.Image(label="์ข
๋ฃ ์ธ๋ค์ผ", elem_id="end_thumb")
|
359 |
-
# GIF ์์ฑ ๋ฒํผ
|
360 |
-
generate_button = gr.Button("๐ก GIF ์์ฑํ๊ธฐ", elem_id="generate_btn", css="", variant="primary").style(full_width=False)
|
361 |
-
logs_output = gr.Textbox(label="์์
๋ก๊ทธ", lines=6)
|
362 |
-
gr.HTML("</div>")
|
363 |
-
|
364 |
-
# 5) ์ด๋ฒคํธ & ๋ก์ง ์ฐ๊ฒฐ
|
365 |
-
start_time = gr.Textbox(label="์์ ์๊ฐ (์: 00:00:05)", value="00:00:00")
|
366 |
-
end_time = gr.Textbox(label="์ข
๋ฃ ์๊ฐ (์: 00:00:10)", value="00:00:05")
|
367 |
-
|
368 |
-
# ํ๋ฉด์์๋ ํ์๋์ง ์์ง๋ง, ๋ก์ง ์ฒ๋ฆฌ๋ฅผ ์ํด ์์น๋ง ์ก์๋ (elem_id ์์ด)
|
369 |
-
# -> ํ์ํ๋ค๋ฉด style="display:none;"๋ก ์จ๊ฒจ๋ ๋จ.
|
370 |
start_time.change(
|
371 |
fn=update_thumbnails,
|
372 |
inputs=[video_input, start_time, end_time],
|
@@ -383,40 +373,38 @@ with gr.Blocks() as demo:
|
|
383 |
outputs=[start_thumb_output, end_thumb_output]
|
384 |
)
|
385 |
|
|
|
386 |
generate_button.click(
|
387 |
fn=process_video,
|
388 |
inputs=[
|
389 |
-
video_input,
|
390 |
-
start_time,
|
391 |
-
end_time,
|
392 |
-
platform_option,
|
393 |
-
frame_rate_slider,
|
394 |
-
speed_slider,
|
395 |
-
repeat_slider,
|
396 |
-
resolution_scale_slider
|
397 |
],
|
398 |
outputs=[
|
399 |
-
gif_preview_output,
|
400 |
-
download_output,
|
401 |
-
logs_output
|
402 |
]
|
403 |
)
|
404 |
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
</div>
|
418 |
-
"""
|
419 |
-
)
|
420 |
|
421 |
if __name__ == "__main__":
|
422 |
demo.launch()
|
|
|
64 |
width, height = clip.size
|
65 |
current_ratio = width / height
|
66 |
|
|
|
67 |
if current_ratio > target_ratio:
|
68 |
new_width = int(height * target_ratio)
|
69 |
new_height = height
|
|
|
76 |
def process_video(video,
|
77 |
start_time_str,
|
78 |
end_time_str,
|
79 |
+
platform_option,
|
80 |
+
frame_rate_factor,
|
81 |
speed_factor,
|
82 |
repeat_count,
|
83 |
+
resolution_scale):
|
84 |
"""
|
85 |
๋์์์ GIF๋ก ๋ณํํ๋ ํจ์
|
86 |
"""
|
|
|
89 |
|
90 |
add_log("[LOG 1] ๋น๋์ค ์
๋ก๋ ๋ฐ ์ฒ๋ฆฌ ์์")
|
91 |
|
92 |
+
# video ํ๋ผ๋ฏธํฐ์์ ํ์ผ ๊ฒฝ๋ก ์ถ์ถ
|
93 |
video_path = video if isinstance(video, str) else video.name
|
94 |
|
95 |
add_log("[LOG 2] ๋น๋์ค ๋ก๋ ์ค...")
|
|
|
120 |
add_log("[LOG 6] ์์ ์๋ฅด๊ธฐ ์์
์งํ...")
|
121 |
clip = input_video.subclip(start_sec, end_sec)
|
122 |
|
|
|
123 |
add_log(f"[LOG 7] ํ๋ซํผ ๋น์จ ์กฐ์ : {platform_option}")
|
124 |
clip = adjust_aspect_ratio(clip, platform_option)
|
125 |
|
126 |
+
# ์ถ๋ ฅ ํด์๋ ์ถ์
|
127 |
if abs(resolution_scale - 1.0) > 1e-3:
|
128 |
add_log(f"[LOG 7-1] ์ถ๋ ฅ ํด์๋ ์ถ์: {resolution_scale*100:.0f}%")
|
129 |
clip = clip.resize(resolution_scale)
|
|
|
133 |
add_log(f"[LOG 8] ์ฌ์์๋ {speed_factor}๋ฐฐ๋ก ์กฐ์ ์ค...")
|
134 |
clip = clip.fx(mp.vfx.speedx, speed_factor)
|
135 |
|
|
|
136 |
original_fps = clip.fps
|
137 |
target_fps = original_fps * frame_rate_factor
|
138 |
add_log(f"[LOG 9] ์ต์ข
์ถ๋ ฅ FPS: {target_fps:.2f} (์๋ณธ FPS: {original_fps})")
|
139 |
clip = clip.set_fps(target_fps)
|
140 |
|
141 |
+
# ๋ฐ๋ณต ํ์ ์ค์
|
142 |
add_log(f"[LOG 10] GIF ๋ฐ๋ณต ํ์ ์ค์ : {repeat_count} (0์ด๋ฉด ๋ฌดํ๋ฐ๋ณต)")
|
143 |
final_clip = clip
|
144 |
|
|
|
146 |
output_filename = f"temp_{uuid.uuid4().hex}.gif"
|
147 |
try:
|
148 |
loop_param = 0 if int(repeat_count) == 0 else int(repeat_count)
|
|
|
149 |
final_clip.write_gif(output_filename, fps=target_fps, loop=loop_param)
|
150 |
add_log(f"[LOG 12] GIF ์์ฑ ์๋ฃ! ํ์ผ๋ช
: {output_filename}, loop={loop_param}")
|
151 |
except Exception as e:
|
152 |
add_log(f"[ERROR] GIF ์์ฑ ์คํจ: {e}")
|
153 |
return None, None, "\n".join(global_logs)
|
154 |
|
|
|
155 |
return output_filename, output_filename, "\n".join(global_logs)
|
156 |
|
157 |
def update_thumbnails(video, start_time_str, end_time_str):
|
158 |
"""
|
159 |
+
์์/๋ ์ธ๋ค์ผ์ ์
๋ฐ์ดํธํ๊ธฐ ์ํ ํจ์
|
160 |
"""
|
161 |
video_path = video if isinstance(video, str) else video.name
|
162 |
|
|
|
183 |
|
184 |
return start_thumb, end_thumb
|
185 |
|
186 |
+
|
187 |
+
# ---------- ์ปค์คํ
CSS ----------
|
188 |
+
custom_css = """
|
189 |
+
/* ์ ์ฒด ๋ฐฐ๊ฒฝ */
|
190 |
+
body {
|
191 |
+
background-color: #fdfdfd;
|
192 |
+
margin: 0;
|
193 |
+
padding: 0;
|
194 |
+
font-family: 'Noto Sans KR', sans-serif;
|
195 |
+
}
|
196 |
+
|
197 |
+
/* ์๋จ ์ ๋ชฉ ์์ญ */
|
198 |
+
.title-container {
|
199 |
+
text-align: center;
|
200 |
+
margin-top: 20px;
|
201 |
+
margin-bottom: 15px;
|
202 |
+
}
|
203 |
+
.title-container h1 {
|
204 |
+
font-size: 2.2rem;
|
205 |
+
font-weight: bold;
|
206 |
+
color: #333;
|
207 |
+
}
|
208 |
+
.title-container h1 .emoji {
|
209 |
+
font-size: 1.8rem;
|
210 |
+
}
|
211 |
+
|
212 |
+
/* ์ฌ์ฉ ๊ฐ์ด๋ ์์ญ */
|
213 |
+
.guide-container {
|
214 |
+
text-align: center;
|
215 |
+
padding: 0 20px;
|
216 |
+
margin-bottom: 20px;
|
217 |
+
}
|
218 |
+
.guide-container p {
|
219 |
+
font-size: 1rem;
|
220 |
+
color: #444;
|
221 |
+
line-height: 1.5;
|
222 |
+
}
|
223 |
+
|
224 |
+
/* ํ๋ ์(ํ
๋๋ฆฌ) ๊ณตํต ์คํ์ผ */
|
225 |
+
.frame {
|
226 |
+
border: 2px solid #ccc;
|
227 |
+
border-radius: 15px;
|
228 |
+
padding: 15px;
|
229 |
+
margin: 10px;
|
230 |
+
background-color: #fff;
|
231 |
+
}
|
232 |
+
.frame h3 {
|
233 |
+
margin-top: 0;
|
234 |
+
}
|
235 |
+
|
236 |
+
/* ๊ทธ๋ฆฌ๋์ค ์ปดํฌ๋ํธ์ ๊ธฐ๋ณธ ์ฌ๋ฐฑ ๋ฑ์ ์ ๊ฑฐ/์กฐ์ */
|
237 |
+
.gradio-container {
|
238 |
+
padding: 0 !important;
|
239 |
+
}
|
240 |
+
|
241 |
+
/* ์
๋ ฅ๋ถ์ ์ถ๋ ฅ๋ถ ๊ฐ์ ๋ผ์ธ ๋ฐฐ์น */
|
242 |
+
.flex-row {
|
243 |
+
display: flex;
|
244 |
+
justify-content: space-around;
|
245 |
+
gap: 10px;
|
246 |
+
flex-wrap: wrap; /* ํ๋ฉด ์ข์ ๋ ์๋ ์ค๋ฐ๊ฟ */
|
247 |
+
}
|
248 |
+
.flex-column {
|
249 |
+
flex: 1;
|
250 |
+
min-width: 300px;
|
251 |
+
}
|
252 |
+
|
253 |
+
/* ํ์ํ ๋ฒํผ */
|
254 |
+
.custom-button {
|
255 |
+
border-radius: 25px !important;
|
256 |
+
background-color: #fa8072 !important;
|
257 |
+
color: #fff !important;
|
258 |
+
font-weight: bold !important;
|
259 |
+
}
|
260 |
+
|
261 |
+
/* ํ๋จ ์ธ๋ค์ผ ์์ญ์ ํ ์ค(์ ์ฒด ํญ)๋ก ๋ฐฐ๏ฟฝ๏ฟฝ */
|
262 |
+
.full-width-row {
|
263 |
+
display: flex;
|
264 |
+
justify-content: center;
|
265 |
+
margin-top: 10px;
|
266 |
+
gap: 20px;
|
267 |
+
flex-wrap: wrap; /* ํ๋ฉด ์ข์์ง๋ฉด ์ค๋ฐ๊ฟ */
|
268 |
+
}
|
269 |
+
"""
|
270 |
+
|
271 |
# ------------------------------
|
272 |
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ (Blocks)
|
273 |
# ------------------------------
|
274 |
+
with gr.Blocks(css=custom_css, theme=None) as demo:
|
275 |
+
# ์๋จ ์ ๋ชฉ
|
276 |
+
with gr.HTML():
|
277 |
+
html_title = """
|
278 |
+
<div class="title-container">
|
279 |
+
<h1><span class="emoji">๐๏ธ</span> ์์์ GIF๋ก ๋ณํํ๊ธฐ <span class="emoji">โจ</span></h1>
|
280 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
281 |
"""
|
282 |
+
print(html_title) # ์ด ์ถ๋ ฅ์ ์ค์ UI์๋ ์ํฅ ์ฃผ์ง ์์
|
283 |
+
gr.HTML(html_title)
|
284 |
+
|
285 |
+
# ์ฌ์ฉ ๊ฐ์ด๋
|
286 |
+
with gr.HTML():
|
287 |
+
html_guide = """
|
288 |
+
<div class="guide-container">
|
289 |
+
<p>๐ ์ํ๋ ์์์ ์
๋ก๋ํ๊ณ <br>
|
290 |
+
์ํ๋ ํด์๋/๋น์จ, ์๋, ํ๋ ์ ๋ฑ์ ์กฐ์ ํ์ธ์.<br>
|
291 |
+
<strong>GIF ์์ฑํ๊ธฐ</strong> ๋ฒํผ์ ๋๋ฅด๋ฉด ๋ณํ์ด ์๋ฃ๋ฉ๋๋ค.</p>
|
292 |
</div>
|
293 |
"""
|
294 |
+
print(html_guide)
|
295 |
+
gr.HTML(html_guide)
|
296 |
+
|
297 |
+
# 1) ์
๋ ฅ๋ถ - ์ถ๋ ฅ๋ถ (๊ฐ์ ํ์ ๋ฐฐ์น)
|
298 |
+
with gr.Row(elem_id="row-input-output"):
|
299 |
+
with gr.Column(elem_id="col-input", variant="panel"):
|
300 |
+
custom_input_html = """
|
301 |
+
<div class="frame">
|
302 |
+
<h3>์
๋ ฅ๋ถ ๐</h3>
|
303 |
+
</div>
|
304 |
+
"""
|
305 |
+
gr.HTML(custom_input_html)
|
306 |
+
|
307 |
+
video_input = gr.Video(label="์์ ์
๋ก๋")
|
308 |
+
platform_option = gr.Radio(
|
309 |
+
label="ํด์๋/๋น์จ ์ ํ",
|
310 |
+
choices=["์๋ณธ ์ ์ง", "์ ํ๋ธ (16:9)", "์ผ์ธ /๋ฆด์ค (9:16)", "์ ์ฌ๊ฐํ (1:1)", "์ธ์คํ๊ทธ๋จ (4:5)", "ํด๋์ (4:3)"],
|
311 |
+
value="์๋ณธ ์ ์ง"
|
312 |
+
)
|
313 |
+
resolution_scale_slider = gr.Slider(
|
314 |
+
label="์ถ๋ ฅ ํด์๋ ์ถ์ ๋น์จ (0.1 ~ 1.0)",
|
315 |
+
minimum=0.1, maximum=1.0, step=0.1, value=1.0
|
316 |
+
)
|
317 |
+
frame_rate_slider = gr.Slider(
|
318 |
+
label="ํ๋ ์ ๋ ์ดํธ ๋ฐฐ์จ ์กฐ์ (0.1 ~ 1.0)",
|
319 |
+
minimum=0.1, maximum=1.0, step=0.1, value=1.0
|
320 |
+
)
|
321 |
+
speed_slider = gr.Slider(
|
322 |
+
label="์ฌ์ ์๋ ์กฐ์ (0.5 ~ 5.0)",
|
323 |
+
minimum=0.5, maximum=5.0, step=0.1, value=1.0
|
324 |
+
)
|
325 |
+
repeat_slider = gr.Slider(
|
326 |
+
label="GIF ๋ฐ๋ณต ํ์ (0: ๋ฌดํ๋ฐ๋ณต, 1~10: ๋ฐ๋ณต ํ์)",
|
327 |
+
minimum=0, maximum=10, step=1, value=0
|
328 |
+
)
|
329 |
+
|
330 |
+
with gr.Column(elem_id="col-output", variant="panel"):
|
331 |
+
custom_output_html = """
|
332 |
+
<div class="frame">
|
333 |
+
<h3>์ถ๋ ฅ๋ถ ๐</h3>
|
334 |
+
</div>
|
335 |
+
"""
|
336 |
+
gr.HTML(custom_output_html)
|
337 |
+
|
338 |
+
gif_preview_output = gr.Image(label="GIF ๊ฒฐ๊ณผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ")
|
339 |
+
download_output = gr.File(label="GIF ๋ค์ด๋ก๋")
|
340 |
+
|
341 |
+
# 2) ์ธ๋ค์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ (๋ ๋ฒ์งธ ์ค ์ ์ฒด)
|
342 |
+
with gr.Row(elem_id="row-thumbnail"):
|
343 |
+
custom_thumb_html = """
|
344 |
+
<div class="frame">
|
345 |
+
<h3>์์
์ธ๋ค์ผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ๐</h3>
|
346 |
+
</div>
|
347 |
+
"""
|
348 |
+
gr.HTML(custom_thumb_html)
|
349 |
|
350 |
+
start_thumb_output = gr.Image(label="์์ ์ธ๋ค์ผ")
|
351 |
+
end_thumb_output = gr.Image(label="์ข
๋ฃ ์ธ๋ค์ผ")
|
352 |
+
generate_button = gr.Button("GIF ์์ฑํ๊ธฐ", elem_classes="custom-button")
|
353 |
+
logs_output = gr.Textbox(label="๋ก๊ทธ ์ถ๋ ฅ", lines=8)
|
354 |
+
|
355 |
+
# ์ด๋ฒคํธ ๋ก์ง
|
356 |
+
start_time = gr.Textbox(label="์์ ์๊ฐ (์: 00:00:05)", value="00:00:00", visible=False)
|
357 |
+
end_time = gr.Textbox(label="์ข
๋ฃ ์๊ฐ (์: 00:00:10)", value="00:00:05", visible=False)
|
358 |
+
|
359 |
+
# ์ธ๋ค์ผ ์
๋ฐ์ดํธ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
360 |
start_time.change(
|
361 |
fn=update_thumbnails,
|
362 |
inputs=[video_input, start_time, end_time],
|
|
|
373 |
outputs=[start_thumb_output, end_thumb_output]
|
374 |
)
|
375 |
|
376 |
+
# GIF ์์ฑ ๋ฒํผ ์ด๋ฒคํธ
|
377 |
generate_button.click(
|
378 |
fn=process_video,
|
379 |
inputs=[
|
380 |
+
video_input,
|
381 |
+
start_time,
|
382 |
+
end_time,
|
383 |
+
platform_option,
|
384 |
+
frame_rate_slider,
|
385 |
+
speed_slider,
|
386 |
+
repeat_slider,
|
387 |
+
resolution_scale_slider
|
388 |
],
|
389 |
outputs=[
|
390 |
+
gif_preview_output,
|
391 |
+
download_output,
|
392 |
+
logs_output
|
393 |
]
|
394 |
)
|
395 |
|
396 |
+
# ๊ฐ๋จํ ์ฌ์ฉ ๊ฐ์ด๋ (HTML๋ก ํ์, ์ค์ ์ฑ ๋ด๋ถ์ ํ์ํ๋ ค๋ฉด gr.HTML(...)์ ๋ฃ์ด๋ ๋จ)
|
397 |
+
guide_text = """
|
398 |
+
<h2>๊ฐ๋จ ์ฌ์ฉ ๊ฐ์ด๋ ๐</h2>
|
399 |
+
<ol>
|
400 |
+
<li>์์ ํ์ผ์ ์
๋ก๋ํ์ธ์.</li>
|
401 |
+
<li>์ํ๋ ํด์๋/๋น์จ ์ต์
์ ์ ํํ์ธ์.</li>
|
402 |
+
<li>์ถ๋ ฅ ํด์๋ ์ถ์ ๋น์จ, ํ๋ ์ ๋ ์ดํธ, ์ฌ์ ์๋, GIF ๋ฐ๋ณต ํ์๋ฅผ ์กฐ์ ํ์ธ์.</li>
|
403 |
+
<li><strong>GIF ์์ฑํ๊ธฐ</strong> ๋ฒํผ์ ๋๋ฅด๋ฉด ๋ณํ์ด ์๋ฃ๋ฉ๋๋ค.</li>
|
404 |
+
<li>์ถ๋ ฅ๋ GIF๋ฅผ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ก ํ์ธํ๊ณ , ๋ค์ด๋ก๋ํ ์ ์์ต๋๋ค.</li>
|
405 |
+
</ol>
|
406 |
+
"""
|
407 |
+
print(guide_text)
|
|
|
|
|
|
|
408 |
|
409 |
if __name__ == "__main__":
|
410 |
demo.launch()
|