Spaces:
Running
Running
Commit
·
821924e
1
Parent(s):
e221206
remove useless stuff
Browse files
app.py
CHANGED
@@ -38,31 +38,23 @@ def encode_image(image_path):
|
|
38 |
@spaces.GPU #[uncomment to use ZeroGPU]
|
39 |
def infer(
|
40 |
prompt,
|
41 |
-
negative_prompt,
|
42 |
-
seed,
|
43 |
-
randomize_seed,
|
44 |
-
width,
|
45 |
-
height,
|
46 |
-
guidance_scale,
|
47 |
-
num_inference_steps,
|
48 |
progress=gr.Progress(track_tqdm=True),
|
49 |
):
|
50 |
-
|
51 |
-
seed = random.randint(0, MAX_SEED)
|
52 |
|
53 |
-
generator = torch.Generator().manual_seed(seed)
|
54 |
|
55 |
image = pipe(
|
56 |
prompt=prompt,
|
57 |
-
negative_prompt=negative_prompt,
|
58 |
guidance_scale=0.,
|
59 |
num_inference_steps=4,
|
60 |
width=1420,
|
61 |
height=1080,
|
62 |
max_sequence_length=256,
|
|
|
63 |
).images[0]
|
64 |
|
65 |
-
return image
|
66 |
|
67 |
@spaces.GPU #[uncomment to use ZeroGPU]
|
68 |
def generate_description_fn(
|
@@ -96,12 +88,6 @@ def generate_description_fn(
|
|
96 |
return chat_completion.choices[0].message.content
|
97 |
|
98 |
|
99 |
-
examples = [
|
100 |
-
"Astronaut in a jungle, cold color palette, muted colors, detailed, 8k",
|
101 |
-
"An astronaut riding a green horse",
|
102 |
-
"A delicious ceviche cheesecake slice",
|
103 |
-
]
|
104 |
-
|
105 |
css = """
|
106 |
#col-container {
|
107 |
margin: 0 auto;
|
@@ -134,73 +120,13 @@ with gr.Blocks(css=css) as demo:
|
|
134 |
|
135 |
result = gr.Image(label="Result", show_label=False)
|
136 |
|
137 |
-
with gr.Accordion("Advanced Settings", open=False):
|
138 |
-
negative_prompt = gr.Text(
|
139 |
-
label="Negative prompt",
|
140 |
-
max_lines=1,
|
141 |
-
placeholder="Enter a negative prompt",
|
142 |
-
visible=False,
|
143 |
-
)
|
144 |
-
|
145 |
-
seed = gr.Slider(
|
146 |
-
label="Seed",
|
147 |
-
minimum=0,
|
148 |
-
maximum=MAX_SEED,
|
149 |
-
step=1,
|
150 |
-
value=0,
|
151 |
-
)
|
152 |
-
|
153 |
-
randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
|
154 |
-
|
155 |
-
with gr.Row():
|
156 |
-
width = gr.Slider(
|
157 |
-
label="Width",
|
158 |
-
minimum=256,
|
159 |
-
maximum=MAX_IMAGE_SIZE,
|
160 |
-
step=32,
|
161 |
-
value=1024, # Replace with defaults that work for your model
|
162 |
-
)
|
163 |
-
|
164 |
-
height = gr.Slider(
|
165 |
-
label="Height",
|
166 |
-
minimum=256,
|
167 |
-
maximum=MAX_IMAGE_SIZE,
|
168 |
-
step=32,
|
169 |
-
value=1024, # Replace with defaults that work for your model
|
170 |
-
)
|
171 |
-
|
172 |
-
with gr.Row():
|
173 |
-
guidance_scale = gr.Slider(
|
174 |
-
label="Guidance scale",
|
175 |
-
minimum=0.0,
|
176 |
-
maximum=10.0,
|
177 |
-
step=0.1,
|
178 |
-
value=0.0, # Replace with defaults that work for your model
|
179 |
-
)
|
180 |
-
|
181 |
-
num_inference_steps = gr.Slider(
|
182 |
-
label="Number of inference steps",
|
183 |
-
minimum=1,
|
184 |
-
maximum=50,
|
185 |
-
step=1,
|
186 |
-
value=2, # Replace with defaults that work for your model
|
187 |
-
)
|
188 |
-
|
189 |
-
gr.Examples(examples=examples, inputs=[prompt])
|
190 |
gr.on(
|
191 |
triggers=[run_button.click, prompt.submit],
|
192 |
fn=infer,
|
193 |
inputs=[
|
194 |
prompt,
|
195 |
-
negative_prompt,
|
196 |
-
seed,
|
197 |
-
randomize_seed,
|
198 |
-
width,
|
199 |
-
height,
|
200 |
-
guidance_scale,
|
201 |
-
num_inference_steps,
|
202 |
],
|
203 |
-
outputs=[result
|
204 |
)
|
205 |
|
206 |
gr.on(
|
|
|
38 |
@spaces.GPU #[uncomment to use ZeroGPU]
|
39 |
def infer(
|
40 |
prompt,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
progress=gr.Progress(track_tqdm=True),
|
42 |
):
|
43 |
+
# seed = random.randint(0, MAX_SEED)
|
|
|
44 |
|
45 |
+
# generator = torch.Generator().manual_seed(seed)
|
46 |
|
47 |
image = pipe(
|
48 |
prompt=prompt,
|
|
|
49 |
guidance_scale=0.,
|
50 |
num_inference_steps=4,
|
51 |
width=1420,
|
52 |
height=1080,
|
53 |
max_sequence_length=256,
|
54 |
+
|
55 |
).images[0]
|
56 |
|
57 |
+
return image
|
58 |
|
59 |
@spaces.GPU #[uncomment to use ZeroGPU]
|
60 |
def generate_description_fn(
|
|
|
88 |
return chat_completion.choices[0].message.content
|
89 |
|
90 |
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
css = """
|
92 |
#col-container {
|
93 |
margin: 0 auto;
|
|
|
120 |
|
121 |
result = gr.Image(label="Result", show_label=False)
|
122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
gr.on(
|
124 |
triggers=[run_button.click, prompt.submit],
|
125 |
fn=infer,
|
126 |
inputs=[
|
127 |
prompt,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
],
|
129 |
+
outputs=[result],
|
130 |
)
|
131 |
|
132 |
gr.on(
|