Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -4,10 +4,12 @@ import random
|
|
4 |
import spaces #[uncomment to use ZeroGPU]
|
5 |
from diffusers import DiffusionPipeline, DPMSolverSDEScheduler
|
6 |
import torch
|
|
|
7 |
|
8 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
9 |
-
model_repo_id = "John6666/wai-ani-nsfw-ponyxl-v8-sdxl"
|
10 |
|
|
|
11 |
if torch.cuda.is_available():
|
12 |
torch_dtype = torch.float16
|
13 |
else:
|
@@ -20,7 +22,28 @@ pipe = pipe.to(device)
|
|
20 |
MAX_SEED = np.iinfo(np.int32).max
|
21 |
MAX_IMAGE_SIZE = 1024
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
|
25 |
|
26 |
if randomize_seed:
|
@@ -29,16 +52,19 @@ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance
|
|
29 |
generator = torch.Generator().manual_seed(seed)
|
30 |
|
31 |
image = pipe(
|
32 |
-
prompt
|
33 |
-
negative_prompt
|
34 |
-
guidance_scale
|
35 |
-
num_inference_steps
|
36 |
-
width
|
37 |
-
height
|
38 |
-
generator
|
39 |
).images[0]
|
|
|
|
|
|
|
40 |
|
41 |
-
return
|
42 |
|
43 |
examples = [
|
44 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
@@ -46,12 +72,7 @@ examples = [
|
|
46 |
"A delicious ceviche cheesecake slice",
|
47 |
]
|
48 |
|
49 |
-
css="""
|
50 |
-
#col-container {
|
51 |
-
margin: 0 auto;
|
52 |
-
max-width: 640px;
|
53 |
-
}
|
54 |
-
"""
|
55 |
|
56 |
with gr.Blocks(css=css) as demo:
|
57 |
|
@@ -118,26 +139,3 @@ with gr.Blocks(css=css) as demo:
|
|
118 |
minimum=0.0,
|
119 |
maximum=10.0,
|
120 |
step=0.1,
|
121 |
-
value=0.0, #Replace with defaults that work for your model
|
122 |
-
)
|
123 |
-
|
124 |
-
num_inference_steps = gr.Slider(
|
125 |
-
label="Number of inference steps",
|
126 |
-
minimum=1,
|
127 |
-
maximum=50,
|
128 |
-
step=1,
|
129 |
-
value=2, #Replace with defaults that work for your model
|
130 |
-
)
|
131 |
-
|
132 |
-
gr.Examples(
|
133 |
-
examples = examples,
|
134 |
-
inputs = [prompt]
|
135 |
-
)
|
136 |
-
gr.on(
|
137 |
-
triggers=[run_button.click, prompt.submit],
|
138 |
-
fn = infer,
|
139 |
-
inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
|
140 |
-
outputs = [result, seed]
|
141 |
-
)
|
142 |
-
|
143 |
-
demo.queue().launch()
|
|
|
4 |
import spaces #[uncomment to use ZeroGPU]
|
5 |
from diffusers import DiffusionPipeline, DPMSolverSDEScheduler
|
6 |
import torch
|
7 |
+
from transformers import AutoModelForObjectDetection, AutoImageProcessor
|
8 |
|
9 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
+
model_repo_id = "John6666/wai-ani-nsfw-ponyxl-v8-sdxl" # Your diffusion model
|
11 |
|
12 |
+
# Load your main diffusion pipeline
|
13 |
if torch.cuda.is_available():
|
14 |
torch_dtype = torch.float16
|
15 |
else:
|
|
|
22 |
MAX_SEED = np.iinfo(np.int32).max
|
23 |
MAX_IMAGE_SIZE = 1024
|
24 |
|
25 |
+
# Load ADetailer model (from Hugging Face)
|
26 |
+
adetailer_model_id = "Bingsu/adetailer"
|
27 |
+
adetailer_model = AutoModelForObjectDetection.from_pretrained(adetailer_model_id)
|
28 |
+
adetailer_processor = AutoImageProcessor.from_pretrained(adetailer_model_id)
|
29 |
+
|
30 |
+
def fix_eyes_with_adetailer(image):
|
31 |
+
# Convert image to format for ADetailer
|
32 |
+
pixel_values = adetailer_processor(images=image, return_tensors="pt").pixel_values
|
33 |
+
pixel_values = pixel_values.to(device)
|
34 |
+
|
35 |
+
# Run ADetailer on the image
|
36 |
+
with torch.no_grad():
|
37 |
+
outputs = adetailer_model(pixel_values=pixel_values)
|
38 |
+
|
39 |
+
# Post-process the outputs and apply the fixes (if any)
|
40 |
+
corrected_image = image # Placeholder for the actual post-processing
|
41 |
+
# Apply fixes based on the detection and correction model outputs
|
42 |
+
# This step requires actual ADetailer implementation details for correcting eyes.
|
43 |
+
|
44 |
+
return corrected_image # Return the corrected image
|
45 |
+
|
46 |
+
@spaces.GPU #[uncomment to use ZeroGPU]
|
47 |
def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
|
48 |
|
49 |
if randomize_seed:
|
|
|
52 |
generator = torch.Generator().manual_seed(seed)
|
53 |
|
54 |
image = pipe(
|
55 |
+
prompt=prompt,
|
56 |
+
negative_prompt=negative_prompt,
|
57 |
+
guidance_scale=guidance_scale,
|
58 |
+
num_inference_steps=num_inference_steps,
|
59 |
+
width=width,
|
60 |
+
height=height,
|
61 |
+
generator=generator
|
62 |
).images[0]
|
63 |
+
|
64 |
+
# Apply ADetailer to fix eyes after generating the image
|
65 |
+
corrected_image = fix_eyes_with_adetailer(image)
|
66 |
|
67 |
+
return corrected_image, seed
|
68 |
|
69 |
examples = [
|
70 |
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
|
|
72 |
"A delicious ceviche cheesecake slice",
|
73 |
]
|
74 |
|
75 |
+
css="""#col-container {margin: 0 auto; max-width: 640px;}"""
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
with gr.Blocks(css=css) as demo:
|
78 |
|
|
|
139 |
minimum=0.0,
|
140 |
maximum=10.0,
|
141 |
step=0.1,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|