seawolf2357 commited on
Commit
3f176c4
โ€ข
1 Parent(s): 96b10cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -4
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
  # ๋น„๋””์˜ค ๋ฐฉํ–ฅ๊ณผ ํ•ด์ƒ๋„ ์„ค์ •