Update app.py
Browse files
app.py
CHANGED
@@ -43,24 +43,18 @@ def generate_image(prompt, negative_prompt, sampler, seed, guidance_scale, infer
|
|
43 |
# Print the API response for debugging
|
44 |
print("API Response:", response_body)
|
45 |
|
46 |
-
|
|
|
|
|
47 |
return "Error: API response does not contain 'b64_json' key."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
-
# Decode the base64-encoded JSON string
|
50 |
-
b64_json_string = response_body.get("b64_json")
|
51 |
-
decoded_json_bytes = base64.b64decode(b64_json_string)
|
52 |
-
decoded_json_string = decoded_json_bytes.decode("utf-8")
|
53 |
-
|
54 |
-
# Load the decoded JSON string into a Python dictionary
|
55 |
-
output_dict = json.loads(decoded_json_string)
|
56 |
-
|
57 |
-
# Extract the image URL from the output dictionary
|
58 |
-
image_url = output_dict.get("output").get("image_url")
|
59 |
-
|
60 |
-
if image_url is None:
|
61 |
-
return "Error: API response does not contain 'image_url' key."
|
62 |
-
|
63 |
-
return image_url
|
64 |
|
65 |
# Create Gradio interface
|
66 |
iface = gr.Interface(
|
@@ -73,7 +67,7 @@ iface = gr.Interface(
|
|
73 |
gr.Slider(label="Guidance Scale", minimum=0, maximum=20, value=5),
|
74 |
gr.Slider(label="Inference Steps", minimum=1, maximum=50, value=25)
|
75 |
],
|
76 |
-
outputs=gr.Image(label="Generated Image")
|
77 |
)
|
78 |
|
79 |
# Launch the Gradio app
|
|
|
43 |
# Print the API response for debugging
|
44 |
print("API Response:", response_body)
|
45 |
|
46 |
+
# Decode the base64-encoded image data
|
47 |
+
b64_image_data = response_body.get("b64_json")
|
48 |
+
if b64_image_data is None:
|
49 |
return "Error: API response does not contain 'b64_json' key."
|
50 |
+
|
51 |
+
image_data = base64.b64decode(b64_image_data)
|
52 |
+
|
53 |
+
# Since Gradio's Image component can accept a PIL Image, convert the binary data to a PIL Image
|
54 |
+
image = Image.open(BytesIO(image_data))
|
55 |
+
|
56 |
+
return image
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
|
59 |
# Create Gradio interface
|
60 |
iface = gr.Interface(
|
|
|
67 |
gr.Slider(label="Guidance Scale", minimum=0, maximum=20, value=5),
|
68 |
gr.Slider(label="Inference Steps", minimum=1, maximum=50, value=25)
|
69 |
],
|
70 |
+
outputs=gr.Image(label="Generated Image"),
|
71 |
)
|
72 |
|
73 |
# Launch the Gradio app
|