VirtualOasis commited on
Commit
8861022
·
verified ·
1 Parent(s): f3608f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
  import tempfile
 
3
  import gradio as gr
4
  from PIL import Image, ImageDraw, ImageFont
5
 
@@ -160,12 +161,33 @@ def text_to_images_generator(text_content, style='lines'):
160
  # Paste this page onto the combined image
161
  combined_img.paste(page_img, (0, page_idx * IMG_HEIGHT))
162
 
163
- # Save combined image to temporary file
164
  temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
165
  combined_img.save(temp_file.name, format='PNG')
166
  temp_file.close()
167
 
168
- return f"Image successfully generated and saved to: {temp_file.name}\n\nImage details:\n- Total pages: {len(pages_content)}\n- Image dimensions: {IMG_WIDTH} x {total_height} pixels\n- Style: {style}\n- Format: PNG"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
 
170
  # --- Gradio Interface ---
171
 
 
1
  import os
2
  import tempfile
3
+ import base64
4
  import gradio as gr
5
  from PIL import Image, ImageDraw, ImageFont
6
 
 
161
  # Paste this page onto the combined image
162
  combined_img.paste(page_img, (0, page_idx * IMG_HEIGHT))
163
 
164
+ # Save combined image to temporary file and also encode as base64
165
  temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
166
  combined_img.save(temp_file.name, format='PNG')
167
  temp_file.close()
168
 
169
+ # Convert to base64 for inline viewing
170
+ import io
171
+ img_buffer = io.BytesIO()
172
+ combined_img.save(img_buffer, format='PNG')
173
+ img_buffer.seek(0)
174
+ img_base64 = base64.b64encode(img_buffer.getvalue()).decode('utf-8')
175
+
176
+ return f"""Image successfully generated and saved to: {temp_file.name}
177
+
178
+ Image details:
179
+ - Total pages: {len(pages_content)}
180
+ - Image dimensions: {IMG_WIDTH} x {total_height} pixels
181
+ - Style: {style}
182
+ - Format: PNG
183
+
184
+ Base64 encoded image (you can copy this and paste into a base64 image viewer):
185
+ data:image/png;base64,{img_base64}
186
+
187
+ To view the image:
188
+ 1. Copy the entire data:image/png;base64,... string above
189
+ 2. Paste it into your browser's address bar, or
190
+ 3. Use an online base64 image viewer like: https://base64.guru/converter/decode/image"""
191
 
192
  # --- Gradio Interface ---
193