votepurchase commited on
Commit
68bc475
1 Parent(s): a9915cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +129 -1
app.py CHANGED
@@ -1,3 +1,131 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
2
 
3
- gr.load("models/votepurchase/juggernautXL_hyper_8step_sfw").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import numpy as np
3
+ import PIL.Image
4
+ from PIL import Image
5
+ import random
6
+ from diffusers import ControlNetModel, StableDiffusionXLPipeline, AutoencoderKL
7
+ from diffusers import DDIMScheduler, EulerAncestralDiscreteScheduler
8
+ import cv2
9
+ import torch
10
+ import spaces
11
 
12
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
13
+
14
+ pipe = StableDiffusionXLPipeline.from_pretrained(
15
+ "votepurchase/juggernautXL_hyper_8step_sfw",
16
+ torch_dtype=torch.float16,
17
+ use_safetensors=True,
18
+ )
19
+
20
+ pipe.scheduler = EulerAncestralDiscreteScheduler.from_config(pipe.scheduler.config)
21
+ pipe.to(device)
22
+
23
+ MAX_SEED = np.iinfo(np.int32).max
24
+ MAX_IMAGE_SIZE = 1216
25
+
26
+
27
+ @spaces.GPU
28
+ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
29
+
30
+ if randomize_seed:
31
+ seed = random.randint(0, MAX_SEED)
32
+
33
+ generator = torch.Generator().manual_seed(seed)
34
+
35
+ output_image = pipe(
36
+ prompt=prompt,
37
+ negative_prompt=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 output_image
46
+
47
+
48
+ css = """
49
+ #col-container {
50
+ margin: 0 auto;
51
+ max-width: 520px;
52
+ }
53
+ """
54
+
55
+ with gr.Blocks(css=css) as demo:
56
+
57
+ with gr.Column(elem_id="col-container"):
58
+
59
+ with gr.Row():
60
+ prompt = gr.Text(
61
+ label="Prompt",
62
+ show_label=False,
63
+ max_lines=1,
64
+ placeholder="Enter your prompt",
65
+ container=False,
66
+ )
67
+
68
+ run_button = gr.Button("Run", scale=0)
69
+
70
+ result = gr.Image(label="Result", show_label=False)
71
+
72
+ with gr.Accordion("Advanced Settings", open=False):
73
+
74
+ negative_prompt = gr.Text(
75
+ label="Negative prompt",
76
+ max_lines=1,
77
+ placeholder="Enter a negative prompt",
78
+ value="nsfw, (low quality, worst quality:1.2), very displeasing, 3d, watermark, signature, ugly, poorly drawn"
79
+ )
80
+
81
+ seed = gr.Slider(
82
+ label="Seed",
83
+ minimum=0,
84
+ maximum=MAX_SEED,
85
+ step=1,
86
+ value=0,
87
+ )
88
+
89
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
90
+
91
+ with gr.Row():
92
+ width = gr.Slider(
93
+ label="Width",
94
+ minimum=256,
95
+ maximum=MAX_IMAGE_SIZE,
96
+ step=32,
97
+ value=1024,#832,
98
+ )
99
+
100
+ height = gr.Slider(
101
+ label="Height",
102
+ minimum=256,
103
+ maximum=MAX_IMAGE_SIZE,
104
+ step=32,
105
+ value=1024,#1216,
106
+ )
107
+
108
+ with gr.Row():
109
+ guidance_scale = gr.Slider(
110
+ label="Guidance scale",
111
+ minimum=0.0,
112
+ maximum=20.0,
113
+ step=0.1,
114
+ value=7,
115
+ )
116
+
117
+ num_inference_steps = gr.Slider(
118
+ label="Number of inference steps",
119
+ minimum=1,
120
+ maximum=28,
121
+ step=1,
122
+ value=28,
123
+ )
124
+
125
+ run_button.click(#lambda x: None, inputs=None, outputs=result).then(
126
+ fn=infer,
127
+ inputs=[prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps],
128
+ outputs=[result]
129
+ )
130
+
131
+ demo.queue().launch()