Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -140,37 +140,7 @@ class ContentGenerator:
|
|
| 140 |
log_message(f"❌ Quote generation failed: {str(e)}")
|
| 141 |
return self._get_fallback_quote()
|
| 142 |
|
| 143 |
-
|
| 144 |
-
try:
|
| 145 |
-
response = requests.get(image_url)
|
| 146 |
-
img = Image.open(BytesIO(response.content))
|
| 147 |
-
|
| 148 |
-
# Convert to RGBA for transparency
|
| 149 |
-
img = img.convert('RGBA')
|
| 150 |
-
overlay = Image.new('RGBA', img.size, (0,0,0,0))
|
| 151 |
-
draw = ImageDraw.Draw(overlay)
|
| 152 |
-
|
| 153 |
-
# Add semi-transparent background
|
| 154 |
-
draw.rectangle([(0, img.height//2-100), (img.width, img.height//2+100)],
|
| 155 |
-
fill=(0,0,0,128))
|
| 156 |
-
|
| 157 |
-
# Add quote and author
|
| 158 |
-
quote_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 40)
|
| 159 |
-
author_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 30)
|
| 160 |
-
|
| 161 |
-
draw.text((img.width//2, img.height//2), quote_text,
|
| 162 |
-
font=quote_font, fill='white', anchor='mm', align='center')
|
| 163 |
-
draw.text((img.width//2, img.height//2 + 60), f"- {author}",
|
| 164 |
-
font=author_font, fill='white', anchor='mm')
|
| 165 |
-
|
| 166 |
-
# Combine images
|
| 167 |
-
final_img = Image.alpha_composite(img, overlay)
|
| 168 |
-
buffer = BytesIO()
|
| 169 |
-
final_img.convert('RGB').save(buffer, format='JPEG')
|
| 170 |
-
return buffer.getvalue()
|
| 171 |
-
except Exception as e:
|
| 172 |
-
log_message(f"❌ Error creating quote overlay: {str(e)}")
|
| 173 |
-
return None
|
| 174 |
|
| 175 |
def generate_image(self, quote, tradition, theme):
|
| 176 |
"""Generate an image using OpenAI DALL-E with enhanced prompts"""
|
|
@@ -252,6 +222,37 @@ class ContentGenerator:
|
|
| 252 |
log_message(f"❌ Audio generation failed: {str(e)}", "error")
|
| 253 |
raise
|
| 254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
|
| 256 |
def display_debug_logs():
|
| 257 |
"""Display debug logs with enhanced visualization"""
|
|
|
|
| 140 |
log_message(f"❌ Quote generation failed: {str(e)}")
|
| 141 |
return self._get_fallback_quote()
|
| 142 |
|
| 143 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
def generate_image(self, quote, tradition, theme):
|
| 146 |
"""Generate an image using OpenAI DALL-E with enhanced prompts"""
|
|
|
|
| 222 |
log_message(f"❌ Audio generation failed: {str(e)}", "error")
|
| 223 |
raise
|
| 224 |
|
| 225 |
+
def create_image_with_quote(image_url, quote_text, author):
|
| 226 |
+
try:
|
| 227 |
+
response = requests.get(image_url)
|
| 228 |
+
img = Image.open(BytesIO(response.content))
|
| 229 |
+
|
| 230 |
+
# Convert to RGBA for transparency
|
| 231 |
+
img = img.convert('RGBA')
|
| 232 |
+
overlay = Image.new('RGBA', img.size, (0,0,0,0))
|
| 233 |
+
draw = ImageDraw.Draw(overlay)
|
| 234 |
+
|
| 235 |
+
# Add semi-transparent background
|
| 236 |
+
draw.rectangle([(0, img.height//2-100), (img.width, img.height//2+100)],
|
| 237 |
+
fill=(0,0,0,128))
|
| 238 |
+
|
| 239 |
+
# Add quote and author
|
| 240 |
+
quote_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 40)
|
| 241 |
+
author_font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 30)
|
| 242 |
+
|
| 243 |
+
draw.text((img.width//2, img.height//2), quote_text,
|
| 244 |
+
font=quote_font, fill='white', anchor='mm', align='center')
|
| 245 |
+
draw.text((img.width//2, img.height//2 + 60), f"- {author}",
|
| 246 |
+
font=author_font, fill='white', anchor='mm')
|
| 247 |
+
|
| 248 |
+
# Combine images
|
| 249 |
+
final_img = Image.alpha_composite(img, overlay)
|
| 250 |
+
buffer = BytesIO()
|
| 251 |
+
final_img.convert('RGB').save(buffer, format='JPEG')
|
| 252 |
+
return buffer.getvalue()
|
| 253 |
+
except Exception as e:
|
| 254 |
+
log_message(f"❌ Error creating quote overlay: {str(e)}")
|
| 255 |
+
return None
|
| 256 |
|
| 257 |
def display_debug_logs():
|
| 258 |
"""Display debug logs with enhanced visualization"""
|