panelforge commited on
Commit
6d482fb
·
verified ·
1 Parent(s): 23a6b34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -42
app.py CHANGED
@@ -1,12 +1,12 @@
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
- import spaces #[uncomment to use ZeroGPU]
5
  from diffusers import DiffusionPipeline, DPMSolverSDEScheduler
6
  import torch
7
 
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
- model_repo_id = "John6666/wai-ani-nsfw-ponyxl-v8-sdxl" #Replace to the model you would like to use
10
 
11
  if torch.cuda.is_available():
12
  torch_dtype = torch.float16
@@ -20,24 +20,28 @@ pipe = pipe.to(device)
20
  MAX_SEED = np.iinfo(np.int32).max
21
  MAX_IMAGE_SIZE = 1024
22
 
23
- @spaces.GPU #[uncomment to use ZeroGPU]
24
- def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, progress=gr.Progress(track_tqdm=True)):
 
 
 
 
25
 
26
  if randomize_seed:
27
  seed = random.randint(0, MAX_SEED)
28
-
29
  generator = torch.Generator().manual_seed(seed)
30
-
31
  image = pipe(
32
- prompt = 'score_9, score_8_up, score_7_up,source_anime, ' + prompt,
33
- negative_prompt = 'worst quality, bad quality, jpeg artifacts, source_cartoon, 3d, (censor), monochrome, blurry, lowres, watermark, ' + negative_prompt,
34
- guidance_scale = guidance_scale,
35
- num_inference_steps = num_inference_steps,
36
- width = width,
37
- height = height,
38
- generator = generator
39
- ).images[0]
40
-
41
  return image, seed
42
 
