Spaces:
Build error
Build error
Update app.py
Browse files
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
|
| 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(
|