Update app.py
Browse files
app.py
CHANGED
|
@@ -34,19 +34,17 @@ def create_manim_script(problem_data, script_path):
|
|
| 34 |
})
|
| 35 |
|
| 36 |
slides = problem_data.get("slides", [])
|
| 37 |
-
|
| 38 |
if not slides:
|
| 39 |
raise ValueError("No slides provided in input data")
|
| 40 |
|
| 41 |
-
|
| 42 |
-
slides_repr = repr(slides) # This handles all escaping correctly
|
| 43 |
|
| 44 |
manim_code = f'''
|
| 45 |
from manim import *
|
|
|
|
| 46 |
|
| 47 |
class GeneratedMathScene(Scene):
|
| 48 |
def construct(self):
|
| 49 |
-
# Settings
|
| 50 |
self.camera.background_color = "{settings.get('background_color', '#0f0f23')}"
|
| 51 |
default_color = {settings.get('text_color', 'WHITE')}
|
| 52 |
highlight_color = {settings.get('highlight_color', 'YELLOW')}
|
|
@@ -71,6 +69,8 @@ class GeneratedMathScene(Scene):
|
|
| 71 |
|
| 72 |
if slide_type == "title":
|
| 73 |
obj = Text(content, color=highlight_color, font=default_font, font_size=title_size)
|
|
|
|
|
|
|
| 74 |
obj.move_to(ORIGIN)
|
| 75 |
self.play(FadeIn(obj), run_time=duration * 0.8)
|
| 76 |
self.wait(duration * 0.3)
|
|
@@ -78,11 +78,19 @@ class GeneratedMathScene(Scene):
|
|
| 78 |
continue
|
| 79 |
|
| 80 |
elif slide_type == "text":
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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:
|
| 88 |
obj.to_edge(LEFT, buff=0.3)
|
|
|
|
| 34 |
})
|
| 35 |
|
| 36 |
slides = problem_data.get("slides", [])
|
|
|
|
| 37 |
if not slides:
|
| 38 |
raise ValueError("No slides provided in input data")
|
| 39 |
|
| 40 |
+
slides_repr = repr(slides)
|
|
|
|
| 41 |
|
| 42 |
manim_code = f'''
|
| 43 |
from manim import *
|
| 44 |
+
import textwrap
|
| 45 |
|
| 46 |
class GeneratedMathScene(Scene):
|
| 47 |
def construct(self):
|
|
|
|
| 48 |
self.camera.background_color = "{settings.get('background_color', '#0f0f23')}"
|
| 49 |
default_color = {settings.get('text_color', 'WHITE')}
|
| 50 |
highlight_color = {settings.get('highlight_color', 'YELLOW')}
|
|
|
|
| 69 |
|
| 70 |
if slide_type == "title":
|
| 71 |
obj = Text(content, color=highlight_color, font=default_font, font_size=title_size)
|
| 72 |
+
if obj.width > 12:
|
| 73 |
+
obj.set_width(12)
|
| 74 |
obj.move_to(ORIGIN)
|
| 75 |
self.play(FadeIn(obj), run_time=duration * 0.8)
|
| 76 |
self.wait(duration * 0.3)
|
|
|
|
| 78 |
continue
|
| 79 |
|
| 80 |
elif slide_type == "text":
|
| 81 |
+
# Wrap long text to multiple lines automatically
|
| 82 |
+
if len(content) > 50:
|
| 83 |
+
lines = textwrap.wrap(content, width=50)
|
| 84 |
+
wrapped_content = "\
|
| 85 |
+
".join(lines)
|
| 86 |
+
obj = Text(wrapped_content, color=default_color, font=default_font, font_size=text_size, line_spacing=1)
|
| 87 |
+
else:
|
| 88 |
+
obj = Text(content, color=default_color, font=default_font, font_size=text_size)
|
| 89 |
|
| 90 |
elif slide_type == "equation":
|
|
|
|
| 91 |
obj = MathTex(content, color=default_color, font_size=equation_size)
|
| 92 |
+
if obj.width > 12:
|
| 93 |
+
obj.scale(12 / obj.width)
|
| 94 |
|
| 95 |
if obj:
|
| 96 |
obj.to_edge(LEFT, buff=0.3)
|