43
  examples = [
@@ -46,22 +50,27 @@ examples = [
46
  "A delicious ceviche cheesecake slice",
47
  ]
48
 
49
- css="""
50
  #col-container {
51
  margin: 0 auto;
52
  max-width: 640px;
53
  }
54
  """
55
 
 
 
 
 
 
 
56
  with gr.Blocks(css=css) as demo:
57
-
58
  with gr.Column(elem_id="col-container"):
59
- gr.Markdown(f"""
60
  # Text-to-Image Gradio Template
61
  """)
62
-
63
  with gr.Row():
64
-
65
  prompt = gr.Text(
66
  label="Prompt",
67
  show_label=False,
@@ -69,20 +78,23 @@ with gr.Blocks(css=css) as demo:
69
  placeholder="Enter your prompt",
70
  container=False,
71
  )
72
-
73
  run_button = gr.Button("Run", scale=0)
74
-
75
  result = gr.Image(label="Result", show_label=False)
76
 
 
 
 
 
77
  with gr.Accordion("Advanced Settings", open=False):
78
-
79
  negative_prompt = gr.Text(
80
  label="Negative prompt",
81
  max_lines=1,
82
  placeholder="Enter a negative prompt",
83
  visible=False,
84
  )
85
-
86
  seed = gr.Slider(
87
  label="Seed",
88
  minimum=0,
@@ -90,54 +102,52 @@ with gr.Blocks(css=css) as demo:
90
  step=1,
91
  value=0,
92
  )
93
-
94
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
95
-
96
  with gr.Row():
97
-
98
  width = gr.Slider(
99
  label="Width",
100
  minimum=256,
101
  maximum=MAX_IMAGE_SIZE,
102
  step=32,
103
- value=1024, #Replace with defaults that work for your model
104
  )
105
-
106
  height = gr.Slider(
107
  label="Height",
108
  minimum=256,
109
  maximum=MAX_IMAGE_SIZE,
110
  step=32,
111
- value=1024, #Replace with defaults that work for your model
112
  )
113
-
114
  with gr.Row():
115
-
116
  guidance_scale = gr.Slider(
117
  label="Guidance scale",
118
  minimum=0.0,
119
  maximum=10.0,
120
  step=0.1,
121
- value=7, #Replace with defaults that work for your model
122
  )
123
-
124
  num_inference_steps = gr.Slider(
125
  label="Number of inference steps",
126
  minimum=1,
127
  maximum=50,
128
  step=1,
129
- value=35, #Replace with defaults that work for your model
130
  )
131
-
132
  gr.Examples(
133
- examples = examples,
134
- inputs = [prompt]
135
  )
136
  gr.on(
137
  triggers=[run_button.click, prompt.submit],
138
- fn = infer,
139
- inputs = [prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
140
- outputs = [result, seed]
141
  )
142
 
143
- demo.queue().launch()
 
1
  import gradio as gr
2
  import numpy as np
3
  import random
4
+ import spaces # [uncomment to use ZeroGPU]
5
  from diffusers import DiffusionPipeline, DPMSolverSDEScheduler
6
  import torch
7
 
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
+ model_repo_id = "John6666/wai-ani-nsfw-ponyxl-v8-sdxl" # Replace to the model you would like to use
10
 
11
  if torch.cuda.is_available():
12
  torch_dtype = torch.float16
 
20
  MAX_SEED = np.iinfo(np.int32).max
21
  MAX_IMAGE_SIZE = 1024
22
 
23
+ @spaces.GPU # [uncomment to use ZeroGPU]
24
+ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, tag_selection, progress=gr.Progress(track_tqdm=True)):
25
+
26
+ # Combine selected tags with the user input prompt
27
+ tags_text = ', '.join(tag_selection)
28
+ final_prompt = f'score_9, score_8_up, score_7_up,source_anime, {tags_text}, {prompt}'
29
 
30
  if randomize_seed:
31
  seed = random.randint(0, MAX_SEED)
32
+
33
  generator = torch.Generator().manual_seed(seed)
34
+
35
  image = pipe(
36
+ prompt=final_prompt,
37
+ negative_prompt='worst quality, bad quality, jpeg artifacts, source_cartoon, 3d, (censor), monochrome, blurry, lowres, watermark, ' + negative_prompt,
38
+ guidance_scale=guidance_scale,
39
+ num_inference_steps=num_inference_steps,
40
+ width=width,
41
+ height=height,
42
+ generator=generator
43
+ ).images[0]
44
+
45
  return image, seed
46
 
47
  examples = [
 
50
  "A delicious ceviche cheesecake slice",
51
  ]
52
 
53
+ css = """
54
  #col-container {
55
  margin: 0 auto;
56
  max-width: 640px;
57
  }
58
  """
59
 
60
+ # Define a list of example tags
61
+ tag_options = [
62
+ "fantasy", "sci-fi", "realistic", "cyberpunk", "noir", "surreal",
63
+ "colorful", "detailed", "high resolution", "anime style"
64
+ ]
65
+
66
  with gr.Blocks(css=css) as demo:
67
+
68
  with gr.Column(elem_id="col-container"):
69
+ gr.Markdown("""
70
  # Text-to-Image Gradio Template
71
  """)
72
+
73
  with gr.Row():
 
74
  prompt = gr.Text(
75
  label="Prompt",
76
  show_label=False,
 
78
  placeholder="Enter your prompt",
79
  container=False,
80
  )
81
+
82
  run_button = gr.Button("Run", scale=0)
83
+
84
  result = gr.Image(label="Result", show_label=False)
85
 
86
+ with gr.Row():
87
+ # Checkbox group for selectable tags
88
+ tag_selection = gr.CheckboxGroup(choices=tag_options, label="Select Tags")
89
+
90
  with gr.Accordion("Advanced Settings", open=False):
 
91
  negative_prompt = gr.Text(
92
  label="Negative prompt",
93
  max_lines=1,
94
  placeholder="Enter a negative prompt",
95
  visible=False,
96
  )
97
+
98
  seed = gr.Slider(
99
  label="Seed",
100
  minimum=0,
 
102
  step=1,
103
  value=0,
104
  )
105
+
106
  randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
107
+
108
  with gr.Row():
 
109
  width = gr.Slider(
110
  label="Width",
111
  minimum=256,
112
  maximum=MAX_IMAGE_SIZE,
113
  step=32,
114
+ value=1024, # Replace with defaults that work for your model
115
  )
116
+
117
  height = gr.Slider(
118
  label="Height",
119
  minimum=256,
120
  maximum=MAX_IMAGE_SIZE,
121
  step=32,
122
+ value=1024, # Replace with defaults that work for your model
123
  )
124
+
125
  with gr.Row():
 
126
  guidance_scale = gr.Slider(
127
  label="Guidance scale",
128
  minimum=0.0,
129
  maximum=10.0,
130
  step=0.1,
131
+ value=7, # Replace with defaults that work for your model
132
  )
133
+
134
  num_inference_steps = gr.Slider(
135
  label="Number of inference steps",
136
  minimum=1,
137
  maximum=50,
138
  step=1,
139
+ value=35, # Replace with defaults that work for your model
140
  )
141
+
142
  gr.Examples(
143
+ examples=examples,
144
+ inputs=[prompt]
145
  )
146
  gr.on(
147
  triggers=[run_button.click, prompt.submit],
148
+ fn=infer,
149
+ inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps, tag_selection],
150
+ outputs=[result, seed]
151
  )
152
 
153
+ demo.queue().launch()