fantaxy commited on
Commit
2c08108
Β·
verified Β·
1 Parent(s): 49a1eca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -104
app.py CHANGED
@@ -16,14 +16,7 @@ if torch.cuda.is_available():
16
  else:
17
  torch_dtype = torch.float32
18
 
19
- def split_image(input_image, num_splits=8):
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
- prompt_template = f"A side by side 8 frame image showing high quality consecutive stills from a looped gif animation moving from left to right. The scene has motion. The stills are of {prompt}"
 
 
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=7.5,
55
  ).images[0]
56
 
57
  progress(0.8, desc="Creating GIF...")
58
  gif_name = f"{uuid.uuid4().hex}-flux.gif"
59
- export_to_gif(split_image(image, 8), gif_name, fps=6)
 
 
 
 
 
 
 
 
 
60
 
61
  progress(1.0, desc="Done!")
62
  return gif_name, image, seed
63
 
 
64
  examples = [
65
- "a red panda playing with a bamboo stick in the snow",
66
- "an astronaut breakdancing on the moon",
67
- "a magical butterfly transforming into sparkles",
68
- "a robot learning to paint like Van Gogh",
69
- "a dragon hatching from a crystal egg",
70
- "a time traveler stepping through a portal",
71
- "a mermaid playing with bioluminescent fish",
72
- "a steampunk clock with moving gears",
73
- "a flower blooming in timelapse",
74
- "a wizard casting a colorful spell"
75
  ]
76
 
77
  css = """
78
- footer {visibility: hidden}
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-samples-table {
110
- color: black !important;
111
- background: transparent !important;
112
- }
113
- .gr-samples-table * {
114
- color: black !important;
115
  background: transparent !important;
116
  }
117
- .gr-button.gr-button-lg {
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-prose {
137
- color: black !important;
138
  background: transparent !important;
139
  }
140
- .gr-prose * {
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
- .example-container {
176
- background: transparent !important;
177
  }
178
- .selectable-example {
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
  """