Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
|
| 4 |
import torch
|
| 5 |
from PIL import Image, ImageOps
|
| 6 |
import gradio as gr
|
|
|
|
| 7 |
|
| 8 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
| 9 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
|
@@ -297,7 +298,7 @@ def rotate_output(has_flipped):
|
|
| 297 |
else:
|
| 298 |
return gr.Image(elem_classes="rotated"), gr.Button("Rotate to see prompt 1!"), not has_flipped
|
| 299 |
|
| 300 |
-
def simple_call(prompt1, prompt2):
|
| 301 |
generator = [torch.Generator(device="cuda").manual_seed(5)]
|
| 302 |
res = call(
|
| 303 |
pipe,
|
|
@@ -314,12 +315,20 @@ def simple_call(prompt1, prompt2):
|
|
| 314 |
generator=generator
|
| 315 |
)
|
| 316 |
image1 = res.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 317 |
return image1
|
| 318 |
css = '''
|
| 319 |
#result_image{ transition: transform 2s ease-in-out }
|
| 320 |
#result_image.rotated{transform: rotate(180deg)}
|
| 321 |
'''
|
| 322 |
-
with gr.Blocks(
|
| 323 |
gr.Markdown(
|
| 324 |
'''
|
| 325 |
<center>
|
|
@@ -362,7 +371,13 @@ with gr.Blocks(css=css) as app:
|
|
| 362 |
show_progress=False
|
| 363 |
)
|
| 364 |
|
| 365 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
|
| 367 |
if __name__ == "__main__":
|
| 368 |
-
|
|
|
|
| 4 |
import torch
|
| 5 |
from PIL import Image, ImageOps
|
| 6 |
import gradio as gr
|
| 7 |
+
import user_history
|
| 8 |
|
| 9 |
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
|
| 10 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
|
|
|
| 298 |
else:
|
| 299 |
return gr.Image(elem_classes="rotated"), gr.Button("Rotate to see prompt 1!"), not has_flipped
|
| 300 |
|
| 301 |
+
def simple_call(prompt1, prompt2, profile: gr.OAuthProfile | None=None):
|
| 302 |
generator = [torch.Generator(device="cuda").manual_seed(5)]
|
| 303 |
res = call(
|
| 304 |
pipe,
|
|
|
|
| 315 |
generator=generator
|
| 316 |
)
|
| 317 |
image1 = res.images[0]
|
| 318 |
+
|
| 319 |
+
# save generated images (if logged in)
|
| 320 |
+
user_history.save_image(label=f"{prompt1} / {prompt2}", image=image1, profile=profile, metadata={
|
| 321 |
+
"prompt2": prompt1,
|
| 322 |
+
"prompt1": prompt2,
|
| 323 |
+
"seed": seed,
|
| 324 |
+
})
|
| 325 |
+
|
| 326 |
return image1
|
| 327 |
css = '''
|
| 328 |
#result_image{ transition: transform 2s ease-in-out }
|
| 329 |
#result_image.rotated{transform: rotate(180deg)}
|
| 330 |
'''
|
| 331 |
+
with gr.Blocks() as app:
|
| 332 |
gr.Markdown(
|
| 333 |
'''
|
| 334 |
<center>
|
|
|
|
| 371 |
show_progress=False
|
| 372 |
)
|
| 373 |
|
| 374 |
+
with gr.Blocks(css=css) as app_with_history:
|
| 375 |
+
with gr.Tab("Upside Down Diffusion"):
|
| 376 |
+
app.render()
|
| 377 |
+
with gr.Tab("Past generations"):
|
| 378 |
+
user_history.render()
|
| 379 |
+
|
| 380 |
+
app_with_history.queue(max_size=20)
|
| 381 |
|
| 382 |
if __name__ == "__main__":
|
| 383 |
+
app_with_history.launch(debug=True)
|