Spaces:
Running
Running
JV A
commited on
Commit
·
f27f103
1
Parent(s):
c254f78
Update app.py
Browse files
app.py
CHANGED
@@ -6,15 +6,15 @@ 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 |
restore_faces = bool(restore_faces)
|
11 |
print(f"restore_faces: {restore_faces}, type: {type(restore_faces)}")
|
12 |
# Define the API endpoint
|
13 |
-
apiUrl =
|
14 |
# Define the request headers
|
15 |
headers = {
|
16 |
"Content-Type": "application/json",
|
17 |
-
"token": "
|
18 |
}
|
19 |
|
20 |
# Define the request body
|
@@ -64,7 +64,6 @@ def generate_image(prompt, negative_prompt, scheduler, steps, width, height, res
|
|
64 |
"controlnet_threshold_b": 200,
|
65 |
}
|
66 |
|
67 |
-
|
68 |
# Send the request
|
69 |
response = requests.post(apiUrl, headers=headers, data=json.dumps(body), verify=False)
|
70 |
# Print the response body if the status code is not 200
|
@@ -79,8 +78,7 @@ def generate_image(prompt, negative_prompt, scheduler, steps, width, height, res
|
|
79 |
if 'results' in response_json and isinstance(response_json['results'], list) and len(response_json['results']) > 0:
|
80 |
image_url = response_json['results'][0]
|
81 |
|
82 |
-
# Get the image from the URL
|
83 |
-
image_response = requests.get(image_url)
|
84 |
image = PIL.Image.open(BytesIO(image_response.content))
|
85 |
|
86 |
return image
|
@@ -115,13 +113,13 @@ iface = gr.Interface(
|
|
115 |
"DPM++ SDE Karras",
|
116 |
"DDIM",
|
117 |
"PLMS"
|
118 |
-
], label="Scheduler", default="
|
119 |
gr.components.Slider(minimum=10, maximum=100, step=1.0,default=30, label="Steps"),
|
120 |
gr.components.Slider(minimum=512, maximum=1600, default=768, label="Width"),
|
121 |
gr.components.Slider(minimum=512, maximum=1600, default=768, label="Height"),
|
122 |
gr.components.Slider(minimum=4, maximum=12, step=0.5, default=7.0, label="CFG"),
|
123 |
gr.components.Number(label="Seed", default=None),
|
124 |
-
gr.inputs.Checkbox(label="Restore Faces"),
|
125 |
],
|
126 |
outputs=gr.components.Image(),
|
127 |
title="Freedom Demonstration",
|
@@ -143,4 +141,4 @@ Thanks to [Redmond.ai](LINK_TO_REDMOND.AI) for providing GPU Time and sponsoring
|
|
143 |
)
|
144 |
|
145 |
# Launch the app
|
146 |
-
iface.launch(debug=True)
|
|
|
6 |
import os
|
7 |
import random
|
8 |
|
9 |
+
def generate_image(prompt, negative_prompt, scheduler, steps, width, height, restore_faces, seed, cfg):
|
10 |
restore_faces = bool(restore_faces)
|
11 |
print(f"restore_faces: {restore_faces}, type: {type(restore_faces)}")
|
12 |
# Define the API endpoint
|
13 |
+
apiUrl = os.getenv("API_URL")
|
14 |
# Define the request headers
|
15 |
headers = {
|
16 |
"Content-Type": "application/json",
|
17 |
+
"token": os.getenv("API_TOKEN")
|
18 |
}
|
19 |
|
20 |
# Define the request body
|
|
|
64 |
"controlnet_threshold_b": 200,
|
65 |
}
|
66 |
|
|
|
67 |
# Send the request
|
68 |
response = requests.post(apiUrl, headers=headers, data=json.dumps(body), verify=False)
|
69 |
# Print the response body if the status code is not 200
|
|
|
78 |
if 'results' in response_json and isinstance(response_json['results'], list) and len(response_json['results']) > 0:
|
79 |
image_url = response_json['results'][0]
|
80 |
|
81 |
+
# Get the image from the URL image_response = requests.get(image_url)
|
|
|
82 |
image = PIL.Image.open(BytesIO(image_response.content))
|
83 |
|
84 |
return image
|
|
|
113 |
"DPM++ SDE Karras",
|
114 |
"DDIM",
|
115 |
"PLMS"
|
116 |
+
], label="Scheduler", default="DPM++ SDE Karras"),
|
117 |
gr.components.Slider(minimum=10, maximum=100, step=1.0,default=30, label="Steps"),
|
118 |
gr.components.Slider(minimum=512, maximum=1600, default=768, label="Width"),
|
119 |
gr.components.Slider(minimum=512, maximum=1600, default=768, label="Height"),
|
120 |
gr.components.Slider(minimum=4, maximum=12, step=0.5, default=7.0, label="CFG"),
|
121 |
gr.components.Number(label="Seed", default=None),
|
122 |
+
gr.inputs.Checkbox(label="Restore Faces", default=False),
|
123 |
],
|
124 |
outputs=gr.components.Image(),
|
125 |
title="Freedom Demonstration",
|
|
|
141 |
)
|
142 |
|
143 |
# Launch the app
|
144 |
+
iface.launch(debug=True)
|