Abiru commited on
Commit
e2ee1af
1 Parent(s): 63f7b3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -1,3 +1,27 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- gr.load("models/UnfilteredAI/NSFW-gen-v2").launch()
 
1
  import gradio as gr
2
+ from diffusers import DiffusionPipeline
3
+ import random
4
+
5
+ pipe = DiffusionPipeline.from_pretrained("models/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.inputs.Textbox(label="Prompt", default="A fantasy landscape", lines=2),
18
+ gr.inputs.Textbox(label="Negative Prompt", default="", lines=2),
19
+ gr.inputs.Slider(minimum=256, maximum=1024, step=64, default=1024, label="Height"),
20
+ gr.inputs.Slider(minimum=256, maximum=1024, step=64, default=1024, label="Width"),
21
+ gr.inputs.Number(default=None, label="Seed", optional=True)
22
+ ]
23
+
24
+ outputs = gr.outputs.Image(type="pil", label="Generated Image")
25
+
26
+ gr.Interface(fn=generate_image, inputs=inputs, outputs=outputs, title="Stable Diffusion Image Generator").launch()
27