Spaces:
Runtime error
Runtime error
weifeng-chen
commited on
Commit
โข
1ec3b8e
1
Parent(s):
efe74f2
init commit
Browse files- README.md +1 -1
- app.py +37 -0
- source.png +0 -0
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title: Taiyi Stable Diffusion
|
3 |
emoji: ๐ฉ
|
4 |
colorFrom: red
|
5 |
colorTo: red
|
|
|
1 |
---
|
2 |
+
title: Taiyi Stable Diffusion Chinese
|
3 |
emoji: ๐ฉ
|
4 |
colorFrom: red
|
5 |
colorTo: red
|
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from PIL import Image
|
4 |
+
import numpy as np
|
5 |
+
from io import BytesIO
|
6 |
+
from diffusers import StableDiffusionImg2ImgPipeline, StableDiffusionPipeline, UNet2DConditionModel, AutoencoderKL
|
7 |
+
from transformers import BertTokenizer, BertModel
|
8 |
+
|
9 |
+
|
10 |
+
device="cuda"
|
11 |
+
model_id = "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1"
|
12 |
+
|
13 |
+
# pipe_img2img = StableDiffusionImg2ImgPipeline.from_pretrained(model_id, tokenizer=tokenizer, text_encoder=text_encoder, vae=vae, unet=unet).to(device)
|
14 |
+
pipe_text2img = StableDiffusionPipeline.from_pretrained(model_id).to(device)
|
15 |
+
|
16 |
+
def resize(w_val,l_val,img):
|
17 |
+
img = Image.open(img)
|
18 |
+
img = img.resize((w_val,l_val), Image.Resampling.LANCZOS)
|
19 |
+
return img
|
20 |
+
|
21 |
+
|
22 |
+
def infer(prompt, guide, steps, width, height):
|
23 |
+
image_list = pipe_text2img([prompt], guidance_scale=guide, num_inference_steps=steps, width=width, height=height)
|
24 |
+
images = []
|
25 |
+
for i, image in enumerate(image_list["sample"]):
|
26 |
+
images.append(image)
|
27 |
+
return image
|
28 |
+
|
29 |
+
gr.Interface(fn=infer, inputs=
|
30 |
+
[
|
31 |
+
# gr.Image(source="upload", type="filepath", label="ๅๅงๅพๅ"),
|
32 |
+
gr.Textbox(label = 'ๆ็คบ่ฏ(prompt)'),
|
33 |
+
gr.Slider(2, 15, value = 7, label = 'ๆๆฌๅผๅฏผๅผบๅบฆ'),
|
34 |
+
gr.Slider(10, 30, value = 20, step = 1, label = '่ฟญไปฃๆฌกๆฐ'),
|
35 |
+
gr.Slider(256, 768, value = 512, step = 64, label = 'ๅฎฝๅบฆ'),
|
36 |
+
gr.Slider(256, 768, value = 512, step = 64, label = '้ซๅบฆ'),
|
37 |
+
],outputs='image').queue(max_size=10).launch(enable_queue=True)
|
source.png
ADDED