Update app.py
Browse files
app.py
CHANGED
|
@@ -86,10 +86,17 @@ styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
|
| 86 |
STYLE_NAMES = list(styles.keys())
|
| 87 |
DEFAULT_STYLE_NAME = "(No style)"
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
@spaces.GPU #[uncomment to use ZeroGPU]
|
| 90 |
def infer(
|
| 91 |
prompt,
|
| 92 |
negative_prompt,
|
|
|
|
| 93 |
seed,
|
| 94 |
randomize_seed,
|
| 95 |
width,
|
|
@@ -100,7 +107,7 @@ def infer(
|
|
| 100 |
):
|
| 101 |
if randomize_seed:
|
| 102 |
seed = random.randint(0, MAX_SEED)
|
| 103 |
-
|
| 104 |
generator = torch.Generator().manual_seed(seed)
|
| 105 |
|
| 106 |
image = pipe(
|
|
@@ -215,6 +222,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 215 |
inputs=[
|
| 216 |
prompt,
|
| 217 |
negative_prompt,
|
|
|
|
| 218 |
seed,
|
| 219 |
randomize_seed,
|
| 220 |
width,
|
|
|
|
| 86 |
STYLE_NAMES = list(styles.keys())
|
| 87 |
DEFAULT_STYLE_NAME = "(No style)"
|
| 88 |
|
| 89 |
+
def apply_style(style_name: str, positive: str, negative: str = "") -> Tuple[str, str]:
|
| 90 |
+
p, n = styles.get(style_name, styles[DEFAULT_STYLE_NAME])
|
| 91 |
+
if not negative:
|
| 92 |
+
negative = ""
|
| 93 |
+
return p.replace("{prompt}", positive), n + negative
|
| 94 |
+
|
| 95 |
@spaces.GPU #[uncomment to use ZeroGPU]
|
| 96 |
def infer(
|
| 97 |
prompt,
|
| 98 |
negative_prompt,
|
| 99 |
+
style,
|
| 100 |
seed,
|
| 101 |
randomize_seed,
|
| 102 |
width,
|
|
|
|
| 107 |
):
|
| 108 |
if randomize_seed:
|
| 109 |
seed = random.randint(0, MAX_SEED)
|
| 110 |
+
prompt, negative_prompt = apply_style(style, prompt, negative_prompt)
|
| 111 |
generator = torch.Generator().manual_seed(seed)
|
| 112 |
|
| 113 |
image = pipe(
|
|
|
|
| 222 |
inputs=[
|
| 223 |
prompt,
|
| 224 |
negative_prompt,
|
| 225 |
+
style_selection,
|
| 226 |
seed,
|
| 227 |
randomize_seed,
|
| 228 |
width,
|