vankhieu Codex commited on
Commit
4eed8a5
·
1 Parent(s): cb4ab83

Refine app examples and video playback

Browse files

Co-authored-by: Codex <codex@openai.com>

Files changed (1) hide show
  1. app.py +25 -6
app.py CHANGED
@@ -74,7 +74,6 @@ footer,
74
  }
75
 
76
  #sci-shell {
77
- width: min(1500px, calc(100vw - 28px));
78
  margin: 0 auto;
79
  padding: 18px 0 26px;
80
  }
@@ -429,6 +428,7 @@ Requirements:
429
  4. Strict Animation Speed (CRITICAL SPEED FIX):
430
  - Animate the tracker `t` from 0 to 2*PI using `self.play(t.animate.set_value(2 * PI), run_time=6, rate_func=linear)`.
431
  - YOU MUST EXPLICITLY INCLUDE `rate_func=linear` to eliminate the default smooth easing effect. This ensures that time 't' updates at a perfectly constant velocity, making the physical oscillation and graph rendering completely uniform from start to finish.""",
 
432
  "Orbit": """Create a beautiful, scientifically accurate 2D physics animation of a satellite in an elliptical orbit around Earth using ManimCE.
433
 
434
  Requirements:
@@ -448,6 +448,7 @@ Requirements:
448
  - In the top-right corner, add a LaTeX mathematical text displaying Newton's Law of Universal Gravitation: "F_g = G * (M_1 * M_2) / r²".
449
 
450
  4. Animation flow: Run the animation for 2 complete orbital periods (about 10-12 seconds) so the viewer can clearly observe the dramatic speeding up at the close approach and slowing down at the far end. Wrap everything inside a single clean Scene class.""",
 
451
  "Simple Pendulum": """Create a high-quality Physics simulation of a Damped Simple Pendulum using ManimCE.
452
 
453
  Requirements:
@@ -489,7 +490,25 @@ Requirements:
489
  - Step 3: Animate the two Rectangle blocks (ab) creating themselves using `Create` to fill the remaining empty corners (1.5s).
490
  - Step 4: Display the labels inside each block using `Write`.
491
 
492
- 6. Constraint: Keep the code clean, modular, and under 5 seconds total run_time. Do not use random pixel offsets; strictly use `next_to` with `buff=0` for perfect grid locking."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
493
  }
494
  return examples.get(example, "")
495
 
@@ -504,7 +523,7 @@ with gr.Blocks(css=custom_css, title="SciVisual-Agent") as demo:
504
  <div class="kicker">Physics & Mathematics Virtual Animation Lab</div>
505
  <h1 class="cyber-title">SciVisual-Agent</h1>
506
  <p class="cyber-subtitle">
507
- Turn math and physics ideas into animated Manim videos.
508
  </p>
509
  </div>
510
 
@@ -517,7 +536,7 @@ with gr.Blocks(css=custom_css, title="SciVisual-Agent") as demo:
517
  with gr.Column(scale=5, elem_classes=["panel-left"]):
