Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -66,6 +66,7 @@ def generate_image(prompt, image=None, output_filename="generated_image"):
|
|
66 |
config=generate_content_config,
|
67 |
)
|
68 |
|
|
|
69 |
# Process the response
|
70 |
for chunk in response:
|
71 |
if not chunk.candidates or not chunk.candidates[0].content or not chunk.candidates[0].content.parts:
|
@@ -79,10 +80,13 @@ def generate_image(prompt, image=None, output_filename="generated_image"):
|
|
79 |
# Convert binary data to PIL Image
|
80 |
img = Image.open(io.BytesIO(inline_data.data))
|
81 |
return img, f"Image saved as {filename}"
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
return None, "No image generated"
|
86 |
|
87 |
# Function to handle chat interaction
|
88 |
def chat_handler(prompt, user_image, chat_history, output_filename="generated_image"):
|
@@ -114,6 +118,7 @@ def chat_handler(prompt, user_image, chat_history, output_filename="generated_im
|
|
114 |
# Create thumbnail for chatbot
|
115 |
thumbnail_size = (100, 100) # Define thumbnail size
|
116 |
thumbnail = img.copy()
|
|
|
117 |
thumbnail.thumbnail(thumbnail_size)
|
118 |
|
119 |
# Convert thumbnail to base64 for chatbot display
|
@@ -121,6 +126,7 @@ def chat_handler(prompt, user_image, chat_history, output_filename="generated_im
|
|
121 |
thumbnail.save(buffered, format="PNG")
|
122 |
thumbnail_base64 = base64.b64encode(buffered.getvalue()).decode()
|
123 |
thumbnail_data_uri = f"data:image/png;base64,{thumbnail_base64}"
|
|
|
124 |
assistant_message_content = gr.HTML(f'<img src="{thumbnail_data_uri}" alt="Generated Image Thumbnail">') # Use gr.HTML
|
125 |
else:
|
126 |
assistant_message_content = status # If no image, send text status
|
|
|
66 |
config=generate_content_config,
|
67 |
)
|
68 |
|
69 |
+
full_text_response = "" # For debugging text truncation
|
70 |
# Process the response
|
71 |
for chunk in response:
|
72 |
if not chunk.candidates or not chunk.candidates[0].content or not chunk.candidates[0].content.parts:
|
|
|
80 |
# Convert binary data to PIL Image
|
81 |
img = Image.open(io.BytesIO(inline_data.data))
|
82 |
return img, f"Image saved as {filename}"
|
83 |
+
elif chunk.text:
|
84 |
+
full_text_response += chunk.text # Append chunk text for full response
|
85 |
+
print("Chunk Text Response:", chunk.text) # Debugging chunk text
|
86 |
+
|
87 |
+
print("Full Text Response from Gemini:", full_text_response) # Debugging full text
|
88 |
+
return None, full_text_response # Return full text response
|
89 |
|
|
|
90 |
|
91 |
# Function to handle chat interaction
|
92 |
def chat_handler(prompt, user_image, chat_history, output_filename="generated_image"):
|
|
|
118 |
# Create thumbnail for chatbot
|
119 |
thumbnail_size = (100, 100) # Define thumbnail size
|
120 |
thumbnail = img.copy()
|
121 |
+
thumbnail = thumbnail.convert("RGB") # Force RGB mode for thumbnail
|
122 |
thumbnail.thumbnail(thumbnail_size)
|
123 |
|
124 |
# Convert thumbnail to base64 for chatbot display
|
|
|
126 |
thumbnail.save(buffered, format="PNG")
|
127 |
thumbnail_base64 = base64.b64encode(buffered.getvalue()).decode()
|
128 |
thumbnail_data_uri = f"data:image/png;base64,{thumbnail_base64}"
|
129 |
+
print("Thumbnail Data URI:", thumbnail_data_uri) # Print to console
|
130 |
assistant_message_content = gr.HTML(f'<img src="{thumbnail_data_uri}" alt="Generated Image Thumbnail">') # Use gr.HTML
|
131 |
else:
|
132 |
assistant_message_content = status # If no image, send text status
|