Spaces:
Runtime error
Runtime error
Duplicate from souljoy/Pokemon-Stable-Diffusion-Chinese
Browse filesCo-authored-by: 小爷毛毛-卓寿杰 <souljoy@users.noreply.huggingface.co>
- .gitattributes +34 -0
- README.md +14 -0
- app.py +54 -0
- requirements.txt +6 -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,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Taiyi Stable Diffusion Chinese
|
3 |
+
emoji: 🤯
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: red
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.10.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
license: creativeml-openrail-m
|
11 |
+
duplicated_from: souljoy/Pokemon-Stable-Diffusion-Chinese
|
12 |
+
---
|
13 |
+
|
14 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import torch
|
4 |
+
|
5 |
+
from diffusers import (
|
6 |
+
StableDiffusionPipeline,
|
7 |
+
StableDiffusionImg2ImgPipeline,
|
8 |
+
)
|
9 |
+
|
10 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
+
model_id = "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Anime-Chinese-v0.1"
|
12 |
+
|
13 |
+
pipe_text2img = StableDiffusionPipeline.from_pretrained(model_id)
|
14 |
+
model_path = "souljoy/sd-pokemon-model-lora-zh"
|
15 |
+
pipe_text2img.unet.load_attn_procs(model_path)
|
16 |
+
pipe_text2img.to(device)
|
17 |
+
pipe_text2img.safety_checker = lambda images, clip_input: (images, False)
|
18 |
+
pipe_img2img = StableDiffusionImg2ImgPipeline(**pipe_text2img.components).to(device)
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
def infer_text2img(prompt, guide, steps, width, height, image_in, strength):
|
23 |
+
if image_in is not None:
|
24 |
+
init_image = image_in.convert("RGB").resize((width, height))
|
25 |
+
output = pipe_img2img(prompt, image=init_image, strength=strength, width=width, height=height, guidance_scale=guide, num_inference_steps=steps)
|
26 |
+
else:
|
27 |
+
output = pipe_text2img(prompt, width=width, height=height, guidance_scale=guide, num_inference_steps=steps)
|
28 |
+
image = output.images[0]
|
29 |
+
return image
|
30 |
+
|
31 |
+
|
32 |
+
with gr.Blocks() as demo:
|
33 |
+
examples = [
|
34 |
+
["粉色的蝴蝶,小精灵,卡通"],
|
35 |
+
["可爱的狗,小精灵,卡通"],
|
36 |
+
["漂亮的猫,小精灵,卡通"],
|
37 |
+
]
|
38 |
+
with gr.Row():
|
39 |
+
with gr.Column(scale=1, ):
|
40 |
+
image_out = gr.Image(label = '输出(output)')
|
41 |
+
with gr.Column(scale=1, ):
|
42 |
+
image_in = gr.Image(source='upload', elem_id="image_upload", type="pil", label="参考图(非必须)(ref)")
|
43 |
+
prompt = gr.Textbox(label = '提示词(prompt)')
|
44 |
+
submit_btn = gr.Button("生成图像(Generate)")
|
45 |
+
with gr.Row(scale=0.5 ):
|
46 |
+
guide = gr.Slider(2, 15, value = 7, step = 0.1, label = '文本引导强度(guidance scale)')
|
47 |
+
steps = gr.Slider(10, 30, value = 20, step = 1, label = '迭代次数(inference steps)')
|
48 |
+
width = gr.Slider(384, 640, value = 512, step = 64, label = '宽度(width)')
|
49 |
+
height = gr.Slider(384, 640, value = 512, step = 64, label = '高度(height)')
|
50 |
+
strength = gr.Slider(0, 1.0, value = 0.8, step = 0.02, label = '参考图改变程度(strength)')
|
51 |
+
ex = gr.Examples(examples, fn=infer_text2img, inputs=[prompt, guide, steps, width, height], outputs=image_out)
|
52 |
+
|
53 |
+
submit_btn.click(fn = infer_text2img, inputs = [prompt, guide, steps, width, height, image_in, strength], outputs = image_out)
|
54 |
+
demo.queue(concurrency_count=1, max_size=8).launch()
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--extra-index-url https://download.pytorch.org/whl/cu113
|
2 |
+
torch
|
3 |
+
torchvision
|
4 |
+
git+https://github.com/huggingface/diffusers.git
|
5 |
+
transformers
|
6 |
+
accelerate
|