kijeoung commited on
Commit
b3c0282
ยท
verified ยท
1 Parent(s): 8a89d94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -106
app.py CHANGED
@@ -1,115 +1,68 @@
1
- import gradio as gr
2
- from moviepy.editor import VideoFileClip
3
- from PIL import Image
4
- import tempfile
5
  import logging
6
 
7
- # Configure logging
8
  logging.basicConfig(level=logging.INFO)
 
9
 
10
- # Function to get video info
11
- def get_video_info(video):
12
- logging.info("Getting video info")
13
- if not video:
14
- return "No video uploaded."
15
- clip = VideoFileClip(video)
16
- duration = clip.duration
17
- clip.close()
18
- return f"Duration: {duration:.2f} seconds"
19
 
20
- # Function to generate thumbnails
21
- def generate_thumbnails(video, start_time, end_time):
22
- logging.info("Generating thumbnails")
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
- # Function to generate GIF
40
- def generate_gif(video, start_time, end_time, resolution, frame_rate, playback_speed, loop_count):
41
- logging.info("Generating GIF")
42
- if not video:
43
- return None, None
44
- clip = VideoFileClip(video)
45
- # Apply start and end times
46
- if start_time > clip.duration:
47
- start_time = 0
48
- if end_time > clip.duration:
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
- # Gradio interface
71
- with gr.Blocks() as demo:
72
- gr.Markdown("<h1>Video to GIF Converter</h1>")
73
-
74
- # Upload video
75
- video_input = gr.Video(label="Upload Video")
76
-
77
- # Button to get video info
78
- with gr.Row():
79
- get_info_button = gr.Button("Get Video Info")
80
- video_info = gr.Textbox(label="Video Information")
81
-
82
- # Display uploaded video
83
- video_output = gr.Video(label="Uploaded Video")
84
-
85
- # Inputs for start and end times
86
- start_time = gr.Number(label="Start Time (seconds)", value=0)
87
- end_time = gr.Number(label="End Time (seconds)", value=0)
88
-
89
- # Thumbnails
90
- with gr.Row():
91
- start_thumbnail = gr.Image(label="Start Thumbnail")
92
- end_thumbnail = gr.Image(label="End Thumbnail")
93
-
94
- # Sliders
95
- resolution = gr.Slider(100, 1920, step=100, value=1920, label="Resolution")
96
- frame_rate = gr.Slider(1, 30, step=1, value=10, label="Frame Rate")
97
- playback_speed = gr.Slider(0.1, 2.0, step=0.1, value=1.0, label="Playback Speed")
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
- # Button functions
108
- get_info_button.click(get_video_info, inputs=video_input, outputs=video_info)
109
- video_input.change(lambda x: x, inputs=video_input, outputs=video_output)
110
- video_input.change(generate_thumbnails, inputs=[video_input, start_time, end_time], outputs=[start_thumbnail, end_thumbnail])
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
- demo.launch()
 
 
 
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