Spaces:
Runtime error
Runtime error
Yuxuan Zhang commited on
Commit ·
905475d
1
Parent(s): 5dbb5a3
change
Browse files- README.md +1 -1
- app.py +21 -33
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -10,4 +10,4 @@ pinned: false
|
|
| 10 |
short_description: CogView4-6B supports Control features, allowing for multiple
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
| 10 |
short_description: CogView4-6B supports Control features, allowing for multiple
|
| 11 |
---
|
| 12 |
|
| 13 |
+
## CogView4-Control
|
app.py
CHANGED
|
@@ -163,11 +163,9 @@ def resize_image_to_valid_dimensions(image, min_size=512, max_size=2048, divisib
|
|
| 163 |
return resized_image
|
| 164 |
|
| 165 |
|
| 166 |
-
# Function to display image information
|
| 167 |
def show_image_info(image):
|
| 168 |
-
"""Display information about the uploaded image and its resized dimensions"""
|
| 169 |
if image is None:
|
| 170 |
-
return "
|
| 171 |
|
| 172 |
if not isinstance(image, Image.Image):
|
| 173 |
image = Image.fromarray(image)
|
|
@@ -176,7 +174,7 @@ def show_image_info(image):
|
|
| 176 |
resized_img = resize_image_to_valid_dimensions(image)
|
| 177 |
new_width, new_height = resized_img.size
|
| 178 |
|
| 179 |
-
return f"
|
| 180 |
|
| 181 |
|
| 182 |
def infer(prompt, control_image, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, num_images,
|
|
@@ -184,18 +182,14 @@ def infer(prompt, control_image, seed, randomize_seed, width, height, guidance_s
|
|
| 184 |
if randomize_seed:
|
| 185 |
seed = random.randint(0, 65536)
|
| 186 |
if control_image is None:
|
| 187 |
-
return None, seed, "
|
| 188 |
if not isinstance(control_image, Image.Image):
|
| 189 |
control_image = Image.fromarray(control_image)
|
| 190 |
|
| 191 |
-
|
|
|
|
|
|
|
| 192 |
|
| 193 |
-
control_image = resize_image_to_valid_dimensions(control_image)
|
| 194 |
-
actual_width, actual_height = control_image.size
|
| 195 |
-
print(f"控制图像尺寸调整为: {actual_width}x{actual_height}")
|
| 196 |
-
except Exception as e:
|
| 197 |
-
print(f"图像处理错误: {e}")
|
| 198 |
-
return None, seed, f"图像处理错误: {e}"
|
| 199 |
|
| 200 |
images = pipe(
|
| 201 |
prompt=prompt,
|
|
@@ -242,15 +236,15 @@ with gr.Blocks() as demo:
|
|
| 242 |
with gr.Column():
|
| 243 |
with gr.Row():
|
| 244 |
prompt = gr.Text(
|
| 245 |
-
label="
|
| 246 |
show_label=True,
|
| 247 |
max_lines=15,
|
| 248 |
-
placeholder="
|
| 249 |
container=True,
|
| 250 |
)
|
| 251 |
with gr.Row():
|
| 252 |
-
enhance = gr.Button("
|
| 253 |
-
run_button = gr.Button("
|
| 254 |
enhance.click(
|
| 255 |
convert_prompt,
|
| 256 |
inputs=[prompt],
|
|
@@ -274,13 +268,13 @@ with gr.Blocks() as demo:
|
|
| 274 |
outputs=[image_info]
|
| 275 |
)
|
| 276 |
with gr.Column(scale=1):
|
| 277 |
-
result = gr.Gallery(label="
|
| 278 |
-
error_output = gr.Text(label="
|
| 279 |
|
| 280 |
with gr.Row():
|
| 281 |
num_images = gr.Radio(
|
| 282 |
choices=[1, 2, 4],
|
| 283 |
-
label="
|
| 284 |
value=1
|
| 285 |
)
|
| 286 |
|
|
@@ -295,43 +289,38 @@ with gr.Blocks() as demo:
|
|
| 295 |
return gr.update(maximum=max_width)
|
| 296 |
|
| 297 |
|
| 298 |
-
with gr.Accordion("
|
| 299 |
seed = gr.Slider(
|
| 300 |
-
label="
|
| 301 |
minimum=0,
|
| 302 |
maximum=65536,
|
| 303 |
step=1,
|
| 304 |
value=0,
|
| 305 |
)
|
| 306 |
|
| 307 |
-
randomize_seed = gr.Checkbox(label="
|
| 308 |
|
| 309 |
with gr.Row():
|
| 310 |
width = gr.Slider(
|
| 311 |
-
label="
|
| 312 |
minimum=512,
|
| 313 |
maximum=2048,
|
| 314 |
step=32,
|
| 315 |
value=1024,
|
| 316 |
-
interactive=False,
|
| 317 |
-
info="宽度将根据上传的控制图像自动调整"
|
| 318 |
)
|
| 319 |
|
| 320 |
height = gr.Slider(
|
| 321 |
-
label="
|
| 322 |
minimum=512,
|
| 323 |
maximum=2048,
|
| 324 |
step=32,
|
| 325 |
value=1024,
|
| 326 |
-
interactive=False,
|
| 327 |
-
info="高度将根据上传的控制图像自动调整"
|
| 328 |
)
|
| 329 |
|
| 330 |
-
gr.Markdown("
|
| 331 |
-
|
| 332 |
with gr.Row():
|
| 333 |
guidance_scale = gr.Slider(
|
| 334 |
-
label="
|
| 335 |
minimum=0.0,
|
| 336 |
maximum=10.0,
|
| 337 |
step=0.1,
|
|
@@ -339,7 +328,7 @@ with gr.Blocks() as demo:
|
|
| 339 |
)
|
| 340 |
|
| 341 |
num_inference_steps = gr.Slider(
|
| 342 |
-
label="
|
| 343 |
minimum=10,
|
| 344 |
maximum=100,
|
| 345 |
step=1,
|
|
@@ -349,7 +338,6 @@ with gr.Blocks() as demo:
|
|
| 349 |
gr.Markdown("### Examples")
|
| 350 |
for i, pair in enumerate(example_pairs):
|
| 351 |
with gr.Row():
|
| 352 |
-
# Input image
|
| 353 |
ex_input_img = gr.Image(
|
| 354 |
value=pair["input"],
|
| 355 |
label="Input",
|
|
|
|
| 163 |
return resized_image
|
| 164 |
|
| 165 |
|
|
|
|
| 166 |
def show_image_info(image):
|
|
|
|
| 167 |
if image is None:
|
| 168 |
+
return "Must Upload a Image"
|
| 169 |
|
| 170 |
if not isinstance(image, Image.Image):
|
| 171 |
image = Image.fromarray(image)
|
|
|
|
| 174 |
resized_img = resize_image_to_valid_dimensions(image)
|
| 175 |
new_width, new_height = resized_img.size
|
| 176 |
|
| 177 |
+
return f"Original Size: {orig_width}x{orig_height}, Resize: {new_width}x{new_height}"
|
| 178 |
|
| 179 |
|
| 180 |
def infer(prompt, control_image, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, num_images,
|
|
|
|
| 182 |
if randomize_seed:
|
| 183 |
seed = random.randint(0, 65536)
|
| 184 |
if control_image is None:
|
| 185 |
+
return None, seed, "Must Upload an Image"
|
| 186 |
if not isinstance(control_image, Image.Image):
|
| 187 |
control_image = Image.fromarray(control_image)
|
| 188 |
|
| 189 |
+
control_image = resize_image_to_valid_dimensions(control_image)
|
| 190 |
+
actual_width, actual_height = control_image.size
|
| 191 |
+
print(f"Change Image Size to: {actual_width}x{actual_height}")
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
images = pipe(
|
| 195 |
prompt=prompt,
|
|
|
|
| 236 |
with gr.Column():
|
| 237 |
with gr.Row():
|
| 238 |
prompt = gr.Text(
|
| 239 |
+
label="Prompt",
|
| 240 |
show_label=True,
|
| 241 |
max_lines=15,
|
| 242 |
+
placeholder="Enter your prompt",
|
| 243 |
container=True,
|
| 244 |
)
|
| 245 |
with gr.Row():
|
| 246 |
+
enhance = gr.Button("Enhance Prompt (Strongly Suggest)", scale=1)
|
| 247 |
+
run_button = gr.Button("Run", scale=1)
|
| 248 |
enhance.click(
|
| 249 |
convert_prompt,
|
| 250 |
inputs=[prompt],
|
|
|
|
| 268 |
outputs=[image_info]
|
| 269 |
)
|
| 270 |
with gr.Column(scale=1):
|
| 271 |
+
result = gr.Gallery(label="Results", show_label=True, columns=2, rows=2)
|
| 272 |
+
error_output = gr.Text(label="Errors", visible=False)
|
| 273 |
|
| 274 |
with gr.Row():
|
| 275 |
num_images = gr.Radio(
|
| 276 |
choices=[1, 2, 4],
|
| 277 |
+
label="Number of Images",
|
| 278 |
value=1
|
| 279 |
)
|
| 280 |
|
|
|
|
| 289 |
return gr.update(maximum=max_width)
|
| 290 |
|
| 291 |
|
| 292 |
+
with gr.Accordion("Advanced Settings", open=False):
|
| 293 |
seed = gr.Slider(
|
| 294 |
+
label="Seed",
|
| 295 |
minimum=0,
|
| 296 |
maximum=65536,
|
| 297 |
step=1,
|
| 298 |
value=0,
|
| 299 |
)
|
| 300 |
|
| 301 |
+
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 302 |
|
| 303 |
with gr.Row():
|
| 304 |
width = gr.Slider(
|
| 305 |
+
label="Width",
|
| 306 |
minimum=512,
|
| 307 |
maximum=2048,
|
| 308 |
step=32,
|
| 309 |
value=1024,
|
|
|
|
|
|
|
| 310 |
)
|
| 311 |
|
| 312 |
height = gr.Slider(
|
| 313 |
+
label="Height",
|
| 314 |
minimum=512,
|
| 315 |
maximum=2048,
|
| 316 |
step=32,
|
| 317 |
value=1024,
|
|
|
|
|
|
|
| 318 |
)
|
| 319 |
|
| 320 |
+
gr.Markdown("Warning: The width and height must be divisible by 32 and Image size must not exceed 2^21 pixels.")
|
|
|
|
| 321 |
with gr.Row():
|
| 322 |
guidance_scale = gr.Slider(
|
| 323 |
+
label="Guidance scale",
|
| 324 |
minimum=0.0,
|
| 325 |
maximum=10.0,
|
| 326 |
step=0.1,
|
|
|
|
| 328 |
)
|
| 329 |
|
| 330 |
num_inference_steps = gr.Slider(
|
| 331 |
+
label="Number of inference steps",
|
| 332 |
minimum=10,
|
| 333 |
maximum=100,
|
| 334 |
step=1,
|
|
|
|
| 338 |
gr.Markdown("### Examples")
|
| 339 |
for i, pair in enumerate(example_pairs):
|
| 340 |
with gr.Row():
|
|
|
|
| 341 |
ex_input_img = gr.Image(
|
| 342 |
value=pair["input"],
|
| 343 |
label="Input",
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
accelerate>=1.3.0
|
| 2 |
sentencepiece>=0.2.0
|
| 3 |
-
git+https://github.com/
|
| 4 |
gradio>=5.15.0
|
| 5 |
transformers>=4.48.3
|
| 6 |
openai>=1.61.0
|
|
|
|
| 1 |
accelerate>=1.3.0
|
| 2 |
sentencepiece>=0.2.0
|
| 3 |
+
git+https://github.com/zRzRzRzRzRzRzR/diffusers.git@cogview4_control
|
| 4 |
gradio>=5.15.0
|
| 5 |
transformers>=4.48.3
|
| 6 |
openai>=1.61.0
|