Spaces:
Running
Running
JV A
commited on
Commit
·
8543bbc
1
Parent(s):
d47faed
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,10 +6,9 @@ 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 =
|
| 12 |
-
token = os.getenv("API_TOKEN")
|
| 13 |
# Define the request headers
|
| 14 |
headers = {
|
| 15 |
"Content-Type": "application/json",
|
|
@@ -54,13 +53,7 @@ def generate_image(prompt, negative_prompt, scheduler, steps, width, height, res
|
|
| 54 |
"controlnet_weight": 1,
|
| 55 |
"controlnet_guidance_start": 0,
|
| 56 |
"controlnet_guidance_end": 1,
|
| 57 |
-
"controlnet_ref_img_url": "
|
| 58 |
-
"controlnet_mask": [],
|
| 59 |
-
"controlnet_resize_mode": "Scale to Fit (Inner Fit)",
|
| 60 |
-
"controlnet_lowvram": False,
|
| 61 |
-
"controlnet_processor_res": 512,
|
| 62 |
-
"controlnet_threshold_a": 100,
|
| 63 |
-
"controlnet_threshold_b": 200
|
| 64 |
}
|
| 65 |
|
| 66 |
# Send the request
|
|
@@ -68,18 +61,19 @@ def generate_image(prompt, negative_prompt, scheduler, steps, width, height, res
|
|
| 68 |
|
| 69 |
# Check the response status
|
| 70 |
if response.status_code == 200:
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
else:
|
| 84 |
raise Exception("API request failed with status code " + str(response.status_code))
|
| 85 |
|
|
@@ -89,7 +83,6 @@ iface = gr.Interface(
|
|
| 89 |
inputs=[
|
| 90 |
gr.components.Textbox(label="Prompt"),
|
| 91 |
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"),
|
| 92 |
-
gr.components.Slider(minimum=10, maximum=100, step=1.0,default=30, label="Steps"),
|
| 93 |
gr.components.Dropdown(choices=[
|
| 94 |
"Euler a",
|
| 95 |
"Euler",
|
|
@@ -111,11 +104,13 @@ iface = gr.Interface(
|
|
| 111 |
"DDIM",
|
| 112 |
"PLMS"
|
| 113 |
], label="Scheduler", default="Euler a"),
|
|
|
|
| 114 |
gr.components.Slider(minimum=512, maximum=1600, default=768, label="Width"),
|
| 115 |
gr.components.Slider(minimum=512, maximum=1600, default=768, label="Height"),
|
| 116 |
gr.components.Slider(minimum=4, maximum=12, step=0.5, default=7.0, label="CFG"),
|
| 117 |
gr.components.Number(label="Seed", default=None),
|
| 118 |
gr.components.Checkbox(label="Restore Faces"),
|
|
|
|
| 119 |
],
|
| 120 |
outputs=gr.components.Image(),
|
| 121 |
title="Freedom Demonstration",
|
|
|
|
| 6 |
import os
|
| 7 |
import random
|
| 8 |
|
| 9 |
+
def generate_image(prompt, negative_prompt, scheduler, steps, width, height, restore_faces, seed, cfg, token):
|
| 10 |
# Define the API endpoint
|
| 11 |
+
apiUrl = "https://apiv2.makeai.run/v2/txt2img"
|
|
|
|
| 12 |
# Define the request headers
|
| 13 |
headers = {
|
| 14 |
"Content-Type": "application/json",
|
|
|
|
| 53 |
"controlnet_weight": 1,
|
| 54 |
"controlnet_guidance_start": 0,
|
| 55 |
"controlnet_guidance_end": 1,
|
| 56 |
+
"controlnet_ref_img_url": "",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
}
|
| 58 |
|
| 59 |
# Send the request
|
|
|
|
| 61 |
|
| 62 |
# Check the response status
|
| 63 |
if response.status_code == 200:
|
| 64 |
+
|
| 65 |
+
# Get the image URL from the response
|
| 66 |
+
response_json = response.json()
|
| 67 |
+
if 'results' in response_json and isinstance(response_json['results'], list) and len(response_json['results']) > 0:
|
| 68 |
+
image_url = response_json['results'][0]
|
| 69 |
|
| 70 |
+
# Get the image from the URL
|
| 71 |
+
image_response = requests.get(image_url)
|
| 72 |
+
image = PIL.Image.open(BytesIO(image_response.content))
|
| 73 |
|
| 74 |
+
return image
|
| 75 |
+
else:
|
| 76 |
+
raise Exception("Unexpected API response format")
|
| 77 |
else:
|
| 78 |
raise Exception("API request failed with status code " + str(response.status_code))
|
| 79 |
|
|
|
|
| 83 |
inputs=[
|
| 84 |
gr.components.Textbox(label="Prompt"),
|
| 85 |
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"),
|
|
|
|
| 86 |
gr.components.Dropdown(choices=[
|
| 87 |
"Euler a",
|
| 88 |
"Euler",
|
|
|
|
| 104 |
"DDIM",
|
| 105 |
"PLMS"
|
| 106 |
], label="Scheduler", default="Euler a"),
|
| 107 |
+
gr.components.Slider(minimum=10, maximum=100, step=1.0,default=30, label="Steps"),
|
| 108 |
gr.components.Slider(minimum=512, maximum=1600, default=768, label="Width"),
|
| 109 |
gr.components.Slider(minimum=512, maximum=1600, default=768, label="Height"),
|
| 110 |
gr.components.Slider(minimum=4, maximum=12, step=0.5, default=7.0, label="CFG"),
|
| 111 |
gr.components.Number(label="Seed", default=None),
|
| 112 |
gr.components.Checkbox(label="Restore Faces"),
|
| 113 |
+
gr.components.Textbox(label="Token", type="password")
|
| 114 |
],
|
| 115 |
outputs=gr.components.Image(),
|
| 116 |
title="Freedom Demonstration",
|