weifeng-chen commited on
Commit
1ec3b8e
โ€ข
1 Parent(s): efe74f2

init commit

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +37 -0
  3. source.png +0 -0
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Taiyi Stable Diffusion 1B Chinese
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