Update app.py
Browse files
app.py
CHANGED
|
@@ -68,29 +68,31 @@ def image_prompt(prompt, image1, image2, image3, image4):
|
|
| 68 |
job_step_preview = job_data.get("job_step_preview")
|
| 69 |
job_result = job_data.get("job_result")
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
|
|
|
|
|
|
|
| 73 |
image = Image.open(BytesIO(base64.b64decode(job_step_preview)))
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
| 77 |
final_image_url = job_result[0].get("url")
|
| 78 |
if final_image_url:
|
| 79 |
final_image_url = final_image_url.replace("127.0.0.1", "18.119.36.46")
|
| 80 |
image_response = session.get(final_image_url, timeout=10) # Increase timeout as needed
|
| 81 |
image = Image.open(BytesIO(image_response.content))
|
| 82 |
-
|
| 83 |
-
break
|
| 84 |
else:
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
| 87 |
elif job_stage == "FAILED":
|
| 88 |
-
|
| 89 |
-
break
|
| 90 |
-
|
| 91 |
-
time.sleep(2) # Wait 2 seconds before the next update
|
| 92 |
else:
|
| 93 |
-
|
| 94 |
|
| 95 |
def gradio_app():
|
| 96 |
with gr.Blocks() as demo:
|
|
@@ -104,7 +106,7 @@ def gradio_app():
|
|
| 104 |
status = gr.Textbox(label="Status")
|
| 105 |
|
| 106 |
generate_button = gr.Button("Generate Image")
|
| 107 |
-
generate_button.click(
|
| 108 |
|
| 109 |
demo.launch()
|
| 110 |
|
|
|
|
| 68 |
job_step_preview = job_data.get("job_step_preview")
|
| 69 |
job_result = job_data.get("job_result")
|
| 70 |
|
| 71 |
+
# Continuously print out or display the attributes every 2 seconds
|
| 72 |
+
print(f"Job Stage: {job_stage}")
|
| 73 |
+
if job_step_preview:
|
| 74 |
+
print("Step Preview Available")
|
| 75 |
image = Image.open(BytesIO(base64.b64decode(job_step_preview)))
|
| 76 |
+
if job_result:
|
| 77 |
+
print(f"Job Result: {job_result}")
|
| 78 |
+
|
| 79 |
+
if job_stage == "SUCCESS":
|
| 80 |
final_image_url = job_result[0].get("url")
|
| 81 |
if final_image_url:
|
| 82 |
final_image_url = final_image_url.replace("127.0.0.1", "18.119.36.46")
|
| 83 |
image_response = session.get(final_image_url, timeout=10) # Increase timeout as needed
|
| 84 |
image = Image.open(BytesIO(image_response.content))
|
| 85 |
+
return image, "Job completed successfully."
|
|
|
|
| 86 |
else:
|
| 87 |
+
return None, "Final image URL not found in the job data."
|
| 88 |
+
elif job_stage == "RUNNING":
|
| 89 |
+
if job_step_preview:
|
| 90 |
+
image = Image.open(BytesIO(base64.b64decode(job_step_preview)))
|
| 91 |
+
time.sleep(2) # Wait 2 seconds before the next update
|
| 92 |
elif job_stage == "FAILED":
|
| 93 |
+
return None, "Job failed."
|
|
|
|
|
|
|
|
|
|
| 94 |
else:
|
| 95 |
+
return None, "Job ID not found."
|
| 96 |
|
| 97 |
def gradio_app():
|
| 98 |
with gr.Blocks() as demo:
|
|
|
|
| 106 |
status = gr.Textbox(label="Status")
|
| 107 |
|
| 108 |
generate_button = gr.Button("Generate Image")
|
| 109 |
+
generate_button.click(image_prompt, inputs=[prompt, image1, image2, image3, image4], outputs=[output_image, status])
|
| 110 |
|
| 111 |
demo.launch()
|
| 112 |
|