brnm0327 commited on
Commit
e236679
1 Parent(s): 46b8904

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -11
app.py CHANGED
@@ -3,15 +3,17 @@ import torch
3
  import gradio as gr
4
  import opencc
5
 
6
- def text2image(model, img_style, prompt_input, negative_prompt_input, guidance_scale_input, num_inference_steps_input):
7
- """runwayml/stable-diffusion-v1-5 stabilityai/stable-diffusion-2-1 prompthero/openjourney dreamlike-art/dreamlike-photoreal-2.0 IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1"""
8
  if model == "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1 (中文)":
9
  model_id = "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1"
10
  else:
11
  model_id = model
12
 
13
  pipe = StableDiffusionPipeline.from_pretrained(model_id) # torch_dtype=torch.float16
14
- # pipe = pipe.to("cuda")
 
 
15
 
16
  if img_style == "Default":
17
  style_p = ""
@@ -50,6 +52,11 @@ def text2image(model, img_style, prompt_input, negative_prompt_input, guidance_s
50
  style_p = "素描风格"
51
  else:
52
  style_p = "Sketch style"
 
 
 
 
 
53
 
54
  elif img_style == "Ukiyo-e":
55
  if model_id == "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1":
@@ -61,6 +68,12 @@ def text2image(model, img_style, prompt_input, negative_prompt_input, guidance_s
61
  style_p = "梵高风格"
62
  else:
63
  style_p = "Van Gogh style"
 
 
 
 
 
 
64
  elif img_style == "Pixel Art":
65
  if model_id == "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1":
66
  style_p = "像素艺术风格"
@@ -133,7 +146,8 @@ def text2image(model, img_style, prompt_input, negative_prompt_input, guidance_s
133
  negative_prompt=negative_prompt_input,
134
  guidance_scale=guidance_scale_input,
135
  num_images_per_prompt=2,
136
- num_inference_steps=num_inference_steps_input).images
 
137
 
138
  # image.show()
139
  return image[0], image[1]
@@ -143,11 +157,11 @@ style = """h1 {
143
  }
144
  """
145
 
146
- img_styles = ["Default", "Chinese Painting", "Chinese Landscape Painting", "Oil Painting",
147
- "Landscape Painting", "Ink Painting", "Watercolour Painting", "Sketch",
148
- "Ukiyo-e", "Pixel Art", "Abstract", "Dada", "Expressionism", "Futurism",
149
- "Magic Realism", "Minimalism", "Surrealism", "Neo-Impressionism", "Ghibli",
150
- "Naruto", "Jujutsu Kaisen"]
151
 
152
  theme = gr.themes.Default(primary_hue="violet").set(
153
  loader_color="#33A6B8",
@@ -160,6 +174,7 @@ with gr.Blocks(title="Tang Poem Translation Vizualization", css=style, theme=the
160
  with gr.Column():
161
  model_selection = gr.inputs.Radio(["runwayml/stable-diffusion-v1-5",
162
  "stabilityai/stable-diffusion-2-1",
 
163
  "prompthero/openjourney",
164
  "dreamlike-art/dreamlike-photoreal-2.0",
165
  "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1 (中文)"], label="Model ⛲")
@@ -169,6 +184,7 @@ with gr.Blocks(title="Tang Poem Translation Vizualization", css=style, theme=the
169
  with gr.Accordion("Advanced Options 🪆", open=False):
170
  g_scale = gr.Slider(1, 20, step=0.5, value=7.5, label="Guidance Scale")
171
  steps_num = gr.Slider(10, 100, step=10, value=50, label="Steps")
 
172
 
173
  submit_btn = gr.Button("Submit", variant='primary')
174
 
@@ -178,11 +194,11 @@ with gr.Blocks(title="Tang Poem Translation Vizualization", css=style, theme=the
178
  out_img2 = gr.Image(type='pil')
179
 
180
  submit_btn.click(text2image,
181
- inputs=[model_selection, img_style, prompt_input, neg_prompt_input, g_scale, steps_num],
182
  outputs=[out_img1, out_img2])
183
 
184
  gr.HTML(
185
- "<center>Powered by <a href='https://runwayml.com/'>Runway 🎢</a>, <a href='https://stability.ai/'>Stability AI 🤖</a>, <a href='https://prompthero.com/'>PromptHero 🦸</a>, <a href='https://dreamlike.art/'>Dreamlike.art 🔮</a>, and <a href='https://www.idea.edu.cn/research/ccnl.html'>IDEA-CCNL 🔆</a></center>"
186
  )
187
 
188
  demo.launch()
 
3
  import gradio as gr
4
  import opencc
5
 
6
+ def text2image(model, img_style, prompt_input, negative_prompt_input, guidance_scale_input, num_inference_steps_input, seed):
7
+ """runwayml/stable-diffusion-v1-5 stabilityai/stable-diffusion-2-1 CompVis/stable-diffusion-v1-4 prompthero/openjourney dreamlike-art/dreamlike-photoreal-2.0 IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1"""
8
  if model == "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1 (中文)":
9
  model_id = "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1"
10
  else:
11
  model_id = model
12
 
13
  pipe = StableDiffusionPipeline.from_pretrained(model_id) # torch_dtype=torch.float16
14
+ device = "cuda" if torch.cuda.is_available() else "cpu"
15
+ pipe = pipe.to(device)
16
+ generator = torch.Generator(device).manual_seed(seed)
17
 
18
  if img_style == "Default":
19
  style_p = ""
 
52
  style_p = "素描风格"
53
  else:
54
  style_p = "Sketch style"
55
+ elif img_style == "Cartoon":
56
+ if model_id == "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1":
57
+ style_p = "卡通风格"
58
+ else:
59
+ style_p = "Cartoon style"
60
 
61
  elif img_style == "Ukiyo-e":
62
  if model_id == "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1":
 
68
  style_p = "梵高风格"
69
  else:
70
  style_p = "Van Gogh style"
71
+ elif img_style == "Vermeer":
72
+ if model_id == "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1":
73
+ style_p = "维米尔风格"
74
+ else:
75
+ style_p = "Vermeer style"
76
+
77
  elif img_style == "Pixel Art":
78
  if model_id == "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1":
79
  style_p = "像素艺术风格"
 
146
  negative_prompt=negative_prompt_input,
147
  guidance_scale=guidance_scale_input,
148
  num_images_per_prompt=2,
149
+ num_inference_steps=num_inference_steps_input,
150
+ generator=generator).images
151
 
152
  # image.show()
153
  return image[0], image[1]
 
157
  }
158
  """
159
 
160
+ img_styles = ["Default", "Chinese Painting", "Chinese Landscape Painting", "Oil Painting",
161
+ "Landscape Painting", "Ink Painting", "Watercolour Painting", "Sketch", "Cartoon",
162
+ "Ukiyo-e", "Van Gogh", "Vermeer","Pixel Art", "Abstract", "Dada", "Expressionism", "Futurism",
163
+ "Magic Realism", "Minimalism", "Surrealism", "Neo-Impressionism", "Ghibli",
164
+ "Naruto", "Jujutsu Kaisen"]
165
 
166
  theme = gr.themes.Default(primary_hue="violet").set(
167
  loader_color="#33A6B8",
 
174
  with gr.Column():
175
  model_selection = gr.inputs.Radio(["runwayml/stable-diffusion-v1-5",
176
  "stabilityai/stable-diffusion-2-1",
177
+ "CompVis/stable-diffusion-v1-4",
178
  "prompthero/openjourney",
179
  "dreamlike-art/dreamlike-photoreal-2.0",
180
  "IDEA-CCNL/Taiyi-Stable-Diffusion-1B-Chinese-v0.1 (中文)"], label="Model ⛲")
 
184
  with gr.Accordion("Advanced Options 🪆", open=False):
185
  g_scale = gr.Slider(1, 20, step=0.5, value=7.5, label="Guidance Scale")
186
  steps_num = gr.Slider(10, 100, step=10, value=50, label="Steps")
187
+ seed = gr.Slider(1, 9999999, step=1, value=1024, label="Seed")
188
 
189
  submit_btn = gr.Button("Submit", variant='primary')
190
 
 
194
  out_img2 = gr.Image(type='pil')
195
 
196
  submit_btn.click(text2image,
197
+ inputs=[model_selection, img_style, prompt_input, neg_prompt_input, g_scale, steps_num, seed],
198
  outputs=[out_img1, out_img2])
199
 
200
  gr.HTML(
201
+ "<center>Powered by <a href='https://runwayml.com/'>Runway 🎢</a>, <a href='https://stability.ai/'>Stability AI 🤖</a>, <a href='https://github.com/CompVis'>CompVis 👁</a>, <a href='https://prompthero.com/'>PromptHero 🦸</a>, <a href='https://dreamlike.art/'>Dreamlike.art 🔮</a>, and <a href='https://www.idea.edu.cn/research/ccnl.html'>IDEA-CCNL 🔆</a></center>"
202
  )
203
 
204
  demo.launch()