fujie170 commited on
Commit
b49e232
·
1 Parent(s): 5d5da13
Files changed (3) hide show
  1. README.md +27 -5
  2. app.py +58 -27
  3. requirements.txt +2 -1
README.md CHANGED
@@ -1,12 +1,34 @@
1
  ---
2
- title: Text-to-Image Gradio Template
3
- emoji: 🖼
4
- colorFrom: purple
5
- colorTo: red
6
  sdk: gradio
7
  sdk_version: 5.25.2
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: 可爱熊猫烧香生成器
3
+ emoji: 🐼
4
+ colorFrom: green
5
+ colorTo: yellow
6
  sdk: gradio
7
  sdk_version: 5.25.2
8
  app_file: app.py
9
  pinned: false
10
  ---
11
 
12
+ # 🐼 可爱熊猫烧香生成器
13
+
14
+ 一个专门生成可爱熊猫烧香图片的AI应用!
15
+
16
+ ## 特色功能
17
+
18
+ - 🎨 专门优化的熊猫烧香提示词
19
+ - ⚡ 快速生成(使用SDXL-Turbo模型)
20
+ - 🎯 适中的图片尺寸(512x512)
21
+ - 😊 可爱风格优化
22
+ - 🎲 多种预设样式选择
23
+
24
+ ## 使用方法
25
+
26
+ 1. 选择预设的样式按钮,或者自定义描述
27
+ 2. 点击"🎨 生成"按钮
28
+ 3. 等待几秒钟即可获得可爱的熊猫烧香图片!
29
+
30
+ ## 技术特点
31
+
32
+ - 使用 Stable Diffusion XL Turbo 模型
33
+ - 优化的参数设置以平衡质量和速度
34
+ - 中文友好的用户界面
app.py CHANGED
@@ -7,7 +7,7 @@ from diffusers import DiffusionPipeline
7
  import torch
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
- model_repo_id = "stabilityai/sdxl-turbo" # Replace to the model you would like to use
11
 
12
  if torch.cuda.is_available():
13
  torch_dtype = torch.float16
@@ -18,7 +18,19 @@ pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
18
  pipe = pipe.to(device)
19
 
20
  MAX_SEED = np.iinfo(np.int32).max
21
- MAX_IMAGE_SIZE = 1024
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
 
24
  # @spaces.GPU #[uncomment to use ZeroGPU]
