Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -46,42 +46,68 @@ def split_image(input_image, num_splits=8):
|
|
| 46 |
|
| 47 |
@spaces.GPU
|
| 48 |
def infer(prompt, seed=1, randomize_seed=False, num_inference_steps=20, progress=gr.Progress()):
|
| 49 |
-
progress(0, desc="
|
| 50 |
-
# ν둬ννΈ
|
| 51 |
-
prompt_template = f"A
|
| 52 |
|
| 53 |
if randomize_seed:
|
| 54 |
seed = random.randint(0, MAX_SEED)
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
|
| 59 |
-
#
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
-
progress(0.
|
| 71 |
gif_name = f"{uuid.uuid4().hex}-flux.gif"
|
| 72 |
|
| 73 |
-
# GIF μμ±
|
| 74 |
-
frames = split_image(image, 8)
|
| 75 |
-
|
| 76 |
-
# νλ μ κ° μ νμ λΆλλ½κ² νκΈ° μν μ²λ¦¬
|
| 77 |
export_to_gif(
|
| 78 |
frames,
|
| 79 |
gif_name,
|
| 80 |
-
fps=8
|
| 81 |
)
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
progress(1.0, desc="Done!")
|
| 84 |
-
return gif_name,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
# ν둬ννΈ μμ λ λ λͺ
ννκ² μμ
|
| 87 |
examples = [
|
|
|
|
| 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:
|
| 54 |
seed = random.randint(0, MAX_SEED)
|
| 55 |
|
| 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):
|
| 100 |
+
"""νλ μλ€μ κ°λ‘λ‘ μ°κ²°νμ¬ λ―Έλ¦¬λ³΄κΈ° μ΄λ―Έμ§ μμ±"""
|
| 101 |
+
total_width = sum(frame.width for frame in frames)
|
| 102 |
+
max_height = max(frame.height for frame in frames)
|
| 103 |
+
|
| 104 |
+
preview = Image.new('RGB', (total_width, max_height))
|
| 105 |
+
x_offset = 0
|
| 106 |
+
for frame in frames:
|
| 107 |
+
preview.paste(frame, (x_offset, 0))
|
| 108 |
+
x_offset += frame.width
|
| 109 |
+
|
| 110 |
+
return preview
|
| 111 |
|
| 112 |
# ν둬ννΈ μμ λ λ λͺ
ννκ² μμ
|
| 113 |
examples = [
|