Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -16,14 +16,7 @@ if torch.cuda.is_available():
|
|
16 |
else:
|
17 |
torch_dtype = torch.float32
|
18 |
|
19 |
-
|
20 |
-
output_images = []
|
21 |
-
for i in range(num_splits):
|
22 |
-
left = i * 320
|
23 |
-
right = (i + 1) * 320
|
24 |
-
box = (left, 0, right, 320)
|
25 |
-
output_images.append(input_image.crop(box))
|
26 |
-
return output_images
|
27 |
|
28 |
# νμ΄νλΌμΈ μ΄κΈ°ν μμ
|
29 |
pipe = FluxPipeline.from_pretrained(
|
@@ -34,16 +27,36 @@ pipe = FluxPipeline.from_pretrained(
|
|
34 |
|
35 |
MAX_SEED = np.iinfo(np.int32).max
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
@spaces.GPU
|
38 |
def infer(prompt, seed=1, randomize_seed=False, num_inference_steps=20, progress=gr.Progress()):
|
39 |
progress(0, desc="Starting...")
|
40 |
-
|
|
|
|
|
41 |
if randomize_seed:
|
42 |
seed = random.randint(0, MAX_SEED)
|
43 |
|
44 |
progress(0.3, desc="Generating animation...")
|
45 |
generator = torch.Generator().manual_seed(seed)
|
46 |
|
|
|
47 |
image = pipe(
|
48 |
prompt=prompt_template,
|
49 |
num_inference_steps=num_inference_steps,
|
@@ -51,131 +64,70 @@ def infer(prompt, seed=1, randomize_seed=False, num_inference_steps=20, progress
|
|
51 |
generator=generator,
|
52 |
height=320,
|
53 |
width=2560,
|
54 |
-
guidance_scale=
|
55 |
).images[0]
|
56 |
|
57 |
progress(0.8, desc="Creating GIF...")
|
58 |
gif_name = f"{uuid.uuid4().hex}-flux.gif"
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
progress(1.0, desc="Done!")
|
62 |
return gif_name, image, seed
|
63 |
|
|
|
64 |
examples = [
|
65 |
-
"a red panda
|
66 |
-
"an astronaut
|
67 |
-
"a
|
68 |
-
"a robot
|
69 |
-
"a dragon
|
70 |
-
"a time
|
71 |
-
"a mermaid
|
72 |
-
"a steampunk clock
|
73 |
-
"a flower
|
74 |
-
"a wizard casting a
|
75 |
]
|
76 |
|
77 |
css = """
|
78 |
-
|
79 |
-
#col-container {
|
80 |
-
max-width: 1200px;
|
81 |
-
margin: auto;
|
82 |
-
padding: 20px;
|
83 |
-
background-color: #ffffff;
|
84 |
-
border-radius: 20px;
|
85 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
86 |
-
}
|
87 |
-
.gr-button {
|
88 |
-
background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
|
89 |
-
border: none;
|
90 |
-
color: white;
|
91 |
-
font-weight: 600;
|
92 |
-
border-radius: 8px;
|
93 |
-
}
|
94 |
-
.gr-button:hover {
|
95 |
-
background: linear-gradient(45deg, #4ECDC4, #FF6B6B);
|
96 |
-
transform: translateY(-2px);
|
97 |
-
transition: all 0.3s ease;
|
98 |
-
}
|
99 |
-
.gr-input {
|
100 |
-
border-radius: 8px;
|
101 |
-
border: 2px solid #e0e0e0;
|
102 |
-
}
|
103 |
-
.gr-accordion {
|
104 |
-
border-radius: 8px;
|
105 |
-
background-color: #f8f9fa;
|
106 |
-
}
|
107 |
|
108 |
-
/* Examples μ€νμΌ
|
109 |
-
.gr-
|
110 |
-
color: black !important;
|
111 |
-
background: transparent !important;
|
112 |
-
}
|
113 |
-
.gr-samples-table * {
|
114 |
-
color: black !important;
|
115 |
background: transparent !important;
|
116 |
}
|
117 |
-
.gr-
|
118 |
-
color: black !important;
|
119 |
-
background: transparent !important;
|
120 |
-
border: none !important;
|
121 |
-
box-shadow: none !important;
|
122 |
-
}
|
123 |
-
.gr-button.gr-button-lg:hover {
|
124 |
-
background: rgba(0,0,0,0.05) !important;
|
125 |
-
}
|
126 |
-
.gr-examples-table {
|
127 |
background: transparent !important;
|
128 |
}
|
129 |
.gr-examples {
|
130 |
background: transparent !important;
|
131 |
}
|
132 |
.gr-examples * {
|
133 |
-
color: black !important;
|
134 |
background: transparent !important;
|
135 |
}
|
136 |
-
.gr-
|
137 |
-
color: black !important;
|
138 |
background: transparent !important;
|
139 |
}
|
140 |
-
.gr-
|
141 |
-
color: black !important;
|
142 |
background: transparent !important;
|
143 |
}
|
144 |
-
|
145 |
-
#main-output {
|
146 |
-
height: 500px !important;
|
147 |
-
width: 100% !important;
|
148 |
-
}
|
149 |
-
#preview-output {
|
150 |
-
height: 200px !important;
|
151 |
-
width: auto !important;
|
152 |
-
}
|
153 |
-
#strip-output {
|
154 |
-
height: 150px !important;
|
155 |
-
width: auto !important;
|
156 |
-
}
|
157 |
-
/* νλ‘κ·Έλ μ€ λ° μ€νμΌ */
|
158 |
-
.progress-bar {
|
159 |
-
background-color: #f0f0f0;
|
160 |
-
border-radius: 10px;
|
161 |
-
padding: 3px;
|
162 |
-
}
|
163 |
-
.progress-bar-fill {
|
164 |
-
background: linear-gradient(45deg, #FF6B6B, #4ECDC4);
|
165 |
-
height: 20px;
|
166 |
-
border-radius: 7px;
|
167 |
-
transition: width 0.5s ease-out;
|
168 |
-
}
|
169 |
-
|
170 |
-
/* μΆκ°μ μΈ Examples μ€νμΌ */
|
171 |
-
.example-text {
|
172 |
-
color: black !important;
|
173 |
background: transparent !important;
|
|
|
|
|
174 |
}
|
175 |
-
.
|
176 |
-
background:
|
177 |
}
|
178 |
-
|
179 |
background: transparent !important;
|
180 |
}
|
181 |
"""
|
|
|
16 |
else:
|
17 |
torch_dtype = torch.float32
|
18 |
|
19 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# νμ΄νλΌμΈ μ΄κΈ°ν μμ
|
22 |
pipe = FluxPipeline.from_pretrained(
|
|
|
27 |
|
28 |
MAX_SEED = np.iinfo(np.int32).max
|
29 |
|
30 |
+
def split_image(input_image, num_splits=8):
|
31 |
+
width = input_image.width
|
32 |
+
height = input_image.height
|
33 |
+
split_width = width // num_splits
|
34 |
+
output_images = []
|
35 |
+
|
36 |
+
for i in range(num_splits):
|
37 |
+
left = i * split_width
|
38 |
+
right = (i + 1) * split_width
|
39 |
+
box = (left, 0, right, height)
|
40 |
+
split = input_image.crop(box)
|
41 |
+
# μ΄λ―Έμ§ νμ§ κ°μ μ μν μ²λ¦¬
|
42 |
+
split = split.convert('RGB')
|
43 |
+
output_images.append(split)
|
44 |
+
|
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="Starting...")
|
50 |
+
# ν둬ννΈ ν
νλ¦Ώ κ°μ
|
51 |
+
prompt_template = f"A sequence of 8 distinct consecutive frames showing {prompt}. Each frame should be clearly different and show progression of motion from left to right. High quality, detailed animation frames."
|
52 |
+
|
53 |
if randomize_seed:
|
54 |
seed = random.randint(0, MAX_SEED)
|
55 |
|
56 |
progress(0.3, desc="Generating animation...")
|
57 |
generator = torch.Generator().manual_seed(seed)
|
58 |
|
59 |
+
# μμ± λ§€κ°λ³μ μ‘°μ
|
60 |
image = pipe(
|
61 |
prompt=prompt_template,
|
62 |
num_inference_steps=num_inference_steps,
|
|
|
64 |
generator=generator,
|
65 |
height=320,
|
66 |
width=2560,
|
67 |
+
guidance_scale=8.5, # νμ§ ν₯μμ μν΄ μ½κ° μ¦κ°
|
68 |
).images[0]
|
69 |
|
70 |
progress(0.8, desc="Creating GIF...")
|
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, # fps μ¦κ°λ‘ λ λΆλλ¬μ΄ μ λλ©μ΄μ
|
81 |
+
)
|
82 |
|
83 |
progress(1.0, desc="Done!")
|
84 |
return gif_name, image, seed
|
85 |
|
86 |
+
# ν둬ννΈ μμ λ λ λͺ
ννκ² μμ
|
87 |
examples = [
|
88 |
+
"a red panda doing a complete backflip in the snow",
|
89 |
+
"an astronaut spinning in zero gravity on the moon",
|
90 |
+
"a butterfly emerging from its chrysalis and spreading its wings",
|
91 |
+
"a robot painting a masterpiece stroke by stroke",
|
92 |
+
"a dragon egg cracking open and a baby dragon emerging",
|
93 |
+
"a time portal opening and someone stepping through",
|
94 |
+
"a mermaid diving through bioluminescent waves",
|
95 |
+
"a steampunk clock's gears turning one complete cycle",
|
96 |
+
"a flower bud opening into full bloom",
|
97 |
+
"a wizard casting a spell with energy swirling around"
|
98 |
]
|
99 |
|
100 |
css = """
|
101 |
+
... (μ΄μ CSSμ λμΌ)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
+
/* Examples μμ μ€νμΌ μμ μ¬μ μ */
|
104 |
+
.gr-examples-parent {
|
|
|
|
|
|
|
|
|
|
|
105 |
background: transparent !important;
|
106 |
}
|
107 |
+
.gr-examples-parent > div {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
background: transparent !important;
|
109 |
}
|
110 |
.gr-examples {
|
111 |
background: transparent !important;
|
112 |
}
|
113 |
.gr-examples * {
|
|
|
114 |
background: transparent !important;
|
115 |
}
|
116 |
+
.gr-samples-table {
|
|
|
117 |
background: transparent !important;
|
118 |
}
|
119 |
+
.gr-samples-table > div {
|
|
|
120 |
background: transparent !important;
|
121 |
}
|
122 |
+
.gr-samples-table button {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
background: transparent !important;
|
124 |
+
border: none !important;
|
125 |
+
box-shadow: none !important;
|
126 |
}
|
127 |
+
.gr-samples-table button:hover {
|
128 |
+
background: rgba(0,0,0,0.05) !important;
|
129 |
}
|
130 |
+
div[class*="examples"] {
|
131 |
background: transparent !important;
|
132 |
}
|
133 |
"""
|