Refresh example prompts
Browse filesCo-authored-by: Codex <codex@openai.com>
app.py
CHANGED
|
@@ -303,6 +303,7 @@ button:hover,
|
|
| 303 |
min-height: 430px !important;
|
| 304 |
color: #d9fff8 !important;
|
| 305 |
font-size: 13px !important;
|
|
|
|
| 306 |
}
|
| 307 |
|
| 308 |
.tabs,
|
|
@@ -403,7 +404,31 @@ def run_visual_lab(prompt: str, retries: int) -> Tuple[str | None, str, str]:
|
|
| 403 |
|
| 404 |
def load_example(example: str) -> str:
|
| 405 |
examples = {
|
| 406 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 407 |
"Orbit": """Create a beautiful, scientifically accurate 2D physics animation of a satellite in an elliptical orbit around Earth using ManimCE.
|
| 408 |
|
| 409 |
Requirements:
|
|
@@ -423,7 +448,6 @@ Requirements:
|
|
| 423 |
- 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²".
|
| 424 |
|
| 425 |
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.""",
|
| 426 |
-
"Eigen": "Explain eigenvectors of a 2D linear transformation using a grid, two vectors, and the transformed plane.",
|
| 427 |
"Simple Pendulum": """Create a high-quality Physics simulation of a Damped Simple Pendulum using ManimCE.
|
| 428 |
|
| 429 |
Requirements:
|
|
@@ -431,14 +455,41 @@ Requirements:
|
|
| 431 |
|
| 432 |
2. Visual Elements (Strict Coordinate Updates):
|
| 433 |
- A fixed ceiling line or pivot dot at the top center.
|
| 434 |
-
- A colored dot (e.g., Cyber Cyan or Neon Pink) representing the heavy bob.
|
| 435 |
- A clean line representing the pendulum rod that attaches the pivot to the bob. CRITICAL: You must attach an updater to this rod using `add_updater` so that its end position dynamically calls `rod.put_start_and_end_on(pivot.get_center(), bob.get_center())` at every single frame. The rod must always move dynamically with the bob.
|
| 436 |
- Add an elegant fading trace/trail (`TracedPath`) attached to the bob to visually map its decaying sinusoidal path across the screen over time.
|
| 437 |
|
| 438 |
3. Mathematical Overlay: In the upper left corner, display the differential equation governing the motion: "d²θ/dt² + (b/m)dθ/dt + (g/L)sin(θ) = 0" rendered beautifully via LaTeX.
|
| 439 |
|
| 440 |
-
4. Animation flow: Let the simulation run smoothly for 12 seconds to clearly demonstrate the kinetic energy converting to thermal energy as the oscillation slowly dampens to a complete halt. Ensure the code is self-contained and wrapped inside a single executable Scene class.
|
| 441 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 442 |
}
|
| 443 |
return examples.get(example, "")
|
| 444 |
|
|
@@ -484,8 +535,8 @@ with gr.Blocks(css=custom_css, title="SciVisual-Agent") as demo:
|
|
| 484 |
clear_btn = gr.Button("Clear", elem_id="clear-btn")
|
| 485 |
|
| 486 |
example_choice = gr.Radio(
|
| 487 |
-
choices=["Simple Pendulum", "
|
| 488 |
-
label="Quick
|
| 489 |
value=None,
|
| 490 |
interactive=True,
|
| 491 |
)
|
|
|
|
| 303 |
min-height: 430px !important;
|
| 304 |
color: #d9fff8 !important;
|
| 305 |
font-size: 13px !important;
|
| 306 |
+
overflow-y: scroll !important;
|
| 307 |
}
|
| 308 |
|
| 309 |
.tabs,
|
|
|
|
| 404 |
|
| 405 |
def load_example(example: str) -> str:
|
| 406 |
examples = {
|
| 407 |
+
"Spring Mass": """Create a professional 2D physics simulation of a horizontal spring-mass system with a real-time synchronized position graph using ManimCE. Fix the velocity easing issue.
|
| 408 |
+
|
| 409 |
+
Requirements:
|
| 410 |
+
1. Layout & Axes:
|
| 411 |
+
- Shift the entire Spring-Mass system to the upper half (around y = 1.5).
|
| 412 |
+
- In the lower half (centered at y = -2), create a coordinate system `Axes` using `Axes(x_range=[0, 7, 1], y_range=[-2.5, 2.5, 1], x_length=7, y_length=3)`. Color the axes WHITE and add labels "Time (t)" and "Position (x)".
|
| 413 |
+
|
| 414 |
+
2. Physical Objects:
|
| 415 |
+
- Vertical wall at x = -4 (from y = 0.5 to y = 2.5), color = WHITE.
|
| 416 |
+
- Horizontal track from x = -4 to x = 4 at y = 1.2, color = WHITE.
|
| 417 |
+
- Mass block using `Square(side_length=0.6, color=PURPLE, fill_opacity=0.8)`.
|
| 418 |
+
- Use a `ValueTracker(0)` for time `t`.
|
| 419 |
+
- Update the block's center position via `add_updater` to be exactly at `np.array([2 * np.cos(3 * t.get_value()), 1.5, 0])`.
|
| 420 |
+
- Create the spring using `always_redraw`. Calculate `L = mass.get_left()[0] - (-4)`. Use `ParametricFunction` with `t_range=[0, 1]` where:
|
| 421 |
+
* x_func(u) = -4 + u * L
|
| 422 |
+
* y_func(u) = 1.5 + 0.3 * np.sin(2 * np.pi * 8 * u)
|
| 423 |
+
Color the spring WHITE.
|
| 424 |
+
|
| 425 |
+
3. Graph Synchronization:
|
| 426 |
+
- Create an orange dynamic dot on the graph tracker using `add_updater` at `axes.c2p(t.get_value(), 2 * np.cos(3 * t.get_value()), 0)`.
|
| 427 |
+
- Create the graph line using `always_redraw` plotting `axes.plot(lambda time: 2 * np.cos(3 * time), x_range=[0, max(0.001, t.get_value())], color=ORANGE)`.
|
| 428 |
+
|
| 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 |
- 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:
|
|
|
|
| 455 |
|
| 456 |
2. Visual Elements (Strict Coordinate Updates):
|
| 457 |
- A fixed ceiling line or pivot dot at the top center.
|
| 458 |
+
- A colored dot (e.g., Cyber Cyan or Neon Pink) representing the heavy bob.
|
| 459 |
- A clean line representing the pendulum rod that attaches the pivot to the bob. CRITICAL: You must attach an updater to this rod using `add_updater` so that its end position dynamically calls `rod.put_start_and_end_on(pivot.get_center(), bob.get_center())` at every single frame. The rod must always move dynamically with the bob.
|
| 460 |
- Add an elegant fading trace/trail (`TracedPath`) attached to the bob to visually map its decaying sinusoidal path across the screen over time.
|
| 461 |
|
| 462 |
3. Mathematical Overlay: In the upper left corner, display the differential equation governing the motion: "d²θ/dt² + (b/m)dθ/dt + (g/L)sin(θ) = 0" rendered beautifully via LaTeX.
|
| 463 |
|
| 464 |
+
4. Animation flow: Let the simulation run smoothly for 12 seconds to clearly demonstrate the kinetic energy converting to thermal energy as the oscillation slowly dampens to a complete halt. Ensure the code is self-contained and wrapped inside a single executable Scene class.""",
|
| 465 |
+
"Visual proof (a+b)² = a² + 2ab + b²": """Create a perfect 2D geometric animation proving the identity (a+b)² = a² + 2ab + b² using ManimCE based on strict quadrant alignment. Fix the overlapping bug.
|
| 466 |
+
|
| 467 |
+
Requirements:
|
| 468 |
+
1. Geometry & Scale Setup:
|
| 469 |
+
- Define lengths: a = 2.0 and b = 1.0.
|
| 470 |
+
- Define a central intersection origin point: `origin = np.array([0, 0, 0])`. All blocks must be strictly positioned relative to this point by alignment.
|
| 471 |
+
|
| 472 |
+
2. Precise Corner Alignment (CRITICAL OVERLAP FIX):
|
| 473 |
+
- Block 1 (Square a²): Create a Square with side_length=a, color=BLUE. Use `.next_to(origin, UL, buff=0)` or explicitly align its bottom-right corner to `origin` so it sits entirely in the Upper-Left quadrant.
|
| 474 |
+
- Block 2 (Square b²): Create a Square with side_length=b, color=PINK. Use `.next_to(origin, DR, buff=0)` or explicitly align its top-left corner to `origin` so it sits entirely in the Lower-Right quadrant.
|
| 475 |
+
- Block 3 (Rectangle ab - Top Right): Create a Rectangle with width=b, height=a, color=GREEN. Use `.next_to(origin, UR, buff=0)` or align its bottom-left corner to `origin` so it sits entirely in the Upper-Right quadrant.
|
| 476 |
+
- Block 4 (Rectangle ab - Bottom Left): Create a Rectangle with width=a, height=b, color=GREEN. Use `.next_to(origin, DL, buff=0)` or align its top-right corner to `origin` so it sits entirely in the Lower-Left quadrant.
|
| 477 |
+
- Set fill_opacity=0.5 and stroke_color=WHITE for all 4 blocks.
|
| 478 |
+
|
| 479 |
+
3. Main Outer Square Framework:
|
| 480 |
+
- Create a large outer Square with side_length=(a+b) to represent the final boundary. Center it precisely at the combined visual center of the 4 blocks, which is `np.array([(-a+b)/2, (a-b)/2, 0])`. Color it WHITE with a thin stroke width, without fill.
|
| 481 |
+
|
| 482 |
+
4. Text Labels & Math Mapping:
|
| 483 |
+
- Place MathTex text labels ("a²", "b²", "ab", "ab") centered inside each corresponding block using `.move_to(block.get_center())`. Note: Labels must be created and positioned AFTER the blocks have been moved to their correct quadrants.
|
| 484 |
+
- Place the formula "(a + b)² = a² + 2ab + b²" at the top edge of the screen.
|
| 485 |
+
|
| 486 |
+
5. Animation Sequence:
|
| 487 |
+
- Step 1: Write the formula at the top and create the thin outer main square framework first (1.5s).
|
| 488 |
+
- Step 2: Draw Block 1 (a²) and Block 2 (b²) simultaneously using `FadeIn` (1s).
|
| 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 |
|
|
|
|
| 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,
|
| 542 |
)
|