seawolf2357 commited on
Commit
e73ed34
โ€ข
1 Parent(s): a9a06d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -36
app.py CHANGED
@@ -5,7 +5,6 @@ from components import caption_chain, tag_chain
5
  from components import pexels, utils
6
  import os, gc
7
  import gradio as gr
8
- import os
9
  from moviepy.editor import VideoFileClip, concatenate_videoclips
10
 
11
  # ๋ชจ๋ธ๊ณผ ํ† ํฌ๋‚˜์ด์ € ๋กœ๋“œ
@@ -30,38 +29,10 @@ sum_llm_chain = tag_chain.chain(llm=local_llm)
30
  # Pexels API ํ‚ค
31
  pexels_api_key = os.getenv('pexels_api_key')
32
 
33
-
34
- def pred(product_name, orientation):
35
- # ๊ธฐ์กด ์ฝ”๋“œ ์ƒ๋žต...
36
- folder_name, sentences = pexels.generate_videos(product_name, pexels_api_key, orientation, height, width, llm_chain, sum_llm_chain)
37
- video_files = [os.path.join(folder_name, f) for f in os.listdir(folder_name) if f.endswith('.mp4')]
38
-
39
- if not video_files: # ๋น„๋””์˜ค ํŒŒ์ผ์ด ์—†์œผ๋ฉด ๋ฉ”์‹œ์ง€ ๋ฐ˜ํ™˜
40
- return ["No videos were generated. Please check the input and try again.", ""]
41
-
42
- # ๋น„๋””์˜ค ํŒŒ์ผ ๊ฒฐํ•ฉ
43
- video_path = combine_videos(video_files, folder_name)
44
- if not video_path: # ๋น„๋””์˜ค ๊ฒฐํ•ฉ์— ์‹คํŒจํ•˜๋ฉด ๋ฉ”์‹œ์ง€ ๋ฐ˜ํ™˜
45
- return ["Failed to combine videos.", ""]
46
-
47
- return ["\n".join(sentences), video_path]
48
-
49
- def combine_videos(video_files, output_folder):
50
- if not video_files:
51
- print("No video files to combine.")
52
- return "" # ๋นˆ ๋ฌธ์ž์—ด ๋ฐ˜ํ™˜
53
-
54
- clips = [VideoFileClip(vf) for vf in video_files]
55
- final_clip = concatenate_videoclips(clips)
56
- output_path = os.path.join(output_folder, "final_video.mp4")
57
- final_clip.write_videofile(output_path)
58
- return output_path
59
-
60
- # ์˜ˆ์ธก ํ•จ์ˆ˜
61
  def pred(product_name, orientation):
62
  # ๋น„๋””์˜ค ๋ฐฉํ–ฅ๊ณผ ํ•ด์ƒ๋„ ์„ค์ •
63
  if orientation == "Shorts/Reels/TikTok (1080 x 1920)":
64
- orientation = "portrait" # ์˜คํƒ€ ์ˆ˜์ •
65
  height = 1920
66
  width = 1080
67
  elif orientation == "Youtube Videos (1920 x 1080)":
@@ -77,18 +48,32 @@ def pred(product_name, orientation):
77
  folder_name, sentences = pexels.generate_videos(product_name, pexels_api_key, orientation, height, width, llm_chain, sum_llm_chain)
78
  gc.collect()
79
 
80
- # ๋น„๋””์˜ค ํŒŒ์ผ์ด ์‹ค์ œ๋กœ ์ƒ์„ฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ
81
- if not sentences:
82
- return ["No videos generated. Please try again.", ""]
83
 
84
- # ๋น„๋””์˜ค ํŒŒ์ผ ๊ฒฐํ•ฉ
 
85
 
 
86
  video_path = combine_videos(video_files, folder_name)
87
- if not video_path or not os.path.exists(video_path):
88
  return ["Failed to combine videos.", ""]
89
-
90
  return ["\n".join(sentences), video_path]
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ • ๋ฐ ๋Ÿฐ์นญ
93
  with gr.Blocks() as demo:
94
  gr.Markdown(
 
5
  from components import pexels, utils
6
  import os, gc
7
  import gradio as gr
 
8
  from moviepy.editor import VideoFileClip, concatenate_videoclips
9
 
10
  # ๋ชจ๋ธ๊ณผ ํ† ํฌ๋‚˜์ด์ € ๋กœ๋“œ
 
29
  # Pexels API ํ‚ค
30
  pexels_api_key = os.getenv('pexels_api_key')
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  def pred(product_name, orientation):
33
  # ๋น„๋””์˜ค ๋ฐฉํ–ฅ๊ณผ ํ•ด์ƒ๋„ ์„ค์ •
34
  if orientation == "Shorts/Reels/TikTok (1080 x 1920)":
35
+ orientation = "portrait"
36
  height = 1920
37
  width = 1080
38
  elif orientation == "Youtube Videos (1920 x 1080)":
 
48
  folder_name, sentences = pexels.generate_videos(product_name, pexels_api_key, orientation, height, width, llm_chain, sum_llm_chain)
49
  gc.collect()
50
 
51
+ # ํด๋” ๋‚ด ๋น„๋””์˜ค ํŒŒ์ผ ๋ชฉ๋ก ์ƒ์„ฑ
52
+ video_files = [os.path.join(folder_name, f) for f in os.listdir(folder_name) if f.endswith('.mp4')]
 
53
 
54
+ if not video_files: # ๋น„๋””์˜ค ํŒŒ์ผ์ด ์—†์œผ๋ฉด ๋ฉ”์‹œ์ง€ ๋ฐ˜ํ™˜
55
+ return ["No videos were generated. Please check the input and try again.", ""]
56
 
57
+ # ๋น„๋””์˜ค ํŒŒ์ผ ๊ฒฐํ•ฉ
58
  video_path = combine_videos(video_files, folder_name)
59
+ if not video_path or not os.path.exists(video_path): # ๋น„๋””์˜ค ๊ฒฐํ•ฉ์— ์‹คํŒจํ•˜๋ฉด ๋ฉ”์‹œ์ง€ ๋ฐ˜ํ™˜
60
  return ["Failed to combine videos.", ""]
61
+
62
  return ["\n".join(sentences), video_path]
63
 
64
+
65
+ def combine_videos(video_files, output_folder):
66
+ if not video_files:
67
+ print("No video files to combine.")
68
+ return "" # ๋นˆ ๋ฌธ์ž์—ด ๋ฐ˜ํ™˜
69
+
70
+ clips = [VideoFileClip(vf) for vf in video_files]
71
+ final_clip = concatenate_videoclips(clips)
72
+ output_path = os.path.join(output_folder, "final_video.mp4")
73
+ final_clip.write_videofile(output_path)
74
+ return output_path
75
+
76
+
77
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ • ๋ฐ ๋Ÿฐ์นญ
78
  with gr.Blocks() as demo:
79
  gr.Markdown(