Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -115,9 +115,9 @@ def render_video(prompt, quality="low"):
|
|
| 115 |
"""Main function to generate and render Manim video"""
|
| 116 |
|
| 117 |
try:
|
| 118 |
-
# Create temp directory
|
| 119 |
-
|
| 120 |
-
temp_dir.
|
| 121 |
|
| 122 |
yield "🤖 Generating code...", None, None
|
| 123 |
|
|
@@ -142,23 +142,27 @@ def render_video(prompt, quality="low"):
|
|
| 142 |
|
| 143 |
class_name = match.group(1)
|
| 144 |
|
| 145 |
-
# Save code
|
| 146 |
code_file = temp_dir / "animation.py"
|
| 147 |
with open(code_file, 'w', encoding='utf-8') as f:
|
| 148 |
f.write(code)
|
| 149 |
|
| 150 |
yield f"✓ Code generated (Scene: {class_name})\n🎬 Rendering video...", code, None
|
| 151 |
|
| 152 |
-
# Render video
|
| 153 |
quality_map = {'low': '-ql', 'medium': '-qm', 'high': '-qh'}
|
| 154 |
quality_flag = quality_map.get(quality, '-ql')
|
| 155 |
|
| 156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
process = subprocess.Popen(
|
| 159 |
command, shell=True,
|
| 160 |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
| 161 |
-
text=True
|
| 162 |
)
|
| 163 |
|
| 164 |
output_lines = []
|
|
|
|
| 115 |
"""Main function to generate and render Manim video"""
|
| 116 |
|
| 117 |
try:
|
| 118 |
+
# Create temp directory in /tmp to avoid path issues
|
| 119 |
+
import tempfile
|
| 120 |
+
temp_dir = Path(tempfile.mkdtemp(prefix="manim_"))
|
| 121 |
|
| 122 |
yield "🤖 Generating code...", None, None
|
| 123 |
|
|
|
|
| 142 |
|
| 143 |
class_name = match.group(1)
|
| 144 |
|
| 145 |
+
# Save code to absolute path
|
| 146 |
code_file = temp_dir / "animation.py"
|
| 147 |
with open(code_file, 'w', encoding='utf-8') as f:
|
| 148 |
f.write(code)
|
| 149 |
|
| 150 |
yield f"✓ Code generated (Scene: {class_name})\n🎬 Rendering video...", code, None
|
| 151 |
|
| 152 |
+
# Render video with absolute paths
|
| 153 |
quality_map = {'low': '-ql', 'medium': '-qm', 'high': '-qh'}
|
| 154 |
quality_flag = quality_map.get(quality, '-ql')
|
| 155 |
|
| 156 |
+
# Use absolute path for the file
|
| 157 |
+
abs_code_file = str(code_file.absolute())
|
| 158 |
+
media_dir = str((temp_dir / "media").absolute())
|
| 159 |
+
|
| 160 |
+
command = f"manim {abs_code_file} {class_name} {quality_flag} --disable_caching --media_dir {media_dir}"
|
| 161 |
|
| 162 |
process = subprocess.Popen(
|
| 163 |
command, shell=True,
|
| 164 |
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
| 165 |
+
text=True
|
| 166 |
)
|
| 167 |
|
| 168 |
output_lines = []
|