Thafx
commited on
Commit
•
8925b0b
0
Parent(s):
Duplicate from Thafx/sddh2
Browse files- .gitattributes +34 -0
- README.md +13 -0
- app.py +178 -0
- requirements.txt +10 -0
.gitattributes
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: SD Realistic Vision v1.3
|
3 |
+
emoji: 👀
|
4 |
+
colorFrom: gray
|
5 |
+
colorTo: purple
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.18.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: Thafx/sddh2
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline, DPMSolverMultistepScheduler
|
2 |
+
import gradio as gr
|
3 |
+
import torch
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
model_id = 'DucHaiten/DucHaitenAIart'
|
7 |
+
prefix = 'masterpiece, best quality, 1girl or 1boy, realistic, anime, 3D, pixar, highly detail eyes, perfect eyes, both eyes are the same, smooth, perfect face, hd, 2k, 4k , 8k, 16k,'
|
8 |
+
|
9 |
+
scheduler = DPMSolverMultistepScheduler.from_pretrained(model_id, subfolder="scheduler")
|
10 |
+
|
11 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
12 |
+
model_id,
|
13 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
14 |
+
scheduler=scheduler)
|
15 |
+
|
16 |
+
pipe_i2i = StableDiffusionImg2ImgPipeline.from_pretrained(
|
17 |
+
model_id,
|
18 |
+
torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
|
19 |
+
scheduler=scheduler)
|
20 |
+
|
21 |
+
if torch.cuda.is_available():
|
22 |
+
pipe = pipe.to("cuda")
|
23 |
+
pipe_i2i = pipe_i2i.to("cuda")
|
24 |
+
|
25 |
+
def error_str(error, title="Error"):
|
26 |
+
return f"""#### {title}
|
27 |
+
{error}""" if error else ""
|
28 |
+
|
29 |
+
|
30 |
+
def _parse_args(prompt, generator):
|
31 |
+
parser = argparse.ArgumentParser(
|
32 |
+
description="making it work."
|
33 |
+
)
|
34 |
+
parser.add_argument(
|
35 |
+
"--no-half-vae", help="no half vae"
|
36 |
+
)
|
37 |
+
|
38 |
+
cmdline_args = parser.parse_args()
|
39 |
+
command = cmdline_args.command
|
40 |
+
conf_file = cmdline_args.conf_file
|
41 |
+
conf_args = Arguments(conf_file)
|
42 |
+
opt = conf_args.readArguments()
|
43 |
+
|
44 |
+
if cmdline_args.config_overrides:
|
45 |
+
for config_override in cmdline_args.config_overrides.split(";"):
|
46 |
+
config_override = config_override.strip()
|
47 |
+
if config_override:
|
48 |
+
var_val = config_override.split("=")
|
49 |
+
assert (
|
50 |
+
len(var_val) == 2
|
51 |
+
), f"Config override '{var_val}' does not have the form 'VAR=val'"
|
52 |
+
conf_args.add_opt(opt, var_val[0], var_val[1], force_override=True)
|
53 |
+
|
54 |
+
def inference(prompt, guidance, steps, width=512, height=512, seed=0, img=None, strength=0.5, neg_prompt="", auto_prefix=False):
|
55 |
+
generator = torch.Generator('cuda').manual_seed(seed) if seed != 0 else None
|
56 |
+
prompt = f"{prefix} {prompt}" if auto_prefix else prompt
|
57 |
+
|
58 |
+
try:
|
59 |
+
if img is not None:
|
60 |
+
return img_to_img(prompt, neg_prompt, img, strength, guidance, steps, width, height, generator), None
|
61 |
+
else:
|
62 |
+
return txt_to_img(prompt, neg_prompt, guidance, steps, width, height, generator), None
|
63 |
+
except Exception as e:
|
64 |
+
return None, error_str(e)
|
65 |
+
|
66 |
+
|
67 |
+
|
68 |
+
def txt_to_img(prompt, neg_prompt, guidance, steps, width, height, generator):
|
69 |
+
|
70 |
+
result = pipe(
|
71 |
+
prompt,
|
72 |
+
negative_prompt = neg_prompt,
|
73 |
+
num_inference_steps = int(steps),
|
74 |
+
guidance_scale = guidance,
|
75 |
+
width = width,
|
76 |
+
height = height,
|
77 |
+
generator = generator)
|
78 |
+
|
79 |
+
return result.images[0]
|
80 |
+
|
81 |
+
def img_to_img(prompt, neg_prompt, img, strength, guidance, steps, width, height, generator):
|
82 |
+
|
83 |
+
ratio = min(height / img.height, width / img.width)
|
84 |
+
img = img.resize((int(img.width * ratio), int(img.height * ratio)), Image.LANCZOS)
|
85 |
+
result = pipe_i2i(
|
86 |
+
prompt,
|
87 |
+
negative_prompt = neg_prompt,
|
88 |
+
init_image = img,
|
89 |
+
num_inference_steps = int(steps),
|
90 |
+
strength = strength,
|
91 |
+
guidance_scale = guidance,
|
92 |
+
width = width,
|
93 |
+
height = height,
|
94 |
+
generator = generator)
|
95 |
+
|
96 |
+
return result.images[0]
|
97 |
+
|
98 |
+
def fake_safety_checker(images, **kwargs):
|
99 |
+
return result.images[0], [False] * len(images)
|
100 |
+
|
101 |
+
pipe.safety_checker = fake_safety_checker
|
102 |
+
|
103 |
+
css = """.main-div div{display:inline-flex;align-items:center;gap:.8rem;font-size:1.75rem}.main-div div h1{font-weight:900;margin-bottom:7px}.main-div p{margin-bottom:10px;font-size:94%}a{text-decoration:underline}.tabs{margin-top:0;margin-bottom:0}#gallery{min-height:20rem}
|
104 |
+
"""
|
105 |
+
with gr.Blocks(css=css) as demo:
|
106 |
+
gr.HTML(
|
107 |
+
f"""
|
108 |
+
<div class="main-div">
|
109 |
+
<div>
|
110 |
+
<h1>Stable Diffusion 2 //Duc Haiten</h1>
|
111 |
+
</div>
|
112 |
+
<p>
|
113 |
+
Demo for <a href="https://huggingface.co/SG161222/Realistic_Vision_V1.3">Realistic Vision V1.3</a> Stable Diffusion model by "Eugene".<br><br>
|
114 |
+
Please use this prompt template to get the desired generation results:<br>
|
115 |
+
<h2><b>Prompt</b>:</h2>
|
116 |
+
<details>
|
117 |
+
RAW photo, *subject*, (high detailed skin:1.2), 8k uhd, dslr, soft lighting, high quality, film grain, Fujifilm XT3
|
118 |
+
<br><br>
|
119 |
+
<i>Example: RAW photo, a close up portrait photo of 26 y.o woman in wastelander clothes, long haircut, pale skin, slim body, background is city ruins, (high detailed skin:1.2), 8k uhd, dslr, soft lighting, high quality, film grain, Fujifilm XT3
|
120 |
+
</i>
|
121 |
+
</details>
|
122 |
+
|
123 |
+
<h2><b>Negative Prompt</b>:</h2>
|
124 |
+
<details>
|
125 |
+
(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime:1.4), text, close up, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck
|
126 |
+
</details>
|
127 |
+
<br>
|
128 |
+
Have Fun & Enjoy
|
129 |
+
//THAFX<br>
|
130 |
+
{"" if prefix else ""}
|
131 |
+
</p>
|
132 |
+
Running on {"<b>GPU 🔥</b>" if torch.cuda.is_available() else f"<b>CPU 🔥</b>"}.
|
133 |
+
</div>
|
134 |
+
"""
|
135 |
+
)
|
136 |
+
with gr.Row():
|
137 |
+
|
138 |
+
with gr.Column(scale=55):
|
139 |
+
with gr.Group():
|
140 |
+
with gr.Row():
|
141 |
+
prompt = gr.Textbox(label="Prompt", show_label=False,max_lines=2,placeholder=f"{prefix} [your prompt]").style(container=False)
|
142 |
+
generate = gr.Button(value="Generate").style(rounded=(False, True, True, False))
|
143 |
+
|
144 |
+
image_out = gr.Image(height=512)
|
145 |
+
error_output = gr.Markdown()
|
146 |
+
|
147 |
+
with gr.Column(scale=45):
|
148 |
+
with gr.Tab("Options"):
|
149 |
+
with gr.Group():
|
150 |
+
neg_prompt = gr.Textbox(label="Negative prompt", placeholder="What to exclude from the image")
|
151 |
+
auto_prefix = gr.Checkbox(label="Prefix styling tokens automatically (RAW photo,)", value=prefix, visible=prefix)
|
152 |
+
|
153 |
+
with gr.Row():
|
154 |
+
guidance = gr.Slider(label="Guidance scale", value=7.5, maximum=15)
|
155 |
+
steps = gr.Slider(label="Steps", value=25, minimum=2, maximum=75, step=1)
|
156 |
+
|
157 |
+
with gr.Row():
|
158 |
+
width = gr.Slider(label="Width", value=512, minimum=64, maximum=1024, step=8)
|
159 |
+
height = gr.Slider(label="Height", value=512, minimum=64, maximum=1024, step=8)
|
160 |
+
|
161 |
+
seed = gr.Slider(0, 2147483647, label='Seed (0 = random)', value=0, step=1)
|
162 |
+
|
163 |
+
with gr.Tab("Image to image"):
|
164 |
+
with gr.Group():
|
165 |
+
image = gr.Image(label="Image", height=256, tool="editor", type="pil")
|
166 |
+
strength = gr.Slider(label="Transformation strength", minimum=0, maximum=1, step=0.01, value=0.5)
|
167 |
+
|
168 |
+
auto_prefix.change(lambda x: gr.update(placeholder=f"{prefix} [your prompt]" if x else "[Your prompt]"), inputs=auto_prefix, outputs=prompt, queue=False)
|
169 |
+
|
170 |
+
inputs = [prompt, guidance, steps, width, height, seed, image, strength, neg_prompt, auto_prefix]
|
171 |
+
outputs = [image_out, error_output]
|
172 |
+
prompt.submit(inference, inputs=inputs, outputs=outputs)
|
173 |
+
generate.click(inference, inputs=inputs, outputs=outputs)
|
174 |
+
|
175 |
+
|
176 |
+
|
177 |
+
demo.queue(concurrency_count=1)
|
178 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--extra-index-url https://download.pytorch.org/whl/cu113
|
2 |
+
invisible-watermark
|
3 |
+
fonts
|
4 |
+
font-roboto
|
5 |
+
torch
|
6 |
+
diffusers
|
7 |
+
#transformers
|
8 |
+
git+https://github.com/huggingface/transformers
|
9 |
+
accelerate
|
10 |
+
ftfy
|