File size: 2,007 Bytes
3e2f324
 
 
 
 
b110be1
b080a94
19599cb
3e2f324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ec24a25
1fe1ea5
 
 
 
bcbe59e
 
 
 
1fe1ea5
 
 
 
 
b080a94
b110be1
7bb8a21
 
 
 
3e2f324
 
2341d95
1fe1ea5
 
2341d95
1fe1ea5
aef4fb0
3e2f324
 
2341d95
3e2f324
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from langchain.llms import HuggingFacePipeline
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline, AutoModelForSeq2SeqLM

from components import caption_chain, tag_chain
from components import pexels, utils
import os, gc
import gradio as gr

model = AutoModelForSeq2SeqLM.from_pretrained("declare-lab/flan-alpaca-gpt4-xl")
tokenizer = AutoTokenizer.from_pretrained("declare-lab/flan-alpaca-gpt4-xl")

pipe = pipeline(
    'text2text-generation',
    model=model,
    tokenizer= tokenizer,
    max_length=120
)

local_llm = HuggingFacePipeline(pipeline=pipe)

llm_chain = caption_chain.chain(llm=local_llm)
sum_llm_chain = tag_chain.chain(llm=local_llm)

pexels_api_key = os.getenv('pexels_api_key')

def pred(product_name, orientation):
    if orientation == "Shorts/Reels/TikTok (1080 x 1920)":
        orientation = "potrait"
        height = 1920
        width = 1080
    elif orientation == "Youtube Videos (1920 x 1080)":
        orientation = "landscape"
        height = 1080
        width = 1920
    else :
        orientation = "square"
        height = 1080
        width = 1080
    folder_name, sentences = pexels.generate_videos(product_name, pexels_api_key, orientation, height, width, llm_chain, sum_llm_chain)
    gc.collect()
    utils.combine_videos(folder_name)
    return ["\n".join(sentences), os.path.join(folder_name, "Final_Ad_Video.mp4")]
        #{'video':os.path.join(folder_name, "Final_Ad_Video.mp4"),
       # 'captions':"\n".join(sentences)}
    

with gr.Blocks() as demo:
    dimension = gr.Dropdown(
            ["Shorts/Reels/TikTok (1080 x 1920)", "Facebook/Youtube Videos (1920 x 1080)", "Square (1080 x 1080)"], 
            label="Video Dimension", info="Choose dimension"
        )
    product_name = gr.Textbox(label="product name")
    captions = gr.Textbox(label="captions")
    video = gr.Video()
    btn = gr.Button("Submit")
    btn.click(pred, inputs=[product_name, dimension], outputs=[captions,video])
    
    

demo.launch()