Pavithiran commited on
Commit
3badfd2
·
verified ·
1 Parent(s): 3a3b51d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
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
- # Process the response from the model
106
- response = ""
107
- if response_data:
108
- for result in response_data:
109
- response += result.get('text', '') # Process based on the response format
110
-
111
- return response
 
 
 
 
 
 
 
 
 
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(