Spaces:
Sleeping
Sleeping
Pavithiran
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -102,13 +102,22 @@ def respond(
|
|
102 |
# Pass the base64-encoded image as the input
|
103 |
response_data = client.text_to_image(images=image_base64, prompt=message) # Pass the base64 string as 'images'
|
104 |
|
105 |
-
#
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
# Create the Gradio interface with an image input
|
114 |
demo = gr.ChatInterface(
|
|
|
102 |
# Pass the base64-encoded image as the input
|
103 |
response_data = client.text_to_image(images=image_base64, prompt=message) # Pass the base64 string as 'images'
|
104 |
|
105 |
+
# Check if the response is in the correct format (e.g., image)
|
106 |
+
try:
|
107 |
+
# Assuming the response is an image in base64 format
|
108 |
+
if 'image' in response_data:
|
109 |
+
image_response = response_data['image']
|
110 |
+
print("Image Res:")
|
111 |
+
print(image_response)
|
112 |
+
# Decode the base64 image back into an image object
|
113 |
+
image_bytes = base64.b64decode(image_response)
|
114 |
+
image = Image.open(io.BytesIO(image_bytes))
|
115 |
+
image.show() # Or return the image in Gradio
|
116 |
+
return "Image processed successfully" # You can return some confirmation or process the image further
|
117 |
+
else:
|
118 |
+
return "Error: No valid image returned from the model."
|
119 |
+
except Exception as e:
|
120 |
+
return f"Error processing image: {e}"
|
121 |
|
122 |
# Create the Gradio interface with an image input
|
123 |
demo = gr.ChatInterface(
|