Spaces:
Running
Running
JV A
commited on
Commit
·
74c18cc
1
Parent(s):
680cac7
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,8 +4,9 @@ import json
|
|
| 4 |
import PIL.Image
|
| 5 |
from io import BytesIO
|
| 6 |
import os
|
|
|
|
| 7 |
|
| 8 |
-
def generate_image(prompt, negative_prompt, scheduler, steps, width, height, restore_faces):
|
| 9 |
# Define the API endpoint
|
| 10 |
apiUrl = os.getenv("API_URL")
|
| 11 |
token = os.getenv("API_TOKEN")
|
|
@@ -23,11 +24,11 @@ def generate_image(prompt, negative_prompt, scheduler, steps, width, height, res
|
|
| 23 |
"batch_size": 1,
|
| 24 |
"prompt": prompt,
|
| 25 |
"negative_prompt": negative_prompt,
|
| 26 |
-
"seed":
|
| 27 |
"scheduler": scheduler,
|
| 28 |
"n_iter": 1,
|
| 29 |
"steps": steps,
|
| 30 |
-
"cfg":
|
| 31 |
"offset_noise": 0.0,
|
| 32 |
"width": width,
|
| 33 |
"height": height,
|
|
@@ -75,7 +76,7 @@ def generate_image(prompt, negative_prompt, scheduler, steps, width, height, res
|
|
| 75 |
image = PIL.Image.open(BytesIO(image_response.content))
|
| 76 |
|
| 77 |
return image
|
| 78 |
-
|
| 79 |
raise Exception("API request failed with status code " + str(response.status_code))
|
| 80 |
|
| 81 |
# Define the Gradio interface
|
|
@@ -83,7 +84,7 @@ iface = gr.Interface(
|
|
| 83 |
fn=generate_image,
|
| 84 |
inputs=[
|
| 85 |
gr.components.Textbox(label="Prompt"),
|
| 86 |
-
gr.components.Textbox(label="Negative Prompt"),
|
| 87 |
gr.components.Dropdown(choices=[
|
| 88 |
"Euler a",
|
| 89 |
"Euler",
|
|
@@ -105,10 +106,12 @@ iface = gr.Interface(
|
|
| 105 |
"DDIM",
|
| 106 |
"PLMS"
|
| 107 |
], label="Scheduler", default="Euler a"),
|
| 108 |
-
gr.components.Slider(minimum=10, maximum=
|
| 109 |
-
gr.components.Slider(minimum=512, maximum=
|
| 110 |
-
gr.components.Slider(minimum=512, maximum=
|
| 111 |
-
gr.components.Checkbox(label="Restore Faces")
|
|
|
|
|
|
|
| 112 |
],
|
| 113 |
outputs=gr.components.Image(),
|
| 114 |
title="Freedom Demonstration",
|
|
|
|
| 4 |
import PIL.Image
|
| 5 |
from io import BytesIO
|
| 6 |
import os
|
| 7 |
+
import random
|
| 8 |
|
| 9 |
+
def generate_image(prompt, negative_prompt, scheduler, steps, width, height, restore_faces, seed, cfg):
|
| 10 |
# Define the API endpoint
|
| 11 |
apiUrl = os.getenv("API_URL")
|
| 12 |
token = os.getenv("API_TOKEN")
|
|
|
|
| 24 |
"batch_size": 1,
|
| 25 |
"prompt": prompt,
|
| 26 |
"negative_prompt": negative_prompt,
|
| 27 |
+
"seed": seed if seed else random.randint(0, 999999999),
|
| 28 |
"scheduler": scheduler,
|
| 29 |
"n_iter": 1,
|
| 30 |
"steps": steps,
|
| 31 |
+
"cfg": cfg,
|
| 32 |
"offset_noise": 0.0,
|
| 33 |
"width": width,
|
| 34 |
"height": height,
|
|
|
|
| 76 |
image = PIL.Image.open(BytesIO(image_response.content))
|
| 77 |
|
| 78 |
return image
|
| 79 |
+
else:
|
| 80 |
raise Exception("API request failed with status code " + str(response.status_code))
|
| 81 |
|
| 82 |
# Define the Gradio interface
|
|
|
|
| 84 |
fn=generate_image,
|
| 85 |
inputs=[
|
| 86 |
gr.components.Textbox(label="Prompt"),
|
| 87 |
+
gr.components.Textbox(default="ugly, tiling, poorlydrawn hands, poorly drawn feet, poorly drawn face, out of frame, extra limbs, disfigured, deformed, body out of frame, blurry, bad anatomy, blurred, watermark, grainy, signature, cut off, draft", label="Negative Prompt"),
|
| 88 |
gr.components.Dropdown(choices=[
|
| 89 |
"Euler a",
|
| 90 |
"Euler",
|
|
|
|
| 106 |
"DDIM",
|
| 107 |
"PLMS"
|
| 108 |
], label="Scheduler", default="Euler a"),
|
| 109 |
+
gr.components.Slider(minimum=10, maximum=100, default=30, label="Steps"),
|
| 110 |
+
gr.components.Slider(minimum=512, maximum=1600, default=768, label="Width"),
|
| 111 |
+
gr.components.Slider(minimum=512, maximum=1600, default=768, label="Height"),
|
| 112 |
+
gr.components.Checkbox(label="Restore Faces"),
|
| 113 |
+
gr.components.Number(label="Seed", default=None),
|
| 114 |
+
gr.components.Slider(minimum=4, maximum=12, default==7.0, label="CFG")
|
| 115 |
],
|
| 116 |
outputs=gr.components.Image(),
|
| 117 |
title="Freedom Demonstration",
|