Spaces:
Runtime error
Runtime error
add pdr options
Browse files- README.md +1 -1
- app.py +17 -10
- env-sample +4 -1
README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
---
|
2 |
-
title: PDR
|
3 |
emoji: 👁️
|
4 |
colorFrom: yellow
|
5 |
colorTo: red
|
|
|
1 |
---
|
2 |
+
title: PDR Stable Diffusion
|
3 |
emoji: 👁️
|
4 |
colorFrom: yellow
|
5 |
colorTo: red
|
app.py
CHANGED
@@ -69,9 +69,9 @@ def update_labels(show_labels):
|
|
69 |
updated_gallery = [(path, label if show_labels else "") for path, label in zip(image_paths_global, image_labels_global)]
|
70 |
return updated_gallery
|
71 |
|
72 |
-
def generate_images_wrapper(prompts, pw, model, show_labels):
|
73 |
global image_paths_global, image_labels_global
|
74 |
-
image_paths, image_labels = generate_images(prompts, pw, model)
|
75 |
image_paths_global = image_paths
|
76 |
|
77 |
# store this as a global so we can handle toggle state
|
@@ -108,7 +108,7 @@ def download_all_images():
|
|
108 |
image_labels_global = [] # Reset the global variable
|
109 |
return zip_path
|
110 |
|
111 |
-
def generate_images(prompts, pw, model):
|
112 |
# Check for a valid password
|
113 |
|
114 |
if pw != os.getenv("PW"):
|
@@ -143,13 +143,13 @@ def generate_images(prompts, pw, model):
|
|
143 |
response = replicate.run(
|
144 |
"stability-ai/stable-diffusion:ac732df83cea7fff18b8472768c88ad041fa750ff7682a21affe81863cbe77e4",
|
145 |
input={
|
146 |
-
"width":
|
147 |
-
"height":
|
148 |
"prompt": prompt_w_challenge,
|
149 |
-
"scheduler":
|
150 |
"num_outputs": 1, #images to generate
|
151 |
-
"guidance_scale":
|
152 |
-
"num_inference_steps":
|
153 |
}
|
154 |
)
|
155 |
print(response)
|
@@ -257,6 +257,13 @@ with gr.Blocks(css=css) as demo:
|
|
257 |
text = gr.Textbox(label="What do you want to create?", placeholder="Enter your text and then click on the \"Image Generate\" button")
|
258 |
with gr.Column(scale=1):
|
259 |
model = gr.Dropdown(choices=["stable-diffusion"], label="Model", value="stable-diffusion")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
260 |
with gr.Row():
|
261 |
btn = gr.Button("Generate Images")
|
262 |
|
@@ -280,8 +287,8 @@ with gr.Blocks(css=css) as demo:
|
|
280 |
|
281 |
#submissions
|
282 |
#trigger generation either through hitting enter in the text field, or clicking the button.
|
283 |
-
btn.click(fn=generate_images_wrapper, inputs=[text, pw, model, show_labels], outputs=output_images, api_name=False)
|
284 |
-
text.submit(fn=generate_images_wrapper, inputs=[text, pw, model, show_labels], outputs=output_images, api_name="generate_image") # Generate an api endpoint in Gradio / HF
|
285 |
show_labels.change(fn=update_labels, inputs=[show_labels], outputs=[output_images])
|
286 |
|
287 |
#downloads
|
|
|
69 |
updated_gallery = [(path, label if show_labels else "") for path, label in zip(image_paths_global, image_labels_global)]
|
70 |
return updated_gallery
|
71 |
|
72 |
+
def generate_images_wrapper(prompts, pw, model, show_labels,size, guidance, steps, scheduler):
|
73 |
global image_paths_global, image_labels_global
|
74 |
+
image_paths, image_labels = generate_images(prompts, pw, model,size,guidance,steps,scheduler)
|
75 |
image_paths_global = image_paths
|
76 |
|
77 |
# store this as a global so we can handle toggle state
|
|
|
108 |
image_labels_global = [] # Reset the global variable
|
109 |
return zip_path
|
110 |
|
111 |
+
def generate_images(prompts, pw, model,size,guidance,steps,scheduler):
|
112 |
# Check for a valid password
|
113 |
|
114 |
if pw != os.getenv("PW"):
|
|
|
143 |
response = replicate.run(
|
144 |
"stability-ai/stable-diffusion:ac732df83cea7fff18b8472768c88ad041fa750ff7682a21affe81863cbe77e4",
|
145 |
input={
|
146 |
+
"width": int(size), #must be multiples of 64
|
147 |
+
"height": int(size),
|
148 |
"prompt": prompt_w_challenge,
|
149 |
+
"scheduler": scheduler, #controlling the steps of the diffusion process to balance between image quality, generation speed, and resource consumption - DDIM, K_EULER, DPMSolverMultistep, K_EULER_ANCESTRAL, PNDM, KLMS
|
150 |
"num_outputs": 1, #images to generate
|
151 |
+
"guidance_scale": int(guidance), #0-20, higher the number, more it sticks to the prompt
|
152 |
+
"num_inference_steps": int(steps) #1-500 - higher the better, generally
|
153 |
}
|
154 |
)
|
155 |
print(response)
|
|
|
257 |
text = gr.Textbox(label="What do you want to create?", placeholder="Enter your text and then click on the \"Image Generate\" button")
|
258 |
with gr.Column(scale=1):
|
259 |
model = gr.Dropdown(choices=["stable-diffusion"], label="Model", value="stable-diffusion")
|
260 |
+
with gr.Row():
|
261 |
+
with gr.Column():
|
262 |
+
size = gr.Dropdown(choices=[512,768,1024], label="Size", value=768)
|
263 |
+
scheduler = gr.Dropdown(choices=["DDIM", "K_EULER", "DPMSolverMultistep", "K_EULER_ANCESTRAL", "PNDM", "KLMS"], label="Scheduler", value="K_EULER", info="attempt to balance between image quality, generation speed, and resource consumption")
|
264 |
+
with gr.Column():
|
265 |
+
guidance = gr.Slider(minimum=0, maximum=20, value=7, step=1,label="Guidance",info="0-20, higher the number, more it sticks to the prompt")
|
266 |
+
steps = gr.Slider(minimum=10, maximum=500, value=50, step=10,label="Steps",info="10-500 - higher = better quality, lower = faster")
|
267 |
with gr.Row():
|
268 |
btn = gr.Button("Generate Images")
|
269 |
|
|
|
287 |
|
288 |
#submissions
|
289 |
#trigger generation either through hitting enter in the text field, or clicking the button.
|
290 |
+
btn.click(fn=generate_images_wrapper, inputs=[text, pw, model, show_labels, size, guidance, steps, scheduler ], outputs=output_images, api_name=False)
|
291 |
+
text.submit(fn=generate_images_wrapper, inputs=[text, pw, model, show_labels, size, guidance, steps, scheduler], outputs=output_images, api_name="generate_image") # Generate an api endpoint in Gradio / HF
|
292 |
show_labels.change(fn=update_labels, inputs=[show_labels], outputs=[output_images])
|
293 |
|
294 |
#downloads
|
env-sample
CHANGED
@@ -1,2 +1,5 @@
|
|
1 |
OPENAI_API_KEY = <YOUR_OPENAI_API_KEY>
|
2 |
-
PW = <YOUR_PW>
|
|
|
|
|
|
|
|
1 |
OPENAI_API_KEY = <YOUR_OPENAI_API_KEY>
|
2 |
+
PW = <YOUR_PW>
|
3 |
+
REPLICATE_API_TOKEN=<YOUR_REPLICATE_API_KEY>
|
4 |
+
MODE=dev
|
5 |
+
MONGO_URI=<YOUR_MONGO_URI>
|