518
  prompt = gr.Textbox(
519
  label="Describe the animation",
520
- placeholder="Example: Show how a square wave is built from the first seven Fourier components.",
521
  lines=8,
522
  max_lines=14,
523
  interactive=True,
@@ -535,7 +554,7 @@ with gr.Blocks(css=custom_css, title="SciVisual-Agent") as demo:
535
  clear_btn = gr.Button("Clear", elem_id="clear-btn")
536
 
537
  example_choice = gr.Radio(
538
- choices=["Simple Pendulum", "Spring Mass", "Visual proof (a+b)² = a² + 2ab + b²",],
539
  label="Quick Examples",
540
  value=None,
541
  interactive=True,
@@ -554,7 +573,7 @@ with gr.Blocks(css=custom_css, title="SciVisual-Agent") as demo:
554
  gr.HTML('<div class="panel-title">Output Observatory</div>')
555
  with gr.Tabs():
556
  with gr.Tab("Rendered Video"):
557
- video = gr.Video(label=None, elem_id="render-video", height=560)
558
  with gr.Tab("Generated Code"):
559
  source = gr.Textbox(
560
  label="Clean Python Source",
 
74
  }
75
 
76
  #sci-shell {
 
77
  margin: 0 auto;
78
  padding: 18px 0 26px;
79
  }
 
428
  4. Strict Animation Speed (CRITICAL SPEED FIX):
429
  - Animate the tracker `t` from 0 to 2*PI using `self.play(t.animate.set_value(2 * PI), run_time=6, rate_func=linear)`.
430
  - YOU MUST EXPLICITLY INCLUDE `rate_func=linear` to eliminate the default smooth easing effect. This ensures that time 't' updates at a perfectly constant velocity, making the physical oscillation and graph rendering completely uniform from start to finish.""",
431
+
432
  "Orbit": """Create a beautiful, scientifically accurate 2D physics animation of a satellite in an elliptical orbit around Earth using ManimCE.
433
 
434
  Requirements:
 
448
  - In the top-right corner, add a LaTeX mathematical text displaying Newton's Law of Universal Gravitation: "F_g = G * (M_1 * M_2) / r²".
449
 
450
  4. Animation flow: Run the animation for 2 complete orbital periods (about 10-12 seconds) so the viewer can clearly observe the dramatic speeding up at the close approach and slowing down at the far end. Wrap everything inside a single clean Scene class.""",
451
+
452
  "Simple Pendulum": """Create a high-quality Physics simulation of a Damped Simple Pendulum using ManimCE.
453
 
454
  Requirements:
 
490
  - Step 3: Animate the two Rectangle blocks (ab) creating themselves using `Create` to fill the remaining empty corners (1.5s).
491
  - Step 4: Display the labels inside each block using `Write`.
492
 
493
+ 6. Constraint: Keep the code clean, modular, and under 5 seconds total run_time. Do not use random pixel offsets; strictly use `next_to` with `buff=0` for perfect grid locking.""",
494
+
495
+ "Fourier Series" : """Animate the geometric construction of a square wave using its first 7 Fourier components (odd harmonics: n=1,3,5,7,9,11,13) in ManimCE. Fix the always_redraw compilation conflict.
496
+
497
+ Requirements:
498
+ 1. Math Equations:
499
+ - Base square wave graph: `axes.plot(lambda x: np.sign(np.sin(x)), color=RED)`. (Do NOT wrap this static red wave in always_redraw).
500
+ - Fourier mathematical sum formula inside the loop: `sum((4 / (n * PI)) * np.sin(n * x) for n in range(1, 2 * int(N_tracker.get_value()), 2))`.
501
+
502
+ 2. Correct Animation Sequence (CRITICAL GRAPHICS FIX):
503
+ - Step 1: Add the Axes and the static red square wave directly to the scene using `self.add(axes, square_wave)`.
504
+ - Step 2: Create a STATIC fundamental sine wave curve (where N=1 hardcoded) using `fourier_base = axes.plot(lambda x: (4 / PI) * np.sin(x), color=YELLOW)`. Animate this static line with `self.play(Create(fourier_base), run_time=1.0)`. This guarantees a beautiful, bug-free drawing effect from left to right in the first second.
505
+ - Step 3: Initialize `N_tracker = ValueTracker(1)`. Now, introduce the dynamic morphing curve using `always_redraw`. Inside its lambda, it must calculate the Fourier sum based on `N_tracker.get_value()`.
506
+ - Step 4: Use `self.add(fourier_dynamic)` to overlay it, remove the static `fourier_base`, and immediately animate `N_tracker` from 1 to 7 using `self.play(N_tracker.animate.set_value(7), run_time=4.5, rate_func=linear)`.
507
+
508
+ 3. Ensure no while-loops are used. The transition between the static line and the morphing line must be seamless.""",
509
+
510
+
511
+
512
  }
513
  return examples.get(example, "")
514
 
 
523
  <div class="kicker">Physics & Mathematics Virtual Animation Lab</div>
524
  <h1 class="cyber-title">SciVisual-Agent</h1>
525
  <p class="cyber-subtitle">
526
+ Turn maths and physics ideas into <b>accurate</b> animated Manim videos.
527
  </p>
528
  </div>
529
 
 
536
  with gr.Column(scale=5, elem_classes=["panel-left"]):
537
  prompt = gr.Textbox(
538
  label="Describe the animation",
539
+ placeholder="Please enter your animation description or select one of the examples below.",
540
  lines=8,
541
  max_lines=14,
542
  interactive=True,
 
554
  clear_btn = gr.Button("Clear", elem_id="clear-btn")
555
 
556
  example_choice = gr.Radio(
557
+ choices=["Simple Pendulum", "Spring Mass", "Visual proof (a+b)² = a² + 2ab + b²", "Fourier Series"],
558
  label="Quick Examples",
559
  value=None,
560
  interactive=True,
 
573
  gr.HTML('<div class="panel-title">Output Observatory</div>')
574
  with gr.Tabs():
575
  with gr.Tab("Rendered Video"):
576
+ video = gr.Video(label=None, elem_id="render-video", height=560, autoplay=True, loop=True)
577
  with gr.Tab("Generated Code"):
578
  source = gr.Textbox(
579
  label="Clean Python Source",