Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -193,15 +193,49 @@ class ManimAnimationGenerator:
|
|
| 193 |
|
| 194 |
code = extract_manim_code(code)
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
try:
|
| 197 |
is_valid, message = self.validate_manim_code(code)
|
| 198 |
if not is_valid:
|
| 199 |
return None, f"❌ Validation Error: {message}", ""
|
| 200 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
temp_dir = self.setup_directories()
|
| 202 |
python_file = os.path.join(temp_dir, "animation.py")
|
| 203 |
with open(python_file, "w") as f:
|
| 204 |
f.write(code)
|
|
|
|
| 205 |
|
| 206 |
class_name = self.extract_class_name(code)
|
| 207 |
if not class_name:
|
|
|
|
| 193 |
|
| 194 |
code = extract_manim_code(code)
|
| 195 |
|
| 196 |
+
# try:
|
| 197 |
+
# is_valid, message = self.validate_manim_code(code)
|
| 198 |
+
# if not is_valid:
|
| 199 |
+
# return None, f"❌ Validation Error: {message}", ""
|
| 200 |
+
|
| 201 |
+
# temp_dir = self.setup_directories()
|
| 202 |
+
# python_file = os.path.join(temp_dir, "animation.py")
|
| 203 |
+
# with open(python_file, "w") as f:
|
| 204 |
+
# f.write(code)
|
| 205 |
+
|
| 206 |
try:
|
| 207 |
is_valid, message = self.validate_manim_code(code)
|
| 208 |
if not is_valid:
|
| 209 |
return None, f"❌ Validation Error: {message}", ""
|
| 210 |
|
| 211 |
+
# Dynamically inject portrait (9:16) config
|
| 212 |
+
portrait_config = """
|
| 213 |
+
from manim import config
|
| 214 |
+
# Maintain chosen quality while forcing 9:16 aspect ratio
|
| 215 |
+
if config["pixel_height"] == 480:
|
| 216 |
+
config.pixel_height = 854 # low
|
| 217 |
+
config.pixel_width = 480
|
| 218 |
+
elif config["pixel_height"] == 720:
|
| 219 |
+
config.pixel_height = 1280 # medium
|
| 220 |
+
config.pixel_width = 720
|
| 221 |
+
elif config["pixel_height"] == 1080:
|
| 222 |
+
config.pixel_height = 1920 # high
|
| 223 |
+
config.pixel_width = 1080
|
| 224 |
+
else:
|
| 225 |
+
config.pixel_height = 854
|
| 226 |
+
config.pixel_width = 480
|
| 227 |
+
|
| 228 |
+
config.frame_height = 16
|
| 229 |
+
config.frame_width = 9
|
| 230 |
+
"""
|
| 231 |
+
|
| 232 |
+
code = portrait_config + "\n" + code
|
| 233 |
+
|
| 234 |
temp_dir = self.setup_directories()
|
| 235 |
python_file = os.path.join(temp_dir, "animation.py")
|
| 236 |
with open(python_file, "w") as f:
|
| 237 |
f.write(code)
|
| 238 |
+
#end
|
| 239 |
|
| 240 |
class_name = self.extract_class_name(code)
|
| 241 |
if not class_name:
|