Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,72 +1,69 @@
|
|
1 |
-
|
|
|
2 |
import torch
|
3 |
-
from transformers import AutoTokenizer,
|
4 |
|
|
|
5 |
from components import caption_chain, tag_chain
|
6 |
from components import pexels, utils
|
7 |
import os, gc
|
8 |
import gradio as gr
|
9 |
|
10 |
-
|
11 |
-
# model = AutoModelForSeq2SeqLM.from_pretrained("declare-lab/flan-alpaca-gpt4-xl")
|
12 |
-
# tokenizer = AutoTokenizer.from_pretrained("declare-lab/flan-alpaca-gpt4-xl")
|
13 |
-
|
14 |
model = AutoModelForSeq2SeqLM.from_pretrained("declare-lab/flan-alpaca-large")
|
15 |
tokenizer = AutoTokenizer.from_pretrained("declare-lab/flan-alpaca-large")
|
16 |
|
|
|
17 |
pipe = pipeline(
|
18 |
'text2text-generation',
|
19 |
model=model,
|
20 |
-
tokenizer=
|
21 |
max_length=120
|
22 |
)
|
23 |
|
|
|
24 |
local_llm = HuggingFacePipeline(pipeline=pipe)
|
25 |
|
|
|
26 |
llm_chain = caption_chain.chain(llm=local_llm)
|
27 |
sum_llm_chain = tag_chain.chain(llm=local_llm)
|
28 |
|
|
|
29 |
pexels_api_key = os.getenv('pexels_api_key')
|
30 |
|
|
|
31 |
def pred(product_name, orientation):
|
|
|
32 |
if orientation == "Shorts/Reels/TikTok (1080 x 1920)":
|
33 |
-
orientation = "
|
34 |
height = 1920
|
35 |
width = 1080
|
36 |
elif orientation == "Youtube Videos (1920 x 1080)":
|
37 |
orientation = "landscape"
|
38 |
height = 1080
|
39 |
width = 1920
|
40 |
-
else
|
41 |
orientation = "square"
|
42 |
height = 1080
|
43 |
width = 1080
|
|
|
|
|
44 |
folder_name, sentences = pexels.generate_videos(product_name, pexels_api_key, orientation, height, width, llm_chain, sum_llm_chain)
|
45 |
gc.collect()
|
46 |
-
utils.combine_videos(folder_name)
|
47 |
-
return ["\n".join(sentences), os.path.join(folder_name, "Final_Ad_Video.mp4")]
|
48 |
-
#{'video':os.path.join(folder_name, "Final_Ad_Video.mp4"),
|
49 |
-
# 'captions':"\n".join(sentences)}
|
50 |
-
|
51 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
with gr.Blocks() as demo:
|
53 |
-
|
54 |
-
"""
|
55 |
-
# Ads Generator
|
56 |
-
Create video ads based on your product name using AI
|
57 |
-
### Note : the video generation takes about 2-4 minutes
|
58 |
-
"""
|
59 |
-
)
|
60 |
-
dimension = gr.Dropdown(
|
61 |
-
["Shorts/Reels/TikTok (1080 x 1920)", "Facebook/Youtube Videos (1920 x 1080)", "Square (1080 x 1080)"],
|
62 |
-
label="Video Dimension", info="Choose dimension"
|
63 |
-
)
|
64 |
-
product_name = gr.Textbox(label="product name")
|
65 |
-
captions = gr.Textbox(label="captions")
|
66 |
-
video = gr.Video()
|
67 |
-
btn = gr.Button("Submit")
|
68 |
-
btn.click(pred, inputs=[product_name, dimension], outputs=[captions,video])
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
demo.launch()
|
|
|
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")
|
14 |
tokenizer = AutoTokenizer.from_pretrained("declare-lab/flan-alpaca-large")
|
15 |
|
16 |
+
# ํ์ดํ๋ผ์ธ ์ค์
|
17 |
pipe = pipeline(
|
18 |
'text2text-generation',
|
19 |
model=model,
|
20 |
+
tokenizer=tokenizer,
|
21 |
max_length=120
|
22 |
)
|
23 |
|
24 |
+
# HuggingFacePipeline์ ์ฌ์ฉํ์ฌ LLM ์ด๊ธฐํ
|
25 |
local_llm = HuggingFacePipeline(pipeline=pipe)
|
26 |
|
27 |
+
# ์ฒด์ธ ๊ตฌ์ฑ
|
28 |
llm_chain = caption_chain.chain(llm=local_llm)
|
29 |
sum_llm_chain = tag_chain.chain(llm=local_llm)
|
30 |
|
31 |
+
# Pexels API ํค
|
32 |
pexels_api_key = os.getenv('pexels_api_key')
|
33 |
|
34 |
+
# ์์ธก ํจ์
|
35 |
def pred(product_name, orientation):
|
36 |
+
# ๋น๋์ค ๋ฐฉํฅ๊ณผ ํด์๋ ์ค์
|
37 |
if orientation == "Shorts/Reels/TikTok (1080 x 1920)":
|
38 |
+
orientation = "portrait" # ์คํ ์์
|
39 |
height = 1920
|
40 |
width = 1080
|
41 |
elif orientation == "Youtube Videos (1920 x 1080)":
|
42 |
orientation = "landscape"
|
43 |
height = 1080
|
44 |
width = 1920
|
45 |
+
else:
|
46 |
orientation = "square"
|
47 |
height = 1080
|
48 |
width = 1080
|
49 |
+
|
50 |
+
# ๋น๋์ค ์์ฑ ๋ฐ ๋ฌธ์ฅ ์ถ์ถ
|
51 |
folder_name, sentences = pexels.generate_videos(product_name, pexels_api_key, orientation, height, width, llm_chain, sum_llm_chain)
|
52 |
gc.collect()
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
+
# ๋น๋์ค ํ์ผ์ด ์ค์ ๋ก ์์ฑ๋์๋์ง ํ์ธ
|
55 |
+
if not sentences:
|
56 |
+
return ["No videos generated. Please try again.", ""]
|
57 |
+
|
58 |
+
# ๋น๋์ค ํ์ผ ๊ฒฐํฉ
|
59 |
+
video_path = utils.combine_videos(folder_name)
|
60 |
+
if not os.path.exists(video_path):
|
61 |
+
return ["Failed to combine videos.", ""]
|
62 |
+
|
63 |
+
return ["\n".join(sentences), video_path]
|
64 |
+
|
65 |
+
# Gradio ์ธํฐํ์ด์ค ์ค์ ๋ฐ ๋ฐ์นญ
|
66 |
with gr.Blocks() as demo:
|
67 |
+
# ์๋ต๋ Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
+
demo.launch()
|
|
|
|