Spaces:
Runtime error
Runtime error
seawolf2357
commited on
Commit
โข
3f176c4
1
Parent(s):
96b10cf
Update app.py
Browse files
app.py
CHANGED
@@ -1,13 +1,12 @@
|
|
1 |
-
|
2 |
-
from langchain_community.llms import HuggingFacePipeline # ์์ ๋ ์ํฌํธ
|
3 |
import torch
|
4 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
5 |
-
|
6 |
-
# ๋๋จธ์ง ์ปดํฌ๋ํธ ์ํฌํธ (์ฝ๋์ ๋ฐ๋ผ ๋ค๋ฆ)
|
7 |
from components import caption_chain, tag_chain
|
8 |
from components import pexels, utils
|
9 |
import os, gc
|
10 |
import gradio as gr
|
|
|
|
|
11 |
|
12 |
# ๋ชจ๋ธ๊ณผ ํ ํฌ๋์ด์ ๋ก๋
|
13 |
model = AutoModelForSeq2SeqLM.from_pretrained("declare-lab/flan-alpaca-large")
|
@@ -31,6 +30,33 @@ sum_llm_chain = tag_chain.chain(llm=local_llm)
|
|
31 |
# Pexels API ํค
|
32 |
pexels_api_key = os.getenv('pexels_api_key')
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
# ์์ธก ํจ์
|
35 |
def pred(product_name, orientation):
|
36 |
# ๋น๋์ค ๋ฐฉํฅ๊ณผ ํด์๋ ์ค์
|
|
|
1 |
+
from langchain_community.llms import HuggingFacePipeline
|
|
|
2 |
import torch
|
3 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
|
|
|
|
4 |
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 |
# ๋ชจ๋ธ๊ณผ ํ ํฌ๋์ด์ ๋ก๋
|
12 |
model = AutoModelForSeq2SeqLM.from_pretrained("declare-lab/flan-alpaca-large")
|
|
|
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 None
|
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 |
# ๋น๋์ค ๋ฐฉํฅ๊ณผ ํด์๋ ์ค์
|