Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,44 +1,3 @@
|
|
1 |
-
"""
|
2 |
-
{
|
3 |
-
"inputs": {
|
4 |
-
"prompt": "A text prompt to generate the image from.",
|
5 |
-
"image_prompts": [
|
6 |
-
{
|
7 |
-
"cn_img": "Base64 encoded image data for the first image prompt.",
|
8 |
-
"cn_stop": "ControlNet stop value for the first image prompt.",
|
9 |
-
"cn_weight": "ControlNet weight value for the first image prompt.",
|
10 |
-
"cn_type": "Type of the first image prompt."
|
11 |
-
},
|
12 |
-
{
|
13 |
-
"cn_img": "Base64 encoded image data for the second image prompt.",
|
14 |
-
"cn_stop": "ControlNet stop value for the second image prompt.",
|
15 |
-
"cn_weight": "ControlNet weight value for the second image prompt.",
|
16 |
-
"cn_type": "Type of the second image prompt."
|
17 |
-
},
|
18 |
-
{
|
19 |
-
"cn_img": "Base64 encoded image data for the third image prompt.",
|
20 |
-
"cn_stop": "ControlNet stop value for the third image prompt.",
|
21 |
-
"cn_weight": "ControlNet weight value for the third image prompt.",
|
22 |
-
"cn_type": "Type of the third image prompt."
|
23 |
-
},
|
24 |
-
{
|
25 |
-
"cn_img": "Base64 encoded image data for the fourth image prompt.",
|
26 |
-
"cn_stop": "ControlNet stop value for the fourth image prompt.",
|
27 |
-
"cn_weight": "ControlNet weight value for the fourth image prompt.",
|
28 |
-
"cn_type": "Type of the fourth image prompt."
|
29 |
-
}
|
30 |
-
],
|
31 |
-
"async_process": "Boolean to indicate if the process should be asynchronous."
|
32 |
-
},
|
33 |
-
"outputs": {
|
34 |
-
"job_id": "The ID of the job submitted for image generation.",
|
35 |
-
"job_stage": "The current stage of the job (e.g., RUNNING, SUCCESS, FAILED).",
|
36 |
-
"final_image_url": "The URL of the final generated image.",
|
37 |
-
"step_preview": "Base64 encoded step preview image data."
|
38 |
-
}
|
39 |
-
}
|
40 |
-
"""
|
41 |
-
|
42 |
import requests
|
43 |
from requests.adapters import HTTPAdapter
|
44 |
from requests.packages.urllib3.util.retry import Retry
|
@@ -47,13 +6,11 @@ import base64
|
|
47 |
import time
|
48 |
import gradio as gr
|
49 |
from PIL import Image
|
|
|
50 |
import os
|
51 |
|
52 |
host = "http://18.119.36.46:8888"
|
53 |
|
54 |
-
# 📂 Get the directory where the script is located
|
55 |
-
script_dir = os.path.dirname(os.path.abspath(__file__))
|
56 |
-
|
57 |
def image_prompt(prompt, image1, image2, image3, image4):
|
58 |
source1 = open(image1, "rb").read()
|
59 |
source2 = open(image2, "rb").read()
|
@@ -114,28 +71,21 @@ def image_prompt(prompt, image1, image2, image3, image4):
|
|
114 |
if final_image_url:
|
115 |
final_image_url = final_image_url.replace("127.0.0.1", "18.119.36.46")
|
116 |
image_response = session.get(final_image_url, timeout=10) # Increase timeout as needed
|
117 |
-
|
118 |
-
|
119 |
-
return "output.png", "Job completed successfully."
|
120 |
else:
|
121 |
return None, "Final image URL not found in the job data."
|
122 |
elif job_stage == "RUNNING":
|
123 |
step_preview_base64 = job_data.get("job_step_preview")
|
124 |
if step_preview_base64:
|
125 |
-
|
126 |
-
|
127 |
time.sleep(5)
|
128 |
elif job_stage == "FAILED":
|
129 |
return None, "Job failed."
|
130 |
else:
|
131 |
return None, "Job ID not found."
|
132 |
|
133 |
-
def create_status_image():
|
134 |
-
if os.path.exists("output.png"):
|
135 |
-
return "output.png"
|
136 |
-
else:
|
137 |
-
return None
|
138 |
-
|
139 |
def gradio_app():
|
140 |
with gr.Blocks() as demo:
|
141 |
prompt = gr.Textbox(label="Prompt", placeholder="Enter your text prompt here")
|
@@ -150,12 +100,6 @@ def gradio_app():
|
|
150 |
generate_button = gr.Button("Generate Image")
|
151 |
generate_button.click(image_prompt, inputs=[prompt, image1, image2, image3, image4], outputs=[output_image, status])
|
152 |
|
153 |
-
# 🖼️ Display the status image
|
154 |
-
status_image = gr.Image(label="Queue Status", interactive=False)
|
155 |
-
|
156 |
-
# ⏲️ Update the image every 5 seconds
|
157 |
-
demo.load(create_status_image, every=5, outputs=status_image)
|
158 |
-
|
159 |
demo.launch()
|
160 |
|
161 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import requests
|
2 |
from requests.adapters import HTTPAdapter
|
3 |
from requests.packages.urllib3.util.retry import Retry
|
|
|
6 |
import time
|
7 |
import gradio as gr
|
8 |
from PIL import Image
|
9 |
+
from io import BytesIO
|
10 |
import os
|
11 |
|
12 |
host = "http://18.119.36.46:8888"
|
13 |
|
|
|
|
|
|
|
14 |
def image_prompt(prompt, image1, image2, image3, image4):
|
15 |
source1 = open(image1, "rb").read()
|
16 |
source2 = open(image2, "rb").read()
|
|
|
71 |
if final_image_url:
|
72 |
final_image_url = final_image_url.replace("127.0.0.1", "18.119.36.46")
|
73 |
image_response = session.get(final_image_url, timeout=10) # Increase timeout as needed
|
74 |
+
image = Image.open(BytesIO(image_response.content))
|
75 |
+
return image, "Job completed successfully."
|
|
|
76 |
else:
|
77 |
return None, "Final image URL not found in the job data."
|
78 |
elif job_stage == "RUNNING":
|
79 |
step_preview_base64 = job_data.get("job_step_preview")
|
80 |
if step_preview_base64:
|
81 |
+
image = Image.open(BytesIO(base64.b64decode(step_preview_base64)))
|
82 |
+
return image, "Job is running, step preview available."
|
83 |
time.sleep(5)
|
84 |
elif job_stage == "FAILED":
|
85 |
return None, "Job failed."
|
86 |
else:
|
87 |
return None, "Job ID not found."
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
def gradio_app():
|
90 |
with gr.Blocks() as demo:
|
91 |
prompt = gr.Textbox(label="Prompt", placeholder="Enter your text prompt here")
|
|
|
100 |
generate_button = gr.Button("Generate Image")
|
101 |
generate_button.click(image_prompt, inputs=[prompt, image1, image2, image3, image4], outputs=[output_image, status])
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
demo.launch()
|
104 |
|
105 |
if __name__ == "__main__":
|