Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,50 +18,33 @@ EXECUTOR = ThreadPoolExecutor(max_workers=2) # Handle concurrent requests
|
|
| 18 |
|
| 19 |
# ===== WATERMARK FUNCTION =====
|
| 20 |
def add_watermark(image_bytes):
|
| 21 |
-
"""Add
|
| 22 |
try:
|
| 23 |
image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
|
| 24 |
draw = ImageDraw.Draw(image)
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
"Roboto-Bold.ttf",
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
None # Final fallback to default
|
| 33 |
-
]:
|
| 34 |
-
try:
|
| 35 |
-
size = min(image.width // 15, 40) # Responsive sizing
|
| 36 |
-
font = ImageFont.truetype(font_path, size) if font_path else ImageFont.load_default(size)
|
| 37 |
-
break
|
| 38 |
-
except:
|
| 39 |
-
continue
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
text_w, text_h = bbox[2] - bbox[0], bbox[3] - bbox[1]
|
| 44 |
-
margin = image.width // 50
|
| 45 |
-
position = (image.width - text_w - margin, image.height - text_h - margin)
|
| 46 |
|
| 47 |
-
#
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
WATERMARK_TEXT,
|
| 52 |
-
font=font,
|
| 53 |
-
fill=(0, 0, 0, 180)) # Semi-transparent black
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
WATERMARK_TEXT,
|
| 58 |
-
font=font,
|
| 59 |
-
fill=(255, 255, 255, 200)) # Semi-transparent white
|
| 60 |
|
| 61 |
return image
|
| 62 |
except Exception as e:
|
| 63 |
print(f"Watermark error: {str(e)}")
|
| 64 |
-
return Image.open(io.BytesIO(image_bytes))
|
| 65 |
|
| 66 |
# ===== IMAGE GENERATION =====
|
| 67 |
def generate_image(prompt):
|
|
|
|
| 18 |
|
| 19 |
# ===== WATERMARK FUNCTION =====
|
| 20 |
def add_watermark(image_bytes):
|
| 21 |
+
"""Add watermark with smaller text and simplified positioning"""
|
| 22 |
try:
|
| 23 |
image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
|
| 24 |
draw = ImageDraw.Draw(image)
|
| 25 |
|
| 26 |
+
# Smaller font size (24 instead of 40)
|
| 27 |
+
font_size = 24
|
| 28 |
+
try:
|
| 29 |
+
font = ImageFont.truetype("Roboto-Bold.ttf", font_size)
|
| 30 |
+
except:
|
| 31 |
+
font = ImageFont.load_default(font_size)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
text = "SelamGPT"
|
| 34 |
+
margin = 10 # Reduced from 20
|
|
|
|
|
|
|
|
|
|
| 35 |
|
| 36 |
+
# Calculate position using textlength
|
| 37 |
+
text_width = draw.textlength(text, font=font)
|
| 38 |
+
x = image.width - text_width - margin
|
| 39 |
+
y = image.height - 30 # Fixed vertical position
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
# Simpler white text without transparency
|
| 42 |
+
draw.text((x, y), text, font=font, fill=(255, 255, 255))
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
return image
|
| 45 |
except Exception as e:
|
| 46 |
print(f"Watermark error: {str(e)}")
|
| 47 |
+
return Image.open(io.BytesIO(image_bytes))
|
| 48 |
|
| 49 |
# ===== IMAGE GENERATION =====
|
| 50 |
def generate_image(prompt):
|