Spaces:
Running
Running
Commit ·
aa1c07c
1
Parent(s): e0b1f47
UP
Browse files
utils.py
CHANGED
|
@@ -33,25 +33,35 @@ def extract_pdf_text(pdf_path: str) -> str:
|
|
| 33 |
|
| 34 |
# ── Gemini LLM ────────────────────────────────────────────────────────────────
|
| 35 |
|
| 36 |
-
def generate_manim_code(prompt_text: str, api_key: str)
|
| 37 |
-
"""Stream Manim code from Gemini."""
|
| 38 |
client = genai.Client(api_key=api_key)
|
| 39 |
-
model = "gemini-
|
|
|
|
| 40 |
contents = [
|
| 41 |
-
types.Content(
|
|
|
|
|
|
|
|
|
|
| 42 |
]
|
|
|
|
| 43 |
config = types.GenerateContentConfig(
|
| 44 |
-
thinking_config=types.ThinkingConfig(
|
|
|
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
code = ""
|
| 48 |
for chunk in client.models.generate_content_stream(
|
| 49 |
-
model=model,
|
|
|
|
|
|
|
| 50 |
):
|
| 51 |
if chunk.text:
|
| 52 |
code += chunk.text
|
| 53 |
-
|
| 54 |
|
|
|
|
| 55 |
|
| 56 |
def sanitize_manim_code(raw: str, job_id: str) -> str:
|
| 57 |
"""
|
|
|
|
| 33 |
|
| 34 |
# ── Gemini LLM ────────────────────────────────────────────────────────────────
|
| 35 |
|
| 36 |
+
def generate_manim_code(prompt_text: str, api_key: str):
|
| 37 |
+
"""Stream Manim code from Gemini 3 Flash Preview and return it as a string."""
|
| 38 |
client = genai.Client(api_key=api_key)
|
| 39 |
+
model = "gemini-3-flash-preview"
|
| 40 |
+
|
| 41 |
contents = [
|
| 42 |
+
types.Content(
|
| 43 |
+
role="user",
|
| 44 |
+
parts=[types.Part.from_text(text=prompt_text)]
|
| 45 |
+
)
|
| 46 |
]
|
| 47 |
+
|
| 48 |
config = types.GenerateContentConfig(
|
| 49 |
+
thinking_config=types.ThinkingConfig(
|
| 50 |
+
thinking_level="HIGH"
|
| 51 |
+
)
|
| 52 |
)
|
| 53 |
|
| 54 |
code = ""
|
| 55 |
for chunk in client.models.generate_content_stream(
|
| 56 |
+
model=model,
|
| 57 |
+
contents=contents,
|
| 58 |
+
config=config
|
| 59 |
):
|
| 60 |
if chunk.text:
|
| 61 |
code += chunk.text
|
| 62 |
+
print(chunk.text, end="") # optional live streaming output
|
| 63 |
|
| 64 |
+
return code
|
| 65 |
|
| 66 |
def sanitize_manim_code(raw: str, job_id: str) -> str:
|
| 67 |
"""
|