Spaces:
Running
Running
Commit ·
9c4fab2
1
Parent(s): a9334c7
update for better outputs
Browse files
utils.py
CHANGED
|
@@ -29,10 +29,31 @@ def extract_pdf_text(pdf_path: str) -> str:
|
|
| 29 |
|
| 30 |
def generate_manim_code(prompt_text: str, api_key: str) -> str:
|
| 31 |
"""Stream Manim code from Gemini 3 Flash Preview and return it as a string."""
|
|
|
|
| 32 |
client = genai.Client(api_key=api_key)
|
| 33 |
model = "gemini-3-flash-preview"
|
| 34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
contents = [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
types.Content(
|
| 37 |
role="user",
|
| 38 |
parts=[types.Part.from_text(text=prompt_text)]
|
|
@@ -57,7 +78,6 @@ def generate_manim_code(prompt_text: str, api_key: str) -> str:
|
|
| 57 |
|
| 58 |
return code
|
| 59 |
|
| 60 |
-
|
| 61 |
# ── Manim Code Sanitisation ───────────────────────────────────────────────────
|
| 62 |
|
| 63 |
def sanitize_manim_code(raw: str) -> str:
|
|
|
|
| 29 |
|
| 30 |
def generate_manim_code(prompt_text: str, api_key: str) -> str:
|
| 31 |
"""Stream Manim code from Gemini 3 Flash Preview and return it as a string."""
|
| 32 |
+
|
| 33 |
client = genai.Client(api_key=api_key)
|
| 34 |
model = "gemini-3-flash-preview"
|
| 35 |
|
| 36 |
+
# Robust system prompt
|
| 37 |
+
system_prompt = """
|
| 38 |
+
You are an expert Python developer and Manim animation engineer.
|
| 39 |
+
Always produce code that:
|
| 40 |
+
- Is fully correct and runnable with Manim v1.0+.
|
| 41 |
+
- Uses clear, readable structure, proper imports, and PEP8-compliant formatting.
|
| 42 |
+
- Produces visually correct animations based on the user's description.
|
| 43 |
+
- Minimizes unnecessary complexity but keeps clarity.
|
| 44 |
+
- Names the main scene class `OutputVideo`.
|
| 45 |
+
- Returns code only, without extra explanation or markdown fences.
|
| 46 |
+
- Handles edge cases gracefully.
|
| 47 |
+
- Uses comments sparingly, only when clarifying complex parts.
|
| 48 |
+
- When in doubt, use Google search effectively to verify facts, functions, or best practices.
|
| 49 |
+
Always ensure your output is precise, accurate, and complete.
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
contents = [
|
| 53 |
+
types.Content(
|
| 54 |
+
role="system",
|
| 55 |
+
parts=[types.Part.from_text(text=system_prompt)]
|
| 56 |
+
),
|
| 57 |
types.Content(
|
| 58 |
role="user",
|
| 59 |
parts=[types.Part.from_text(text=prompt_text)]
|
|
|
|
| 78 |
|
| 79 |
return code
|
| 80 |
|
|
|
|
| 81 |
# ── Manim Code Sanitisation ───────────────────────────────────────────────────
|
| 82 |
|
| 83 |
def sanitize_manim_code(raw: str) -> str:
|