Update app.py
Browse files
app.py
CHANGED
|
@@ -1,119 +1,71 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
-
|
| 4 |
-
|
|
|
|
| 5 |
|
| 6 |
-
def
|
| 7 |
"""
|
| 8 |
-
|
|
|
|
| 9 |
"""
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
return
|
| 15 |
|
| 16 |
-
def
|
| 17 |
"""
|
| 18 |
-
|
|
|
|
| 19 |
"""
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
return
|
| 25 |
|
| 26 |
-
def
|
| 27 |
"""
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
- frame_rate: 0์ด๋ฉด ์๋ณธ FPS, ๋ค๋ฅธ ๊ฐ์ด๋ฉด ํด๋น FPS๋ก ์ค์
|
| 31 |
-
- speed: ์์ ์ฌ์ ์๋ ๋ฐฐ์ (1.0์ด๋ฉด ์๋ณธ)
|
| 32 |
-
- loop_count: 0์ด๋ฉด ๋ฌดํ๋ฐ๋ณต, ๊ทธ ์ธ๋ ์ง์ ๋ ํ์ ๋ฐ๋ณต
|
| 33 |
"""
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
# ์๋ ์กฐ์ (๋ฐฐ์)
|
| 38 |
-
if speed != 1.0:
|
| 39 |
-
clip = clip.fx(mp.vfx.speedx, speed)
|
| 40 |
-
|
| 41 |
-
# ํด์๋ ์กฐ์
|
| 42 |
-
if resolution_scale != 1.0:
|
| 43 |
-
clip = clip.resize(resolution_scale)
|
| 44 |
-
|
| 45 |
-
# ํ๋ ์ ์๋ ์ค์ (0์ด๋ฉด ์๋ณธ FPS ์ฌ์ฉ)
|
| 46 |
-
target_fps = clip.fps if frame_rate == 0 else frame_rate
|
| 47 |
|
| 48 |
-
|
| 49 |
-
gif_path = "output.gif"
|
| 50 |
-
clip.write_gif(gif_path, fps=target_fps, loop=int(loop_count))
|
| 51 |
-
clip.close()
|
| 52 |
-
return gif_path
|
| 53 |
-
|
| 54 |
-
def update_video_info(video_path):
|
| 55 |
"""
|
| 56 |
-
|
| 57 |
-
์ข
๋ฃ ์๊ฐ์ ๋์์ ๊ธธ์ด๋ก ์๋ ์
๋ฐ์ดํธ๋ฉ๋๋ค.
|
| 58 |
"""
|
| 59 |
-
|
| 60 |
-
thumb_start = get_thumbnail(video_path, 0)
|
| 61 |
-
# ๋์์์ ๋ ํ๋ ์์ ์ฌ์์๊ฐ์ ๊ฐ๊น๊ฒ ์ถ์ถ
|
| 62 |
-
thumb_end = get_thumbnail(video_path, max(0, duration - 0.1))
|
| 63 |
-
info_text = f"์์ ๊ธธ์ด: {duration:.2f}์ด, FPS: {fps}"
|
| 64 |
-
return info_text, thumb_start, thumb_end, duration
|
| 65 |
|
| 66 |
-
with gr.Blocks() as demo:
|
| 67 |
-
gr.Markdown("#
|
| 68 |
|
| 69 |
with gr.Row():
|
| 70 |
-
|
| 71 |
-
video_input = gr.Video(label="๋์์ ์
๋ก๋")
|
| 72 |
-
video_info = gr.Textbox(label="๋์์ ์ ๋ณด", interactive=False)
|
| 73 |
-
with gr.Column():
|
| 74 |
-
video_output = gr.Video(label="์
๋ก๋๋ ์์")
|
| 75 |
|
|
|
|
|
|
|
|
|
|
| 76 |
with gr.Row():
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
end_thumbnail = gr.Image(label="์ข
๋ฃ ์๊ฐ ์ธ๋ค์ผ", type="pil")
|
| 83 |
|
| 84 |
with gr.Row():
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
loop_slider = gr.Slider(minimum=0, maximum=10, step=1, label="๋ฐ๋ณต ํ์ (0์ ๋ฌดํ ๋ฐ๋ณต)", value=0)
|
| 89 |
|
| 90 |
-
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
-
gif_output = gr.Image(label="์์ฑ๋ GIF ๋ฏธ๋ฆฌ๋ณด๊ธฐ", type="filepath")
|
| 93 |
-
gif_download = gr.File(label="์์ฑ๋ GIF ๋ค์ด๋ก๋")
|
| 94 |
-
|
| 95 |
-
# ๋์์ ์
๋ก๋ ์ ์๋ ์
๋ฐ์ดํธ: ๋์์ ์ ๋ณด, ์ธ๋ค์ผ, ์ข
๋ฃ ์๊ฐ ๊ธฐ๋ณธ๊ฐ(๋์์ ๊ธธ์ด)
|
| 96 |
-
def on_video_upload(video_path):
|
| 97 |
-
if video_path is None:
|
| 98 |
-
return gr.update(value=""), None, None, 0
|
| 99 |
-
info, thumb_start, thumb_end, duration = update_video_info(video_path)
|
| 100 |
-
return info, thumb_start, thumb_end, duration
|
| 101 |
-
|
| 102 |
-
video_input.upload(on_video_upload, inputs=video_input,
|
| 103 |
-
outputs=[video_info, start_thumbnail, end_thumbnail, end_time_input])
|
| 104 |
-
|
| 105 |
-
# GIF ์์ฑ ๋ฒํผ ํด๋ฆญ ์ ๋์์์ ์ ํ ๊ตฌ๊ฐ ๋ฐ ์ต์
์ ์ ์ฉํ์ฌ GIF๋ฅผ ์์ฑํฉ๋๋ค.
|
| 106 |
-
def process(video_path, start_time, end_time, resolution, frame_rate, speed, loop):
|
| 107 |
-
if video_path is None:
|
| 108 |
-
return None, None
|
| 109 |
-
gif_path = generate_gif(video_path, start_time, end_time, resolution, frame_rate, speed, int(loop))
|
| 110 |
-
return gif_path, gif_path
|
| 111 |
-
|
| 112 |
-
generate_button.click(process,
|
| 113 |
-
inputs=[video_input, start_time_input, end_time_input, resolution_slider, frame_rate_slider, speed_slider, loop_slider],
|
| 114 |
-
outputs=[gif_output, gif_download])
|
| 115 |
-
|
| 116 |
-
# ์
๋ก๋๋ ๋์์์ ์ค๋ฅธ์ชฝ ์ถ๋ ฅ์ฐฝ์ ๋ฏธ๋ฌ๋ง
|
| 117 |
-
video_input.change(lambda v: v, video_input, video_output)
|
| 118 |
-
|
| 119 |
demo.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
+
import pandas as pd
|
| 3 |
import gradio as gr
|
| 4 |
+
# ๋ง์ฝ OPENAI API๋ฅผ ์ง์ ์ฌ์ฉํด์ผ ํ ๊ฒฝ์ฐ, ์๋์ ๊ฐ์ด os.getenv๋ก ํ ํฐ์ ๊ฐ์ ธ์ต๋๋ค.
|
| 5 |
+
# import openai
|
| 6 |
+
# openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
|
| 8 |
+
def process_upload(file):
|
| 9 |
"""
|
| 10 |
+
์
๋ก๋๋ ์์
ํ์ผ์์ ์ฒซ 6๊ฐ ์ด(A~F)๋ง ์ฝ์ด ๋ฐํํฉ๋๋ค.
|
| 11 |
+
๋์์ ์๋ณธ ๋ฐ์ดํฐ๋ฅผ ์ํ(state)๋ก ์ ์ฅํฉ๋๋ค.
|
| 12 |
"""
|
| 13 |
+
if file is None:
|
| 14 |
+
return None, None, None
|
| 15 |
+
df = pd.read_excel(file.name)
|
| 16 |
+
df = df.iloc[:, :6] # A~F ์ด ์ ํ
|
| 17 |
+
return df, df, df
|
| 18 |
|
| 19 |
+
def sort_by_date(df):
|
| 20 |
"""
|
| 21 |
+
๋ฆฌ๋ทฐ๋ ์ง ์ปฌ๋ผ์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌํฉ๋๋ค.
|
| 22 |
+
์ถ๋ ฅํ๋ฉด 1: ์ต์ ๋ ์ง ์, ์ถ๋ ฅํ๋ฉด 2: ์ค๋๋ ๋ ์ง ์.
|
| 23 |
"""
|
| 24 |
+
# ๋ฆฌ๋ทฐ๋ ์ง ์ปฌ๋ผ์ datetime ํ์์ผ๋ก ๋ณํ (์กด์ฌํ์ง ์์ ๊ฒฝ์ฐ NaT ์ฒ๋ฆฌ)
|
| 25 |
+
df['๋ฆฌ๋ทฐ๋ ์ง'] = pd.to_datetime(df['๋ฆฌ๋ทฐ๋ ์ง'], errors='coerce')
|
| 26 |
+
df1 = df.sort_values(by='๋ฆฌ๋ทฐ๋ ์ง', ascending=False)
|
| 27 |
+
df2 = df.sort_values(by='๋ฆฌ๋ทฐ๋ ์ง', ascending=True)
|
| 28 |
+
return df1, df2
|
| 29 |
|
| 30 |
+
def sort_by_score(df):
|
| 31 |
"""
|
| 32 |
+
๋ฆฌ๋ทฐ์ ์ ์ปฌ๋ผ์ ๊ธฐ์ค์ผ๋ก ์ ๋ ฌํฉ๋๋ค.
|
| 33 |
+
์ถ๋ ฅํ๋ฉด 1: ๋์ ์ ์ ์, ์ถ๋ ฅํ๋ฉด 2: ๋ฎ์ ์ ์ ์.
|
|
|
|
|
|
|
|
|
|
| 34 |
"""
|
| 35 |
+
df1 = df.sort_values(by='๋ฆฌ๋ทฐ์ ์', ascending=False)
|
| 36 |
+
df2 = df.sort_values(by='๋ฆฌ๋ทฐ์ ์', ascending=True)
|
| 37 |
+
return df1, df2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
def reset_data(df):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
"""
|
| 41 |
+
์๋ณธ ๋ฐ์ดํฐ๋ฅผ ๊ทธ๋๋ก ๋ ํ๋ฉด์ ์ถ๋ ฅํฉ๋๋ค.
|
|
|
|
| 42 |
"""
|
| 43 |
+
return df, df
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
with gr.Blocks(title="์์
๋ถ์๊ธฐ") as demo:
|
| 46 |
+
gr.Markdown("# ์์
๋ถ์๊ธฐ")
|
| 47 |
|
| 48 |
with gr.Row():
|
| 49 |
+
file_input = gr.File(label="์์
ํ์ผ ์
๋ก๋", file_types=['.xlsx', '.xls'])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# ์ํ(state)๋ก ์
๋ก๋ํ ๋ฐ์ดํฐ๋ฅผ ์ ์ฅ
|
| 52 |
+
state = gr.State()
|
| 53 |
+
|
| 54 |
with gr.Row():
|
| 55 |
+
output1 = gr.Dataframe(label="์ถ๋ ฅํ๋ฉด 1")
|
| 56 |
+
output2 = gr.Dataframe(label="์ถ๋ ฅํ๋ฉด 2")
|
| 57 |
|
| 58 |
+
# ์์
ํ์ผ ์
๋ก๋ ์ process_upload ํจ์ ์คํ ํ ์๋ณธ ๋ฐ์ดํฐ์ ํจ๊ป ์ํ ์ ์ฅ
|
| 59 |
+
file_input.change(fn=process_upload, inputs=file_input, outputs=[output1, output2, state])
|
|
|
|
| 60 |
|
| 61 |
with gr.Row():
|
| 62 |
+
btn_date = gr.Button("๋ฆฌ๋ทฐ๋ ์ง")
|
| 63 |
+
btn_score = gr.Button("๋ฆฌ๋ทฐ์ ์")
|
| 64 |
+
btn_reset = gr.Button("์๋ณธ๋ณด๊ธฐ")
|
|
|
|
| 65 |
|
| 66 |
+
# ๋ฒํผ ํด๋ฆญ ์ ํด๋น ํจ์ ์คํ (์ ์ฅ๋ state๋ฅผ ์ฌ์ฉ)
|
| 67 |
+
btn_date.click(fn=sort_by_date, inputs=state, outputs=[output1, output2])
|
| 68 |
+
btn_score.click(fn=sort_by_score, inputs=state, outputs=[output1, output2])
|
| 69 |
+
btn_reset.click(fn=reset_data, inputs=state, outputs=[output1, output2])
|
| 70 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
demo.launch()
|