Abiru commited on
Commit
7d62036
1 Parent(s): b70eca1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -19
app.py CHANGED
@@ -1,27 +1,33 @@
1
  import gradio as gr
2
  from diffusers import DiffusionPipeline
3
  import random
 
4
 
5
  pipe = DiffusionPipeline.from_pretrained("UnfilteredAI/NSFW-gen-v2")
6
 
7
- def generate_image(prompt, negative_prompt="", height=1024, width=1024, seed=None):
8
- generator = None
9
- if seed is not None:
10
- generator = torch.Generator(device="cuda").manual_seed(seed)
11
-
12
- images = pipe(prompt, negative_prompt=negative_prompt, height=height, width=width, generator=generator).images
13
- return images[0]
 
 
 
 
14
 
15
- # Define the Gradio interface
16
- inputs = [
17
- gr.Textbox(label="Prompt", default="A fantasy landscape", lines=2),
18
- gr.Textbox(label="Negative Prompt", default="", lines=2),
19
- gr.Slider(minimum=256, maximum=1024, step=64, default=1024, label="Height"),
20
- gr.Slider(minimum=256, maximum=1024, step=64, default=1024, label="Width"),
21
- gr.Number(default=None, label="Seed", optional=True)
22
- ]
23
 
24
- outputs = gr.Image(type="pil", label="Generated Image")
25
-
26
- c = gr.Interface(fn=generate_image, inputs=inputs, outputs=outputs, title="NSFW-Gen 2 Image Generator").launch()
27
- c.launch()
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from diffusers import DiffusionPipeline
3
  import random
4
+ import spaces
5
 
6
  pipe = DiffusionPipeline.from_pretrained("UnfilteredAI/NSFW-gen-v2")
7
 
8
+ @spaces.GPU
9
+ def generate(prompt, negative_prompt, num_inference_steps, guidance_scale, width, height, num_samples):
10
+ return pipe(
11
+ prompt=prompt
12
+ negative_prompt=negative_prompt,
13
+ num_inference_steps=num_inference_steps,
14
+ guidance_scale=guidance_scale,
15
+ width=width,
16
+ height=height,
17
+ num_images_per_prompt=num_samples
18
+ ).images
19
 
 
 
 
 
 
 
 
 
20
 
21
+ gr.Interface(
22
+ fn=generate,
23
+ inputs=[
24
+ gr.Text(label="Prompt"),
25
+ gr.Text("", label="Negative Prompt"),
26
+ gr.Number(7, label="Number inference steps"),
27
+ gr.Number(3, label="Guidance scale"),
28
+ gr.Number(512, label="Width"),
29
+ gr.Number(512, label="Height"),
30
+ gr.Number(1, label="# images"),
31
+ ],
32
+ outputs=gr.Gallery(),
33
+ ).launch()