Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,16 +31,20 @@ def home():
|
|
| 31 |
img = Image.new("RGB", (256, 256), color=(255, 255, 255))
|
| 32 |
draw = ImageDraw.Draw(img)
|
| 33 |
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
image_tag = f"<h3>Generated Image:</h3><img src='data:image/png;base64,{img_b64}' alt='Generated Image'>"
|
| 45 |
|
| 46 |
return HTML_TEMPLATE.format(image_tag=image_tag)
|
|
|
|
| 31 |
img = Image.new("RGB", (256, 256), color=(255, 255, 255))
|
| 32 |
draw = ImageDraw.Draw(img)
|
| 33 |
|
| 34 |
+
# Safe font handling
|
| 35 |
+
try:
|
| 36 |
+
font = ImageFont.load_default()
|
| 37 |
+
except:
|
| 38 |
+
font = None
|
| 39 |
+
|
| 40 |
+
# Draw text
|
| 41 |
+
draw.text((10, 120), text, fill="black", font=font)
|
| 42 |
+
|
| 43 |
+
# Convert image to base64
|
| 44 |
+
img_bytes = io.BytesIO()
|
| 45 |
+
img.save(img_bytes, format="PNG")
|
| 46 |
+
img_bytes.seek(0)
|
| 47 |
+
img_b64 = base64.b64encode(img_bytes.read()).decode()
|
| 48 |
image_tag = f"<h3>Generated Image:</h3><img src='data:image/png;base64,{img_b64}' alt='Generated Image'>"
|
| 49 |
|
| 50 |
return HTML_TEMPLATE.format(image_tag=image_tag)
|