Spaces:
Running
on
Zero
Running
on
Zero
panelforge
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import gradio as gr
|
|
2 |
import numpy as np
|
3 |
import random
|
4 |
|
5 |
-
import spaces
|
6 |
from diffusers import DiffusionPipeline
|
7 |
import torch
|
8 |
|
@@ -20,8 +20,11 @@ pipe = pipe.to(device)
|
|
20 |
MAX_SEED = np.iinfo(np.int32).max
|
21 |
MAX_IMAGE_SIZE = 1024
|
22 |
|
|
|
|
|
|
|
23 |
|
24 |
-
@spaces.GPU
|
25 |
def infer(
|
26 |
prompt,
|
27 |
negative_prompt,
|
@@ -31,17 +34,20 @@ def infer(
|
|
31 |
height,
|
32 |
guidance_scale,
|
33 |
num_inference_steps,
|
34 |
-
|
35 |
-
progress=None,
|
36 |
):
|
37 |
if randomize_seed:
|
38 |
seed = random.randint(0, MAX_SEED)
|
39 |
|
40 |
generator = torch.Generator().manual_seed(seed)
|
41 |
|
|
|
|
|
|
|
|
|
42 |
image = pipe(
|
43 |
-
prompt=
|
44 |
-
negative_prompt=
|
45 |
guidance_scale=guidance_scale,
|
46 |
num_inference_steps=num_inference_steps,
|
47 |
width=width,
|
@@ -87,7 +93,7 @@ with gr.Blocks(css=css) as demo:
|
|
87 |
label="Negative prompt",
|
88 |
max_lines=1,
|
89 |
placeholder="Enter a negative prompt",
|
90 |
-
visible=
|
91 |
)
|
92 |
|
93 |
seed = gr.Slider(
|
|
|
2 |
import numpy as np
|
3 |
import random
|
4 |
|
5 |
+
import spaces # [uncomment to use ZeroGPU]
|
6 |
from diffusers import DiffusionPipeline
|
7 |
import torch
|
8 |
|
|
|
20 |
MAX_SEED = np.iinfo(np.int32).max
|
21 |
MAX_IMAGE_SIZE = 1024
|
22 |
|
23 |
+
# Specific prefixes for the prompt and negative prompt
|
24 |
+
prompt_prefix = "score_9, score_8_up, score_7_up, source_anime"
|
25 |
+
negative_prompt_prefix = "score_6, score_5, score_4, source_cartoon, 3d, (censor), monochrome, blurry, lowres, watermark"
|
26 |
|
27 |
+
@spaces.GPU # [uncomment to use ZeroGPU]
|
28 |
def infer(
|
29 |
prompt,
|
30 |
negative_prompt,
|
|
|
34 |
height,
|
35 |
guidance_scale,
|
36 |
num_inference_steps,
|
37 |
+
progress=gr.Progress(track_tqdm=True),
|
|
|
38 |
):
|
39 |
if randomize_seed:
|
40 |
seed = random.randint(0, MAX_SEED)
|
41 |
|
42 |
generator = torch.Generator().manual_seed(seed)
|
43 |
|
44 |
+
# Prepend the specific terms to the prompt and negative prompt
|
45 |
+
full_prompt = f"{prompt_prefix}, {prompt}"
|
46 |
+
full_negative_prompt = f"{negative_prompt_prefix}, {negative_prompt}"
|
47 |
+
|
48 |
image = pipe(
|
49 |
+
prompt=full_prompt,
|
50 |
+
negative_prompt=full_negative_prompt,
|
51 |
guidance_scale=guidance_scale,
|
52 |
num_inference_steps=num_inference_steps,
|
53 |
width=width,
|
|
|
93 |
label="Negative prompt",
|
94 |
max_lines=1,
|
95 |
placeholder="Enter a negative prompt",
|
96 |
+
visible=True,
|
97 |
)
|
98 |
|
99 |
seed = gr.Slider(
|