Spaces:
Running
Running
JV A
commited on
Commit
·
da1b766
1
Parent(s):
fedcf0f
Update app.py
Browse files
app.py
CHANGED
@@ -1,107 +1,91 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
|
|
|
|
3 |
|
4 |
def generate_image(prompt):
|
5 |
-
|
6 |
-
|
7 |
-
"mode": "url",
|
8 |
-
"model": "AOM3A1B_orangemixs.safetensors",
|
9 |
-
"tiling": false,
|
10 |
-
"batch_size": 1,
|
11 |
-
"prompt": prompt,
|
12 |
-
"negative_prompt": "worst quality, lowres",
|
13 |
-
"seed": 1234,
|
14 |
-
"scheduler": "Euler a",
|
15 |
-
"n_iter": 1,
|
16 |
-
"steps": 30,
|
17 |
-
"cfg": 11.0,
|
18 |
-
"offset_noise": 0.0,
|
19 |
-
"width": 1024,
|
20 |
-
"height": 1024,
|
21 |
-
"clip_skip": 1,
|
22 |
-
"loras": [
|
23 |
-
{
|
24 |
-
"name": "",
|
25 |
-
"strength": 1.0
|
26 |
-
}
|
27 |
-
],
|
28 |
-
"embeddings": [
|
29 |
-
{
|
30 |
-
"name": "",
|
31 |
-
"strength": 1.0
|
32 |
-
}
|
33 |
-
],
|
34 |
-
"vae": "vae-ft-mse-840000-ema-pruned.ckpt",
|
35 |
-
"restore_faces": false,
|
36 |
-
"fr_model": "CodeFormer",
|
37 |
-
"codeformer_weight": 0.5,
|
38 |
-
"enable_hr": false,
|
39 |
-
"denoising_strength": 0.75,
|
40 |
-
"hr_scale": 2,
|
41 |
-
"hr_upscale": "None",
|
42 |
-
"img2img_ref_img_type": "piece",
|
43 |
-
"img2img_resize_mode": 0,
|
44 |
-
"img2img_denoising_strength": 0.75,
|
45 |
-
"controlnet_enabled": false,
|
46 |
-
"controlnet_ref_img_type": "piece",
|
47 |
-
"controlnet_guessmode": false,
|
48 |
-
"controlnet_module": "canny",
|
49 |
-
"controlnet_model": "control_v11p_sd15_softedge",
|
50 |
-
"controlnet_weight": 1,
|
51 |
-
"controlnet_guidance_start": 0,
|
52 |
-
"controlnet_guidance_end": 1,
|
53 |
-
"controlnet_ref_img_url": "",
|
54 |
-
"controlnet_mask": [],
|
55 |
-
"controlnet_resize_mode": "Scale to Fit (Inner Fit)",
|
56 |
-
"controlnet_lowvram": false,
|
57 |
-
"controlnet_processor_res": 512,
|
58 |
-
"controlnet_threshold_a": 100,
|
59 |
-
"controlnet_threshold_b": 200
|
60 |
-
}
|
61 |
-
headers = {
|
62 |
-
'Content-Type': 'application/json',
|
63 |
-
'token': '514f7ecde6a5434dbab5c6579311ad82' # Replace with your API token
|
64 |
-
}
|
65 |
-
response = requests.post(apiUrl, json=data, headers=headers)
|
66 |
-
responseData = response.json()
|
67 |
-
if responseData and responseData['results'] and responseData['results'][0]:
|
68 |
-
return responseData['results'][0]
|
69 |
-
else:
|
70 |
-
return "No image generated"
|
71 |
|
72 |
-
#
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
# "controlnet_ref_img_url": control_image,
|
78 |
-
# ...
|
79 |
-
# }
|
80 |
-
# headers = {
|
81 |
-
# ...
|
82 |
-
# }
|
83 |
-
# response = requests.post(apiUrl, json=data, headers=headers)
|
84 |
-
# responseData = response.json()
|
85 |
-
# if responseData and responseData['results'] and responseData['results'][0]:
|
86 |
-
# return responseData['results'][0]
|
87 |
-
# else:
|
88 |
-
# return "No image generated"
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
|
94 |
-
#
|
95 |
-
|
96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
97 |
iface = gr.Interface(
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
layout="vertical"
|
105 |
)
|
106 |
|
|
|
107 |
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
+
import json
|
4 |
+
import PIL.Image
|
5 |
+
from io import BytesIO
|
6 |
|
7 |
def generate_image(prompt):
|
8 |
+
# Define the API endpoint
|
9 |
+
apiUrl = "https://apiv2.makeai.run/v2/txt2img"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# Define the request headers
|
12 |
+
headers = {
|
13 |
+
"Content-Type": "application/json",
|
14 |
+
"token": "514f7ecde6a5434dbab5c6579311ad82"
|
15 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
+
# Define the request body
|
18 |
+
body = {
|
19 |
+
"mode": "url",
|
20 |
+
"model": "AOM3A1B_orangemixs.safetensors",
|
21 |
+
"tiling": False,
|
22 |
+
"batch_size": 1,
|
23 |
+
"prompt": prompt,
|
24 |
+
"negative_prompt": "worst quality, lowres",
|
25 |
+
"seed": 1234,
|
26 |
+
"scheduler": "Euler a",
|
27 |
+
"n_iter": 1,
|
28 |
+
"steps": 25,
|
29 |
+
"cfg": 11.0,
|
30 |
+
"offset_noise": 0.0,
|
31 |
+
"width": 512,
|
32 |
+
"height": 512,
|
33 |
+
"clip_skip": 1,
|
34 |
+
"loras": [{"name": "", "strength": 1.0}],
|
35 |
+
"embeddings": [{"name": "", "strength": 1.0}],
|
36 |
+
"vae": "vae-ft-mse-840000-ema-pruned.ckpt",
|
37 |
+
"restore_faces": False,
|
38 |
+
"fr_model": "CodeFormer",
|
39 |
+
"codeformer_weight": 0.5,
|
40 |
+
"enable_hr": False,
|
41 |
+
"denoising_strength": 0.75,
|
42 |
+
"hr_scale": 2,
|
43 |
+
"hr_upscale": "None",
|
44 |
+
"img2img_ref_img_type": "piece",
|
45 |
+
"img2img_resize_mode": 0,
|
46 |
+
"img2img_denoising_strength": 0.75,
|
47 |
+
"controlnet_enabled": False,
|
48 |
+
"controlnet_ref_img_type": "piece",
|
49 |
+
"controlnet_guessmode": False,
|
50 |
+
"controlnet_module": "canny",
|
51 |
+
"controlnet_model": "control_v11p_sd15_softedge",
|
52 |
+
"controlnet_weight": 1,
|
53 |
+
"controlnet_guidance_start": 0,
|
54 |
+
"controlnet_guidance_end": 1,
|
55 |
+
"controlnet_ref_img_url": "https://upload.wikimedia.org/wikipedia/commons/d/d1/Image_not_available.png",
|
56 |
+
"controlnet_mask": [],
|
57 |
+
"controlnet_resize_mode": "Scale to Fit (Inner Fit)",
|
58 |
+
"controlnet_lowvram": False,
|
59 |
+
"controlnet_processor_res": 512,
|
60 |
+
"controlnet_threshold_a": 100,
|
61 |
+
"controlnet_threshold_b": 200
|
62 |
+
}
|
63 |
|
64 |
+
# Send the request
|
65 |
+
response = requests.post(apiUrl, headers=headers, data=json.dumps(body))
|
66 |
|
67 |
+
# Check the response status
|
68 |
+
if response.status_code == 200:
|
69 |
+
# Get the image URL from the response
|
70 |
+
image_url = json.loads(response.text)['results'][0]
|
71 |
+
|
72 |
+
# Get the image from the URL
|
73 |
+
image_response = requests.get(image_url)
|
74 |
+
image = PIL.Image.open(BytesIO(image_response.content))
|
75 |
+
|
76 |
+
return image
|
77 |
+
else:
|
78 |
+
raise Exception("API request failed with status code " + str(response.status_code))
|
79 |
+
|
80 |
+
# Define the Gradio interface
|
81 |
iface = gr.Interface(
|
82 |
+
fn=generate_image,
|
83 |
+
inputs="text",
|
84 |
+
outputs="image",
|
85 |
+
title="Freedom Demonstration",
|
86 |
+
description="Enter a prompt and generate an image.",
|
87 |
+
allow_flagging=False
|
|
|
88 |
)
|
89 |
|
90 |
+
# Launch the app
|
91 |
iface.launch()
|