Spaces:
Runtime error
Runtime error
Commit
·
69bb68e
1
Parent(s):
37a9a0b
Rotate! (#1)
Browse files- Rotate! (18cd14b5dba32210a65fda4e4e0613d44c1fdfa3)
- Update requirements.txt (bcd94f7ae753b1c8c647602af9544ba9c08e9953)
Co-authored-by: Apolinário from multimodal AI art <[email protected]>
- app.py +24 -8
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -287,6 +287,12 @@ def call(
|
|
| 287 |
|
| 288 |
NEGATIVE_PROMPTS = "text, watermark, low-quality, signature, moiré pattern, downsampling, aliasing, distorted, blurry, glossy, blur, jpeg artifacts, compression artifacts, poorly drawn, low-resolution, bad, distortion, twisted, excessive, exaggerated pose, exaggerated limbs, grainy, symmetrical, duplicate, error, pattern, beginner, pixelated, fake, hyper, glitch, overexposed, high-contrast, bad-contrast"
|
| 289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
def simple_call(prompt1, prompt2):
|
| 291 |
generator = [torch.Generator(device="cuda").manual_seed(5)]
|
| 292 |
res = call(
|
|
@@ -304,10 +310,12 @@ def simple_call(prompt1, prompt2):
|
|
| 304 |
generator=generator
|
| 305 |
)
|
| 306 |
image1 = res.images[0]
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
|
|
|
|
|
|
| 311 |
gr.Markdown(
|
| 312 |
'''
|
| 313 |
<center>
|
|
@@ -325,7 +333,7 @@ with gr.Blocks() as app:
|
|
| 325 |
'''
|
| 326 |
)
|
| 327 |
|
| 328 |
-
|
| 329 |
with gr.Row():
|
| 330 |
with gr.Column():
|
| 331 |
prompt1 = gr.Textbox(label="Prompt 1")
|
|
@@ -333,13 +341,21 @@ with gr.Blocks() as app:
|
|
| 333 |
run_btn = gr.Button("Run")
|
| 334 |
|
| 335 |
with gr.Column():
|
| 336 |
-
result_image1 = gr.Image(label="Output
|
| 337 |
-
|
|
|
|
| 338 |
|
| 339 |
run_btn.click(
|
| 340 |
simple_call,
|
| 341 |
inputs=[prompt1, prompt2],
|
| 342 |
-
outputs=[result_image1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
)
|
| 344 |
|
| 345 |
app.queue(max_size=20)
|
|
|
|
| 287 |
|
| 288 |
NEGATIVE_PROMPTS = "text, watermark, low-quality, signature, moiré pattern, downsampling, aliasing, distorted, blurry, glossy, blur, jpeg artifacts, compression artifacts, poorly drawn, low-resolution, bad, distortion, twisted, excessive, exaggerated pose, exaggerated limbs, grainy, symmetrical, duplicate, error, pattern, beginner, pixelated, fake, hyper, glitch, overexposed, high-contrast, bad-contrast"
|
| 289 |
|
| 290 |
+
def rotate_output(has_flipped):
|
| 291 |
+
if(has_flipped):
|
| 292 |
+
return gr.Image(elem_classes="not_rotated"), gr.Button("Rotate to see prompt 2!"), not has_flipped
|
| 293 |
+
else:
|
| 294 |
+
return gr.Image(elem_classes="rotated"), gr.Button("Rotate to see prompt 1!"), not has_flipped
|
| 295 |
+
|
| 296 |
def simple_call(prompt1, prompt2):
|
| 297 |
generator = [torch.Generator(device="cuda").manual_seed(5)]
|
| 298 |
res = call(
|
|
|
|
| 310 |
generator=generator
|
| 311 |
)
|
| 312 |
image1 = res.images[0]
|
| 313 |
+
return image1
|
| 314 |
+
css = '''
|
| 315 |
+
#result_image{ transition: transform 2s ease-in-out }
|
| 316 |
+
#result_image.rotated{transform: rotate(180deg)}
|
| 317 |
+
'''
|
| 318 |
+
with gr.Blocks(css=css) as app:
|
| 319 |
gr.Markdown(
|
| 320 |
'''
|
| 321 |
<center>
|
|
|
|
| 333 |
'''
|
| 334 |
)
|
| 335 |
|
| 336 |
+
has_flipped = gr.State(value=False)
|
| 337 |
with gr.Row():
|
| 338 |
with gr.Column():
|
| 339 |
prompt1 = gr.Textbox(label="Prompt 1")
|
|
|
|
| 341 |
run_btn = gr.Button("Run")
|
| 342 |
|
| 343 |
with gr.Column():
|
| 344 |
+
result_image1 = gr.Image(label="Output", elem_id="result_image", elem_classes="not_rotated")
|
| 345 |
+
rotate_button = gr.Button("Rotate to see prompt 2!")
|
| 346 |
+
|
| 347 |
|
| 348 |
run_btn.click(
|
| 349 |
simple_call,
|
| 350 |
inputs=[prompt1, prompt2],
|
| 351 |
+
outputs=[result_image1]
|
| 352 |
+
)
|
| 353 |
+
rotate_button.click(
|
| 354 |
+
rotate_output,
|
| 355 |
+
inputs=[has_flipped],
|
| 356 |
+
outputs=[result_image1, rotate_button, has_flipped],
|
| 357 |
+
queue=False,
|
| 358 |
+
show_progress=False
|
| 359 |
)
|
| 360 |
|
| 361 |
app.queue(max_size=20)
|
requirements.txt
CHANGED
|
@@ -3,6 +3,6 @@ transformers
|
|
| 3 |
accelerate
|
| 4 |
torch
|
| 5 |
xformers
|
| 6 |
-
gradio
|
| 7 |
Pillow
|
| 8 |
filelock
|
|
|
|
| 3 |
accelerate
|
| 4 |
torch
|
| 5 |
xformers
|
| 6 |
+
https://gradio-builds.s3.amazonaws.com/e7abb0c95d7a0cd37048170982018d5f440a5134/gradio-3.44.4-py3-none-any.whl
|
| 7 |
Pillow
|
| 8 |
filelock
|