Update app.py
Browse files
app.py
CHANGED
@@ -1,115 +1,68 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
from
|
4 |
-
import tempfile
|
5 |
import logging
|
6 |
|
7 |
-
#
|
8 |
logging.basicConfig(level=logging.INFO)
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
duration = clip.duration
|
17 |
-
clip.close()
|
18 |
-
return f"Duration: {duration:.2f} seconds"
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
if not video:
|
24 |
-
return None, None
|
25 |
-
clip = VideoFileClip(video)
|
26 |
-
if start_time > clip.duration:
|
27 |
-
start_img = None
|
28 |
-
else:
|
29 |
-
start_frame = clip.get_frame(start_time)
|
30 |
-
start_img = Image.fromarray(start_frame)
|
31 |
-
if end_time > clip.duration:
|
32 |
-
end_img = None
|
33 |
-
else:
|
34 |
-
end_frame = clip.get_frame(end_time)
|
35 |
-
end_img = Image.fromarray(end_frame)
|
36 |
-
clip.close()
|
37 |
-
return start_img, end_img
|
38 |
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
end_time = clip.duration
|
50 |
-
subclip = clip.subclip(start_time, end_time)
|
51 |
-
# Apply playback speed
|
52 |
-
new_fps = subclip.fps * playback_speed
|
53 |
-
if new_fps <= 0:
|
54 |
-
new_fps = subclip.fps
|
55 |
-
subclip = subclip.set_fps(new_fps)
|
56 |
-
# Resize if resolution is changed
|
57 |
-
if resolution != subclip.size[0]:
|
58 |
-
ratio = resolution / subclip.size[0]
|
59 |
-
new_height = int(subclip.size[1] * ratio)
|
60 |
-
subclip = subclip.resize((resolution, new_height))
|
61 |
-
# Write GIF
|
62 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".gif") as temp:
|
63 |
-
gif_path = temp.name
|
64 |
-
subclip.write_gif(gif_path, fps=frame_rate, loop=int(loop_count))
|
65 |
-
# Read GIF for preview
|
66 |
-
with Image.open(gif_path) as img:
|
67 |
-
preview_frame = img.copy()
|
68 |
-
return preview_frame, gif_path
|
69 |
|
70 |
-
#
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
with gr.
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
loop_count = gr.Slider(0, 10, step=1, value=0, label="GIF Loop Count (0 for infinite)")
|
99 |
-
|
100 |
-
# GIF Generation button
|
101 |
-
generate_button = gr.Button("GIF ์์ฑ")
|
102 |
-
|
103 |
-
# GIF Preview and Download
|
104 |
-
gif_preview = gr.Image(label="GIF Preview")
|
105 |
-
gif_download = gr.File(label="Download GIF")
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
generate_button.click(generate_gif,
|
112 |
-
inputs=[video_input, start_time, end_time, resolution, frame_rate, playback_speed, loop_count],
|
113 |
-
outputs=[gif_preview, gif_download])
|
114 |
|
115 |
-
|
|
|
|
|
|
1 |
+
dimport gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
from datetime import datetime
|
|
|
4 |
import logging
|
5 |
|
6 |
+
# ๋ก๊ทธ ์ค์
|
7 |
logging.basicConfig(level=logging.INFO)
|
8 |
+
logger = logging.getLogger(__name__)
|
9 |
|
10 |
+
def analyze_reviews(file_path):
|
11 |
+
try:
|
12 |
+
logger.info("์์
ํ์ผ ์
๋ก๋ ์์")
|
13 |
+
# ์์
ํ์ผ ์ฝ๊ธฐ
|
14 |
+
df = pd.read_excel(file_path)
|
15 |
+
logger.info("์์
ํ์ผ ์ฝ๊ธฐ ์๋ฃ")
|
|
|
|
|
|
|
16 |
|
17 |
+
# ํ์ฌ ์ฐ๋
|
18 |
+
current_year = 2025
|
19 |
+
start_year = current_year - 3 # ์ต๊ทผ 3๋
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
logger.info(f"๋ฐ์ดํฐ ํํฐ๋ง: {start_year}๋
๋ถํฐ {current_year}๋
๊น์ง")
|
22 |
+
# B์ด์ด ๋ฆฌ๋ทฐ ๋ ์ง๋ผ๊ณ ๊ฐ์ ํ๊ณ , 'B' ์ด์ ์ด๋ฆ์ '๋ฆฌ๋ทฐ๋ ์ง'๋ก ๋ณ๊ฒฝ
|
23 |
+
if '๋ฆฌ๋ทฐ๋ ์ง' not in df.columns:
|
24 |
+
df.rename(columns={df.columns[1]: '๋ฆฌ๋ทฐ๋ ์ง'}, inplace=True)
|
25 |
+
|
26 |
+
# ๋ฆฌ๋ทฐ ๋ ์ง๋ฅผ datetime์ผ๋ก ๋ณํ
|
27 |
+
df['๋ฆฌ๋ทฐ๋ ์ง'] = pd.to_datetime(df['๋ฆฌ๋ทฐ๋ ์ง'], errors='coerce')
|
28 |
+
# ์ต๊ทผ 3๋
๋ฐ์ดํฐ ํํฐ๋ง
|
29 |
+
df_recent = df[df['๋ฆฌ๋ทฐ๋ ์ง'].dt.year >= start_year]
|
30 |
+
logger.info("์ต๊ทผ 3๋
๋ฐ์ดํฐ ํํฐ๋ง ์๋ฃ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
+
# ๋
์๋ณ ๋ฆฌ๋ทฐ ๊ฑด์ ๊ณ์ฐ
|
33 |
+
logger.info("์๋ณ ๋ฆฌ๋ทฐ ๊ฑด์ ์ง๊ณ ์์")
|
34 |
+
df_recent['๋
์'] = df_recent['๋ฆฌ๋ทฐ๋ ์ง'].dt.strftime('%Y-%m')
|
35 |
+
review_counts = df_recent.groupby('๋
์').size().reset_index(name='๋ฆฌ๋ทฐ๊ฑด์')
|
36 |
+
logger.info("์๋ณ ๋ฆฌ๋ทฐ ๊ฑด์ ์ง๊ณ ์๋ฃ")
|
37 |
+
|
38 |
+
# ์๋ก์ด ์ํธ์ ์ ์ฅ
|
39 |
+
logger.info("์๋ก์ด ์๏ฟฝ๏ฟฝ๏ฟฝ '์๋ณ ๋ฆฌ๋ทฐ๊ฑด์' ์์ฑ ์์")
|
40 |
+
with pd.ExcelWriter(file_path, engine='openpyxl', mode='a') as writer:
|
41 |
+
review_counts.to_excel(writer, sheet_name='์๋ณ ๋ฆฌ๋ทฐ๊ฑด์', index=False)
|
42 |
+
logger.info("์๋ก์ด ์ํธ '์๋ณ ๋ฆฌ๋ทฐ๊ฑด์' ์์ฑ ์๋ฃ")
|
43 |
+
|
44 |
+
return file_path
|
45 |
+
except Exception as e:
|
46 |
+
logger.error(f"๋ถ์ ์ค ์ค๋ฅ ๋ฐ์: {e}")
|
47 |
+
return None
|
48 |
+
|
49 |
+
# ๊ทธ๋ผ๋์ค ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
50 |
+
def main():
|
51 |
+
logger.info("๊ทธ๋ผ๋์ค ์ธํฐํ์ด์ค ์์")
|
52 |
+
with gr.Blocks() as demo:
|
53 |
+
gr.Markdown("### ๋ฆฌ๋ทฐ ๋ถ์ ์คํ์ด์ค")
|
54 |
+
with gr.Row():
|
55 |
+
file_input = gr.File(label="์๋ณธ ์์
ํ์ผ ์
๋ก๋", file_types=[".xlsx"])
|
56 |
+
file_output = gr.File(label="๋ถ์๋ ์์
ํ์ผ ๋ค์ด๋ก๋", type="filepath")
|
57 |
+
analyze_button = gr.Button("๋ถ์")
|
58 |
+
|
59 |
+
analyze_button.click(fn=analyze_reviews, inputs=file_input, outputs=file_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
+
demo.launch()
|
62 |
+
|
63 |
+
if __name__ == "__main__":
|
64 |
+
main()
|
|
|
|
|
|
|
65 |
|
66 |
+
gradio==4.44.1
|
67 |
+
pandas
|
68 |
+
openpyxl
|