Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,9 +8,11 @@
|
|
| 8 |
# furnished to do so, subject to the following conditions:
|
| 9 |
#
|
| 10 |
# ..
|
|
|
|
| 11 |
import os
|
| 12 |
import random
|
| 13 |
import uuid
|
|
|
|
| 14 |
|
| 15 |
import gradio as gr
|
| 16 |
import numpy as np
|
|
@@ -20,8 +22,6 @@ import torch
|
|
| 20 |
from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
| 21 |
|
| 22 |
DESCRIPTION = """
|
| 23 |
-
|
| 24 |
-
|
| 25 |
"""
|
| 26 |
|
| 27 |
def save_image(img):
|
|
@@ -54,7 +54,45 @@ if torch.cuda.is_available():
|
|
| 54 |
pipe.load_lora_weights("prithivMLmods/Canopus-Realism-LoRA", weight_name="Canopus-Realism-LoRA.safetensors", adapter_name="rlms")
|
| 55 |
pipe.set_adapters("rlms")
|
| 56 |
pipe.to("cuda")
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
@spaces.GPU(duration=60, enable_queue=True)
|
| 59 |
def generate(
|
| 60 |
prompt: str,
|
|
@@ -65,18 +103,19 @@ def generate(
|
|
| 65 |
height: int = 1024,
|
| 66 |
guidance_scale: float = 3,
|
| 67 |
randomize_seed: bool = False,
|
|
|
|
| 68 |
progress=gr.Progress(track_tqdm=True),
|
| 69 |
):
|
| 70 |
-
|
| 71 |
-
|
| 72 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
| 73 |
|
|
|
|
|
|
|
| 74 |
if not use_negative_prompt:
|
| 75 |
-
|
| 76 |
|
| 77 |
images = pipe(
|
| 78 |
-
prompt=
|
| 79 |
-
negative_prompt=
|
| 80 |
width=width,
|
| 81 |
height=height,
|
| 82 |
guidance_scale=guidance_scale,
|
|
@@ -103,8 +142,7 @@ footer {
|
|
| 103 |
}
|
| 104 |
'''
|
| 105 |
|
| 106 |
-
|
| 107 |
-
with gr.Blocks(css=css,theme="prithivMLmods/theme_brief") as demo:
|
| 108 |
|
| 109 |
with gr.Group():
|
| 110 |
with gr.Row():
|
|
@@ -117,6 +155,7 @@ with gr.Blocks(css=css,theme="prithivMLmods/theme_brief") as demo:
|
|
| 117 |
)
|
| 118 |
run_button = gr.Button("Run", scale=0)
|
| 119 |
result = gr.Gallery(label="Result", columns=1, preview=True, show_label=False)
|
|
|
|
| 120 |
with gr.Accordion("Advanced options", open=False):
|
| 121 |
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
|
| 122 |
negative_prompt = gr.Text(
|
|
@@ -136,6 +175,7 @@ with gr.Blocks(css=css,theme="prithivMLmods/theme_brief") as demo:
|
|
| 136 |
visible=True
|
| 137 |
)
|
| 138 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
|
|
|
| 139 |
with gr.Row(visible=True):
|
| 140 |
width = gr.Slider(
|
| 141 |
label="Width",
|
|
@@ -151,6 +191,7 @@ with gr.Blocks(css=css,theme="prithivMLmods/theme_brief") as demo:
|
|
| 151 |
step=8,
|
| 152 |
value=1024,
|
| 153 |
)
|
|
|
|
| 154 |
with gr.Row():
|
| 155 |
guidance_scale = gr.Slider(
|
| 156 |
label="Guidance Scale",
|
|
@@ -160,6 +201,15 @@ with gr.Blocks(css=css,theme="prithivMLmods/theme_brief") as demo:
|
|
| 160 |
value=3.0,
|
| 161 |
)
|
| 162 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
gr.Examples(
|
| 164 |
examples=examples,
|
| 165 |
inputs=prompt,
|
|
@@ -174,7 +224,6 @@ with gr.Blocks(css=css,theme="prithivMLmods/theme_brief") as demo:
|
|
| 174 |
outputs=negative_prompt,
|
| 175 |
api_name=False,
|
| 176 |
)
|
| 177 |
-
|
| 178 |
|
| 179 |
gr.on(
|
| 180 |
triggers=[
|
|
@@ -192,10 +241,12 @@ with gr.Blocks(css=css,theme="prithivMLmods/theme_brief") as demo:
|
|
| 192 |
height,
|
| 193 |
guidance_scale,
|
| 194 |
randomize_seed,
|
|
|
|
| 195 |
],
|
| 196 |
outputs=[result, seed],
|
| 197 |
api_name="run",
|
| 198 |
)
|
| 199 |
-
|
| 200 |
if __name__ == "__main__":
|
| 201 |
-
demo.queue(max_size=40).launch()
|
|
|
|
|
|
| 8 |
# furnished to do so, subject to the following conditions:
|
| 9 |
#
|
| 10 |
# ..
|
| 11 |
+
|
| 12 |
import os
|
| 13 |
import random
|
| 14 |
import uuid
|
| 15 |
+
from typing import Tuple
|
| 16 |
|
| 17 |
import gradio as gr
|
| 18 |
import numpy as np
|
|
|
|
| 22 |
from diffusers import StableDiffusionXLPipeline, EulerAncestralDiscreteScheduler
|
| 23 |
|
| 24 |
DESCRIPTION = """
|
|
|
|
|
|
|
| 25 |
"""
|
| 26 |
|
| 27 |
def save_image(img):
|
|
|
|
| 54 |
pipe.load_lora_weights("prithivMLmods/Canopus-Realism-LoRA", weight_name="Canopus-Realism-LoRA.safetensors", adapter_name="rlms")
|
| 55 |
pipe.set_adapters("rlms")
|
| 56 |
pipe.to("cuda")
|
| 57 |
+
|
| 58 |
+
style_list = [
|
| 59 |
+
{
|
| 60 |
+
"name": "3840 x 2160",
|
| 61 |
+
"prompt": "hyper-realistic 8K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
|
| 62 |
+
"negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"name": "2560 x 1440",
|
| 66 |
+
"prompt": "hyper-realistic 4K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
|
| 67 |
+
"negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
|
| 68 |
+
},
|
| 69 |
+
{
|
| 70 |
+
"name": "HD+",
|
| 71 |
+
"prompt": "hyper-realistic 2K image of {prompt}. ultra-detailed, lifelike, high-resolution, sharp, vibrant colors, photorealistic",
|
| 72 |
+
"negative_prompt": "cartoonish, low resolution, blurry, simplistic, abstract, deformed, ugly",
|
| 73 |
+
},
|
| 74 |
+
{
|
| 75 |
+
"name": "Style Zero",
|
| 76 |
+
"prompt": "{prompt}",
|
| 77 |
+
"negative_prompt": "",
|
| 78 |
+
},
|
| 79 |
+
]
|
| 80 |
+
|
| 81 |
+
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
| 82 |
+
|
| 83 |
+
DEFAULT_STYLE_NAME = "3840 x 2160"
|
| 84 |
+
STYLE_NAMES = list(styles.keys())
|
| 85 |
+
|
| 86 |
+
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
| 87 |
+
if style_name in styles:
|
| 88 |
+
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
| 89 |
+
else:
|
| 90 |
+
p, n = styles[DEFAULT_STYLE_NAME]
|
| 91 |
+
|
| 92 |
+
if not negative:
|
| 93 |
+
negative = ""
|
| 94 |
+
return p.replace("{prompt}", positive), n + negative
|
| 95 |
+
|
| 96 |
@spaces.GPU(duration=60, enable_queue=True)
|
| 97 |
def generate(
|
| 98 |
prompt: str,
|
|
|
|
| 103 |
height: int = 1024,
|
| 104 |
guidance_scale: float = 3,
|
| 105 |
randomize_seed: bool = False,
|
| 106 |
+
style_name: str = DEFAULT_STYLE_NAME,
|
| 107 |
progress=gr.Progress(track_tqdm=True),
|
| 108 |
):
|
|
|
|
|
|
|
| 109 |
seed = int(randomize_seed_fn(seed, randomize_seed))
|
| 110 |
|
| 111 |
+
positive_prompt, effective_negative_prompt = apply_style(style_name, prompt, negative_prompt)
|
| 112 |
+
|
| 113 |
if not use_negative_prompt:
|
| 114 |
+
effective_negative_prompt = "" # type: ignore
|
| 115 |
|
| 116 |
images = pipe(
|
| 117 |
+
prompt=positive_prompt,
|
| 118 |
+
negative_prompt=effective_negative_prompt,
|
| 119 |
width=width,
|
| 120 |
height=height,
|
| 121 |
guidance_scale=guidance_scale,
|
|
|
|
| 142 |
}
|
| 143 |
'''
|
| 144 |
|
| 145 |
+
with gr.Blocks(css=css, theme="prithivMLmods/theme_brief") as demo:
|
|
|
|
| 146 |
|
| 147 |
with gr.Group():
|
| 148 |
with gr.Row():
|
|
|
|
| 155 |
)
|
| 156 |
run_button = gr.Button("Run", scale=0)
|
| 157 |
result = gr.Gallery(label="Result", columns=1, preview=True, show_label=False)
|
| 158 |
+
|
| 159 |
with gr.Accordion("Advanced options", open=False):
|
| 160 |
use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=True)
|
| 161 |
negative_prompt = gr.Text(
|
|
|
|
| 175 |
visible=True
|
| 176 |
)
|
| 177 |
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
| 178 |
+
|
| 179 |
with gr.Row(visible=True):
|
| 180 |
width = gr.Slider(
|
| 181 |
label="Width",
|
|
|
|
| 191 |
step=8,
|
| 192 |
value=1024,
|
| 193 |
)
|
| 194 |
+
|
| 195 |
with gr.Row():
|
| 196 |
guidance_scale = gr.Slider(
|
| 197 |
label="Guidance Scale",
|
|
|
|
| 201 |
value=3.0,
|
| 202 |
)
|
| 203 |
|
| 204 |
+
style_selection = gr.Radio(
|
| 205 |
+
show_label=True,
|
| 206 |
+
container=True,
|
| 207 |
+
interactive=True,
|
| 208 |
+
choices=STYLE_NAMES,
|
| 209 |
+
value=DEFAULT_STYLE_NAME,
|
| 210 |
+
label="Quality Style",
|
| 211 |
+
)
|
| 212 |
+
|
| 213 |
gr.Examples(
|
| 214 |
examples=examples,
|
| 215 |
inputs=prompt,
|
|
|
|
| 224 |
outputs=negative_prompt,
|
| 225 |
api_name=False,
|
| 226 |
)
|
|
|
|
| 227 |
|
| 228 |
gr.on(
|
| 229 |
triggers=[
|
|
|
|
| 241 |
height,
|
| 242 |
guidance_scale,
|
| 243 |
randomize_seed,
|
| 244 |
+
style_selection,
|
| 245 |
],
|
| 246 |
outputs=[result, seed],
|
| 247 |
api_name="run",
|
| 248 |
)
|
| 249 |
+
|
| 250 |
if __name__ == "__main__":
|
| 251 |
+
demo.queue(max_size=40).launch()
|
| 252 |
+
|