fantaxy commited on
Commit
365bdd8
Β·
verified Β·
1 Parent(s): e525d7c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -22
app.py CHANGED
@@ -45,9 +45,8 @@ def split_image(input_image, num_splits=8):
45
  return output_images
46
 
47
  @spaces.GPU
48
- def infer(prompt, seed=1, randomize_seed=False, num_inference_steps=20, progress=gr.Progress()):
49
- progress(0, desc="Initializing...")
50
- # 각 ν”„λ ˆμž„μ΄ 독립적이도둝 ν”„λ‘¬ν”„νŠΈ μˆ˜μ •
51
  prompt_template = f"A single clear frame of {prompt}. The scene should show only one moment of the action, high quality, detailed, centered composition."
52
 
53
  if randomize_seed:
@@ -56,44 +55,44 @@ def infer(prompt, seed=1, randomize_seed=False, num_inference_steps=20, progress
56
  frames = []
57
  total_frames = 8
58
 
59
- # 각 ν”„λ ˆμž„μ„ κ°œλ³„μ μœΌλ‘œ 생성
60
  for i in range(total_frames):
61
- progress((i / total_frames) * 0.8, desc=f"Generating frame {i+1}/{total_frames}")
 
62
  frame_prompt = f"{prompt_template} Frame {i+1} of sequence."
63
 
64
- # 각 ν”„λ ˆμž„μ— λŒ€ν•΄ κ°œλ³„ μ‹œλ“œ 생성
65
  frame_seed = seed + i
66
  generator = torch.Generator().manual_seed(frame_seed)
67
 
 
 
 
 
 
68
  frame = pipe(
69
  prompt=frame_prompt,
70
  num_inference_steps=num_inference_steps,
71
  num_images_per_prompt=1,
72
  generator=generator,
73
  height=320,
74
- width=320, # 단일 ν”„λ ˆμž„ 크기둜 μˆ˜μ •
75
  guidance_scale=7.5,
76
  ).images[0]
77
 
78
  frames.append(frame)
 
79
 
80
- progress(0.9, desc="Creating GIF...")
81
  gif_name = f"{uuid.uuid4().hex}-flux.gif"
82
 
83
- # GIF 생성
84
- export_to_gif(
85
- frames,
86
- gif_name,
87
- fps=8
88
- )
89
 
90
- # ν”„λ ˆμž„λ“€μ„ κ°€λ‘œλ‘œ μ—°κ²°ν•˜μ—¬ 미리보기 이미지 생성
91
  total_width = 320 * total_frames
92
  preview_image = Image.new('RGB', (total_width, 320))
93
  for i, frame in enumerate(frames):
94
  preview_image.paste(frame, (i * 320, 0))
95
 
96
- progress(1.0, desc="Done!")
97
  return gif_name, preview_image, seed
98
 
99
  def create_preview_image(frames):
@@ -156,23 +155,37 @@ div[class*="examples"] {
156
  background: transparent !important;
157
  }
158
 
159
- /* ν”„λ‘œκ·Έλ ˆμŠ€ λ°” μŠ€νƒ€μΌ κ°œμ„  */
160
  .progress-bar {
161
  background-color: #f0f0f0;
162
  border-radius: 10px;
163
- padding: 3px;
164
- margin: 10px 0;
 
165
  }
 
166
  .progress-bar-fill {
167
  background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
168
- height: 20px;
169
  border-radius: 7px;
170
  transition: width 0.3s ease-out;
 
171
  }
 
172
  .progress-text {
173
  color: black;
174
- font-weight: 500;
175
- margin-bottom: 5px;
 
 
 
 
 
 
 
 
 
 
176
  }
177
  """
178
 
 
45
  return output_images
46
 
47
  @spaces.GPU
48
+ def infer(prompt, seed=1, randomize_seed=False, num_inference_steps=20, progress=gr.Progress(track_tqdm=True)):
49
+ progress(0, desc="Starting...")
 
50
  prompt_template = f"A single clear frame of {prompt}. The scene should show only one moment of the action, high quality, detailed, centered composition."
51
 
52
  if randomize_seed:
 
55
  frames = []
56
  total_frames = 8
57
 
58
+ # μ§„ν–‰ 상황을 더 μ„Έλ°€ν•˜κ²Œ ν‘œμ‹œ
59
  for i in range(total_frames):
60
+ current_progress = (i / total_frames) * 0.8
61
+ progress(current_progress, desc=f"🎨 Generating frame {i+1}/{total_frames}")
62
  frame_prompt = f"{prompt_template} Frame {i+1} of sequence."
63
 
 
64
  frame_seed = seed + i
65
  generator = torch.Generator().manual_seed(frame_seed)
66
 
67
+ # 각 ν”„λ ˆμž„μ˜ 생성 단계도 ν‘œμ‹œ
68
+ for step in range(num_inference_steps):
69
+ step_progress = current_progress + (step / num_inference_steps) * (0.8 / total_frames)
70
+ progress(step_progress, desc=f"Frame {i+1}/{total_frames} - Step {step+1}/{num_inference_steps}")
71
+
72
  frame = pipe(
73
  prompt=frame_prompt,
74
  num_inference_steps=num_inference_steps,
75
  num_images_per_prompt=1,
76
  generator=generator,
77
  height=320,
78
+ width=320,
79
  guidance_scale=7.5,
80
  ).images[0]
81
 
82
  frames.append(frame)
83
+ progress((i + 1) / total_frames * 0.8, desc=f"βœ… Completed frame {i+1}/{total_frames}")
84
 
85
+ progress(0.9, desc="🎬 Creating GIF...")
86
  gif_name = f"{uuid.uuid4().hex}-flux.gif"
87
 
88
+ export_to_gif(frames, gif_name, fps=8)
 
 
 
 
 
89
 
 
90
  total_width = 320 * total_frames
91
  preview_image = Image.new('RGB', (total_width, 320))
92
  for i, frame in enumerate(frames):
93
  preview_image.paste(frame, (i * 320, 0))
94
 
95
+ progress(1.0, desc="✨ Done!")
96
  return gif_name, preview_image, seed
97
 
98
  def create_preview_image(frames):
 
155
  background: transparent !important;
156
  }
157
 
158
+ /* ν”„λ‘œκ·Έλ ˆμŠ€ λ°” μŠ€νƒ€μΌ κ°•ν™” */
159
  .progress-bar {
160
  background-color: #f0f0f0;
161
  border-radius: 10px;
162
+ padding: 5px;
163
+ margin: 15px 0;
164
+ box-shadow: 0 2px 5px rgba(0,0,0,0.1);
165
  }
166
+
167
  .progress-bar-fill {
168
  background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
169
+ height: 25px;
170
  border-radius: 7px;
171
  transition: width 0.3s ease-out;
172
+ box-shadow: 0 2px 5px rgba(0,0,0,0.1);
173
  }
174
+
175
  .progress-text {
176
  color: black;
177
+ font-weight: 600;
178
+ margin-bottom: 8px;
179
+ font-size: 1.1em;
180
+ }
181
+
182
+ /* μ§„ν–‰ μƒνƒœ ν…μŠ€νŠΈ μŠ€νƒ€μΌ */
183
+ .progress-label {
184
+ display: block;
185
+ text-align: center;
186
+ margin-top: 5px;
187
+ color: #666;
188
+ font-size: 0.9em;
189
  }
190
  """
191