seawolf2357 commited on
Commit
97f24d6
·
verified ·
1 Parent(s): 7fc4411

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -0
app.py CHANGED
@@ -21,6 +21,9 @@ from funcs import (
21
  save_videos
22
  )
23
  from transformers import pipeline
 
 
 
24
 
25
  def download_model():
26
  REPO_ID = 'Doubiiu/DynamiCrafter_1024'
@@ -47,6 +50,23 @@ model = model.cuda()
47
  # 번역 모델 초기화
48
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  @spaces.GPU(duration=300)
51
  def infer(image, prompt, steps=50, cfg_scale=7.5, eta=1.0, fs=3, seed=123, video_length=2):
52
  # 한글 입력 감지 및 번역
@@ -105,6 +125,17 @@ def infer(image, prompt, steps=50, cfg_scale=7.5, eta=1.0, fs=3, seed=123, video
105
  save_videos(batch_samples, './', filenames=['output'], fps=save_fps)
106
  return video_path
107
 
 
 
 
 
 
 
 
 
 
 
 
108
  i2v_examples = [
109
  ['prompts/1024/astronaut04.png', 'a man in an astronaut suit playing a guitar', 30, 7.5, 1.0, 6, 123, 2],
110
  ]
@@ -145,4 +176,31 @@ with gr.Blocks(analytics_enabled=False, css=css) as dynamicrafter_iface:
145
  fn = infer
146
  )
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  dynamicrafter_iface.queue(max_size=12).launch(show_api=True)
 
21
  save_videos
22
  )
23
  from transformers import pipeline
24
+ from diffusers import FluxPipeline
25
+ from PIL import Image
26
+ import numpy as np
27
 
28
  def download_model():
29
  REPO_ID = 'Doubiiu/DynamiCrafter_1024'
 
50
  # 번역 모델 초기화
51
  translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
52
 
53
+ # FLUX 파이프라인 초기화
54
+ flux_pipe = FluxPipeline.from_pretrained("black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16)
55
+ flux_pipe.enable_model_cpu_offload()
56
+
57
+ def generate_image_from_text(prompt, seed=0):
58
+ generator = torch.Generator("cpu").manual_seed(seed)
59
+ image = flux_pipe(
60
+ prompt,
61
+ height=1024,
62
+ width=1024,
63
+ guidance_scale=3.5,
64
+ num_inference_steps=50,
65
+ max_sequence_length=512,
66
+ generator=generator
67
+ ).images[0]
68
+ return image
69
+
70
  @spaces.GPU(duration=300)
71
  def infer(image, prompt, steps=50, cfg_scale=7.5, eta=1.0, fs=3, seed=123, video_length=2):
72
  # 한글 입력 감지 및 번역
 
125
  save_videos(batch_samples, './', filenames=['output'], fps=save_fps)
126
  return video_path
127
 
128
+ @spaces.GPU(duration=300)
129
+ def infer_t2v(prompt, video_prompt, steps=50, cfg_scale=7.5, eta=1.0, fs=3, seed=123, video_length=2):
130
+ # 이미지 생성
131
+ image = generate_image_from_text(prompt, seed)
132
+
133
+ # 이미지를 numpy 배열로 변환
134
+ image_np = np.array(image)
135
+
136
+ # 비디오 생성을 위해 기존 infer 함수 호출
137
+ return infer(image_np, video_prompt, steps, cfg_scale, eta, fs, seed, video_length)
138
+
139
  i2v_examples = [
140
  ['prompts/1024/astronaut04.png', 'a man in an astronaut suit playing a guitar', 30, 7.5, 1.0, 6, 123, 2],
141
  ]
 
176
  fn = infer
177
  )
178
 
179
+ with gr.Tab(label='T2V'):
180
+ with gr.Column():
181
+ with gr.Row():
182
+ with gr.Column():
183
+ with gr.Row():
184
+ t2v_input_text = gr.Text(label='Image Generation Prompt')
185
+ with gr.Row():
186
+ t2v_video_prompt = gr.Text(label='Video Generation Prompt')
187
+ with gr.Row():
188
+ t2v_seed = gr.Slider(label='Random Seed', minimum=0, maximum=10000, step=1, value=123)
189
+ t2v_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label='ETA', value=1.0)
190
+ t2v_cfg_scale = gr.Slider(minimum=1.0, maximum=15.0, step=0.5, label='CFG Scale', value=7.5)
191
+ with gr.Row():
192
+ t2v_steps = gr.Slider(minimum=1, maximum=50, step=1, label="Sampling steps", value=30)
193
+ t2v_motion = gr.Slider(minimum=5, maximum=20, step=1, label="FPS", value=8)
194
+ with gr.Row():
195
+ t2v_video_length = gr.Slider(minimum=2, maximum=8, step=1, label="Video Length (seconds)", value=2)
196
+ t2v_end_btn = gr.Button("Generate")
197
+ with gr.Row():
198
+ t2v_output_video = gr.Video(label="Generated Video", autoplay=True, show_share_button=True)
199
+
200
+ t2v_end_btn.click(
201
+ inputs=[t2v_input_text, t2v_video_prompt, t2v_steps, t2v_cfg_scale, t2v_eta, t2v_motion, t2v_seed, t2v_video_length],
202
+ outputs=[t2v_output_video],
203
+ fn=infer_t2v
204
+ )
205
+
206
  dynamicrafter_iface.queue(max_size=12).launch(show_api=True)