@@ -52,9 +64,11 @@ def infer(
52
 
53
 
54
  examples = [
55
- "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
56
- "An astronaut riding a green horse",
57
- "A delicious ceviche cheesecake slice",
 
 
58
  ]
59
 
60
  css = """
@@ -66,74 +80,91 @@ css = """
66
 
67
  with gr.Blocks(css=css) as demo:
68
  with gr.Column(elem_id="col-container"):
69
- gr.Markdown(" # Text-to-Image Gradio Template")
 
70
 
71
  with gr.Row():
72
  prompt = gr.Text(
73
- label="Prompt",
74
  show_label=False,
75
- max_lines=1,
76
- placeholder="Enter your prompt",
77
  container=False,
 
78
  )
79
 
80
- run_button = gr.Button("Run", scale=0, variant="primary")
 
 
 
 
 
 
 
81
 
82
  result = gr.Image(label="Result", show_label=False)
83
 
84
- with gr.Accordion("Advanced Settings", open=False):
85
  negative_prompt = gr.Text(
86
- label="Negative prompt",
87
- max_lines=1,
88
- placeholder="Enter a negative prompt",
89
- visible=False,
90
  )
91
 
92
  seed = gr.Slider(
93
- label="Seed",
94
  minimum=0,
95
  maximum=MAX_SEED,
96
  step=1,
97
  value=0,
98
  )
99
 
100
- randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
101
 
102
  with gr.Row():
103
  width = gr.Slider(
104
- label="Width",
105
  minimum=256,
106
  maximum=MAX_IMAGE_SIZE,
107
  step=32,
108
- value=1024, # Replace with defaults that work for your model
109
  )
110
 
111
  height = gr.Slider(
112
- label="Height",
113
  minimum=256,
114
  maximum=MAX_IMAGE_SIZE,
115
  step=32,
116
- value=1024, # Replace with defaults that work for your model
117
  )
118
 
119
  with gr.Row():
120
  guidance_scale = gr.Slider(
121
- label="Guidance scale",
122
  minimum=0.0,
123
  maximum=10.0,
124
  step=0.1,
125
- value=0.0, # Replace with defaults that work for your model
126
  )
127
 
128
  num_inference_steps = gr.Slider(
129
- label="Number of inference steps",
130
  minimum=1,
131
- maximum=50,
132
  step=1,
133
- value=2, # Replace with defaults that work for your model
134
  )
135
 
136
- gr.Examples(examples=examples, inputs=[prompt])
 
 
 
 
 
 
 
 
137
  gr.on(
138
  triggers=[run_button.click, prompt.submit],
139
  fn=infer,
 
7
  import torch
8
 
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
10
+ model_repo_id = "stabilityai/sdxl-turbo" # 使用SDXL-Turbo以获得更快的生成速度
11
 
12
  if torch.cuda.is_available():
13
  torch_dtype = torch.float16
 
18
  pipe = pipe.to(device)
19
 
20
  MAX_SEED = np.iinfo(np.int32).max
21
+ MAX_IMAGE_SIZE = 768 # 减小最大尺寸以提高生成速度
22
+
23
+ # 熊猫烧香相关的提示词模板
24
+ PANDA_INCENSE_PROMPTS = [
25
+ "cute panda holding incense sticks, kawaii style, soft pastel colors, adorable expression",
26
+ "adorable baby panda with burning incense, peaceful meditation, cartoon style, warm lighting",
27
+ "kawaii panda monk burning incense, temple background, cute and serene, anime style",
28
+ "fluffy panda with incense burner, traditional Chinese style, cute and peaceful",
29
+ "chibi panda holding joss sticks, temple setting, soft colors, very cute"
30
+ ]
31
+
32
+ # 负面提示词,避免不可爱的元素
33
+ DEFAULT_NEGATIVE_PROMPT = "ugly, scary, dark, horror, realistic, photographic, aggressive, angry, sad"
34
 
35
 
36
  # @spaces.GPU #[uncomment to use ZeroGPU]
 
64
 
65
 
66
  examples = [
67
+ "cute panda holding incense sticks, kawaii style, soft pastel colors, adorable expression",
68
+ "adorable baby panda with burning incense, peaceful meditation, cartoon style, warm lighting",
69
+ "kawaii panda monk burning incense, temple background, cute and serene, anime style",
70
+ "fluffy panda with incense burner, traditional Chinese style, cute and peaceful",
71
+ "chibi panda holding joss sticks, temple setting, soft colors, very cute"
72
  ]
73
 
74
  css = """
 
80
 
81
  with gr.Blocks(css=css) as demo:
82
  with gr.Column(elem_id="col-container"):
83
+ gr.Markdown("# 🐼 可爱熊猫烧香生成器")
84
+ gr.Markdown("生成可爱的熊猫烧香图片,快速且高质量!")
85
 
86
  with gr.Row():
87
  prompt = gr.Text(
88
+ label="描述",
89
  show_label=False,
90
+ max_lines=2,
91
+ placeholder="描述你想要的熊猫烧香场景,或者选择下面的示例...",
92
  container=False,
93
+ value="cute panda holding incense sticks, kawaii style, soft pastel colors, adorable expression"
94
  )
95
 
96
+ run_button = gr.Button("🎨 生成", scale=0, variant="primary")
97
+
98
+ # 添加快速选择按钮
99
+ with gr.Row():
100
+ quick_buttons = []
101
+ for i, example_prompt in enumerate(PANDA_INCENSE_PROMPTS):
102
+ btn = gr.Button(f"样式 {i+1}", size="sm", variant="secondary")
103
+ quick_buttons.append(btn)
104
 
105
  result = gr.Image(label="Result", show_label=False)
106
 
107
+ with gr.Accordion("高级设置", open=False):
108
  negative_prompt = gr.Text(
109
+ label="负面提示词",
110
+ max_lines=2,
111
+ placeholder="描述你不想要的元素",
112
+ value=DEFAULT_NEGATIVE_PROMPT,
113
  )
114
 
115
  seed = gr.Slider(
116
+ label="随机种子",
117
  minimum=0,
118
  maximum=MAX_SEED,
119
  step=1,
120
  value=0,
121
  )
122
 
123
+ randomize_seed = gr.Checkbox(label="随机种子", value=True)
124
 
125
  with gr.Row():
126
  width = gr.Slider(
127
+ label="宽度",
128
  minimum=256,
129
  maximum=MAX_IMAGE_SIZE,
130
  step=32,
131
+ value=512, # 较小尺寸以提高生成速度
132
  )
133
 
134
  height = gr.Slider(
135
+ label="高度",
136
  minimum=256,
137
  maximum=MAX_IMAGE_SIZE,
138
  step=32,
139
+ value=512, # 较小尺寸以提高生成速度
140
  )
141
 
142
  with gr.Row():
143
  guidance_scale = gr.Slider(
144
+ label="引导强度",
145
  minimum=0.0,
146
  maximum=10.0,
147
  step=0.1,
148
+ value=1.0, # 适中的引导强度
149
  )
150
 
151
  num_inference_steps = gr.Slider(
152
+ label="推理步数",
153
  minimum=1,
154
+ maximum=10,
155
  step=1,
156
+ value=4, # 更少步数以提高速度
157
  )
158
 
159
+ gr.Examples(examples=examples, inputs=[prompt], label="🎨 示例提示词")
160
+
161
+ # 为快速选择按钮添加事件处理
162
+ for i, btn in enumerate(quick_buttons):
163
+ btn.click(
164
+ fn=lambda x=PANDA_INCENSE_PROMPTS[i]: x,
165
+ outputs=[prompt]
166
+ )
167
+
168
  gr.on(
169
  triggers=[run_button.click, prompt.submit],
170
  fn=infer,
requirements.txt CHANGED
@@ -3,4 +3,5 @@ diffusers
3
  invisible_watermark
4
  torch
5
  transformers
6
- xformers
 
 
3
  invisible_watermark
4
  torch
5
  transformers
6
+ xformers
7
+ gradio