seawolf2357 commited on
Commit
b59f0da
β€’
1 Parent(s): 513a44d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -39
app.py CHANGED
@@ -1,43 +1,22 @@
1
- import gradio as gr
2
- from moviepy.editor import ImageSequenceClip
3
- import tempfile
4
  import os
5
- import shutil # 이 뢀뢄을 μΆ”κ°€
6
 
 
 
7
 
8
- def images_to_video(image_files):
9
- # μž„μ‹œ 디렉터리 생성
10
- temp_dir = tempfile.mkdtemp()
11
-
12
- image_paths = []
13
- for i, image_file in enumerate(image_files):
14
- # μ—…λ‘œλ“œλœ νŒŒμΌμ„ μž„μ‹œ 파일둜 μ €μž₯
15
- temp_file_path = os.path.join(temp_dir, f"image_{i}.png")
16
- with open(temp_file_path, "wb") as f:
17
- f.write(image_file.read()) # λ°”μ΄νŠΈ 데이터λ₯Ό 파일둜 μ €μž₯
18
- image_paths.append(temp_file_path)
19
-
20
- # 이미지 μ‹œν€€μŠ€λ‘œλΆ€ν„° λΉ„λ””μ˜€ 클립 생성 및 기타 둜직...
21
 
22
-
23
- # 이미지 μ‹œν€€μŠ€λ‘œλΆ€ν„° λΉ„λ””μ˜€ 클립 생성 (각 μ΄λ―Έμ§€μ˜ 지속 μ‹œκ°„μ€ 2초)
24
- clip = ImageSequenceClip(image_paths, fps=0.5) # fps=0.5 => 각 μ΄λ―Έμ§€λŠ” 2초 λ™μ•ˆ λ³΄μž„
25
-
26
- # λΉ„λ””μ˜€ 파일 μ €μž₯
27
- output_video_path = os.path.join(temp_dir, "output.mp4")
28
- clip.write_videofile(output_video_path, fps=24) # 24fps둜 좜λ ₯ λΉ„λ””μ˜€ μ €μž₯
29
-
30
- # μƒμ„±λœ λΉ„λ””μ˜€ 파일 경둜 λ°˜ν™˜
31
- return output_video_path
32
-
33
- return image_paths # μ˜ˆμ‹œ λ°˜ν™˜κ°’, μ‹€μ œλ‘œλŠ” μƒμ„±λœ λΉ„λ””μ˜€ 파일 경둜λ₯Ό λ°˜ν™˜ν•΄μ•Ό 함
34
-
35
- # Gradio μΈν„°νŽ˜μ΄μŠ€ μ •μ˜
36
- with gr.Blocks() as demo:
37
- with gr.Row():
38
- file_input = gr.File(label="Upload images")
39
-
40
- video_output = gr.Video(label="Output video")
41
- file_input.change(images_to_video, inputs=file_input, outputs=video_output)
42
-
43
- demo.launch()
 
1
+ import openai
 
 
2
  import os
 
3
 
4
+ # OpenAI API ν‚€ μ„€μ •
5
+ openai.api_key = os.getenv("OPENAI_API_KEY") # ν™˜κ²½ λ³€μˆ˜μ—μ„œ API ν‚€λ₯Ό λΆˆλŸ¬μ˜΅λ‹ˆλ‹€.
6
 
7
+ def generate_keywords_with_gpt(scene_descriptions):
8
+ responses = []
9
+ for description in scene_descriptions:
10
+ response = openai.Completion.create(
11
+ engine="text-davinci-003", # ν˜Ήμ€ λ‹€λ₯Έ GPT λͺ¨λΈμ„ 선택할 수 μžˆμŠ΅λ‹ˆλ‹€.
12
+ prompt=f"Generate a representative keyword for the following scene description: {description}",
13
+ max_tokens=60, # ν•„μš”ν•œ 토큰 수λ₯Ό μ‘°μ ˆν•  수 μžˆμŠ΅λ‹ˆλ‹€.
14
+ temperature=0.7
15
+ )
16
+ responses.append(response.choices[0].text.strip())
17
+ return responses
 
 
18
 
19
+ # μ‚¬μš© μ˜ˆμ‹œ
20
+ scene_descriptions = ["Enter description for Scene 1", "Enter description for Scene 2"]
21
+ keywords = generate_keywords_with_gpt(scene_descriptions)
22
+ print(keywords)