Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,8 @@ import subprocess
|
|
| 8 |
from PIL import Image, ImageDraw, ImageFont
|
| 9 |
import random
|
| 10 |
import textwrap
|
| 11 |
-
import pkg_resources
|
|
|
|
| 12 |
|
| 13 |
# === Config ===
|
| 14 |
GROQ_API_KEY = "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"
|
|
@@ -112,10 +113,14 @@ def create_basic_animation(text, audio_file):
|
|
| 112 |
# 2. Check Pillow version
|
| 113 |
try:
|
| 114 |
pillow_version = pkg_resources.get_distribution("Pillow").version
|
|
|
|
| 115 |
if tuple(map(int, pillow_version.split("."))) < (8, 0, 0):
|
| 116 |
raise ImportError(f"Pillow version >= 8.0.0 is required, but found {pillow_version}")
|
| 117 |
except pkg_resources.DistributionNotFound:
|
| 118 |
raise ImportError("Pillow is not installed")
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
# 2. Create frames
|
| 121 |
frames = []
|
|
@@ -127,7 +132,12 @@ def create_basic_animation(text, audio_file):
|
|
| 127 |
lines = textwrap.wrap(text, width=30) # Adjust max line length as needed
|
| 128 |
y_start = (height - len(lines) * font_size) // 2
|
| 129 |
for j, line in enumerate(lines):
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
d.text((text_x, y_start + j * font_size), line, fill=(0, 0, 0), font=font) # Black text
|
| 132 |
frames.append(img)
|
| 133 |
|
|
|
|
| 8 |
from PIL import Image, ImageDraw, ImageFont
|
| 9 |
import random
|
| 10 |
import textwrap
|
| 11 |
+
import pkg_resources
|
| 12 |
+
import sys
|
| 13 |
|
| 14 |
# === Config ===
|
| 15 |
GROQ_API_KEY = "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"
|
|
|
|
| 113 |
# 2. Check Pillow version
|
| 114 |
try:
|
| 115 |
pillow_version = pkg_resources.get_distribution("Pillow").version
|
| 116 |
+
print(f"Pillow version: {pillow_version}") # Print Pillow version
|
| 117 |
if tuple(map(int, pillow_version.split("."))) < (8, 0, 0):
|
| 118 |
raise ImportError(f"Pillow version >= 8.0.0 is required, but found {pillow_version}")
|
| 119 |
except pkg_resources.DistributionNotFound:
|
| 120 |
raise ImportError("Pillow is not installed")
|
| 121 |
+
except Exception as e:
|
| 122 |
+
print(f"Error checking Pillow version: {e}")
|
| 123 |
+
raise # Re-raise the exception to see the full traceback
|
| 124 |
|
| 125 |
# 2. Create frames
|
| 126 |
frames = []
|
|
|
|
| 132 |
lines = textwrap.wrap(text, width=30) # Adjust max line length as needed
|
| 133 |
y_start = (height - len(lines) * font_size) // 2
|
| 134 |
for j, line in enumerate(lines):
|
| 135 |
+
try:
|
| 136 |
+
text_x = (width - d.textsize(line, font=font)[0]) // 2
|
| 137 |
+
except AttributeError as e:
|
| 138 |
+
print(f"AttributeError: {e}")
|
| 139 |
+
print(f"Pillow version: {pillow_version}")
|
| 140 |
+
raise # Raise the error
|
| 141 |
d.text((text_x, y_start + j * font_size), line, fill=(0, 0, 0), font=font) # Black text
|
| 142 |
frames.append(img)
|
| 143 |
|