Update app.py
Browse files
app.py
CHANGED
|
@@ -38,6 +38,9 @@ def create_manim_script(problem_data, script_path):
|
|
| 38 |
if not slides:
|
| 39 |
raise ValueError("No slides provided in input data")
|
| 40 |
|
|
|
|
|
|
|
|
|
|
| 41 |
manim_code = f'''
|
| 42 |
from manim import *
|
| 43 |
|
|
@@ -57,7 +60,7 @@ class GeneratedMathScene(Scene):
|
|
| 57 |
line_spacing = 0.8
|
| 58 |
screen_bottom = -3.5
|
| 59 |
|
| 60 |
-
slides = {
|
| 61 |
|
| 62 |
for idx, slide in enumerate(slides):
|
| 63 |
obj = None
|
|
@@ -78,6 +81,7 @@ class GeneratedMathScene(Scene):
|
|
| 78 |
obj = Text(content, color=default_color, font=default_font, font_size=text_size)
|
| 79 |
|
| 80 |
elif slide_type == "equation":
|
|
|
|
| 81 |
obj = MathTex(content, color=default_color, font_size=equation_size)
|
| 82 |
|
| 83 |
if obj:
|
|
@@ -111,8 +115,11 @@ class GeneratedMathScene(Scene):
|
|
| 111 |
self.wait(1.5)
|
| 112 |
'''
|
| 113 |
|
| 114 |
-
with open(script_path, 'w') as f:
|
| 115 |
f.write(manim_code)
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
@app.route("/")
|
| 118 |
def home():
|
|
|
|
| 38 |
if not slides:
|
| 39 |
raise ValueError("No slides provided in input data")
|
| 40 |
|
| 41 |
+
# Properly escape slides for Python code generation
|
| 42 |
+
slides_repr = repr(slides) # This handles all escaping correctly
|
| 43 |
+
|
| 44 |
manim_code = f'''
|
| 45 |
from manim import *
|
| 46 |
|
|
|
|
| 60 |
line_spacing = 0.8
|
| 61 |
screen_bottom = -3.5
|
| 62 |
|
| 63 |
+
slides = {slides_repr}
|
| 64 |
|
| 65 |
for idx, slide in enumerate(slides):
|
| 66 |
obj = None
|
|
|
|
| 81 |
obj = Text(content, color=default_color, font=default_font, font_size=text_size)
|
| 82 |
|
| 83 |
elif slide_type == "equation":
|
| 84 |
+
# Use raw string for LaTeX to preserve backslashes
|
| 85 |
obj = MathTex(content, color=default_color, font_size=equation_size)
|
| 86 |
|
| 87 |
if obj:
|
|
|
|
| 115 |
self.wait(1.5)
|
| 116 |
'''
|
| 117 |
|
| 118 |
+
with open(script_path, 'w', encoding='utf-8') as f:
|
| 119 |
f.write(manim_code)
|
| 120 |
+
|
| 121 |
+
print(f"Generated script preview (first 500 chars):
|
| 122 |
+
{manim_code[:500]}...")
|
| 123 |
|
| 124 |
@app.route("/")
|
| 125 |
def home():
|