Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from flask import Flask, render_template, request, url_for, send_from_directory
|
2 |
from google import genai
|
3 |
import re
|
4 |
import subprocess
|
@@ -78,11 +78,13 @@ You got this!! <3
|
|
78 |
time.sleep(2)
|
79 |
continue
|
80 |
|
|
|
81 |
video_path_in_media = os.path.join("media", "videos", code_filename.replace(".py", ""), "720p30", video_filename)
|
82 |
-
|
|
|
83 |
|
84 |
try:
|
85 |
-
shutil.move(video_path_in_media,
|
86 |
except FileNotFoundError:
|
87 |
print("Manim output file not found. Check your manim code and output location.")
|
88 |
time.sleep(2)
|
@@ -92,6 +94,7 @@ You got this!! <3
|
|
92 |
time.sleep(2)
|
93 |
continue
|
94 |
|
|
|
95 |
video_url = url_for('get_video', filename=video_filename)
|
96 |
return render_template("result.html", video_url=video_url)
|
97 |
|
@@ -99,9 +102,10 @@ You got this!! <3
|
|
99 |
|
100 |
@app.route("/video/<filename>")
|
101 |
def get_video(filename):
|
102 |
-
video_path = os.path.join("
|
103 |
-
response = send_from_directory("
|
104 |
|
|
|
105 |
def remove_file():
|
106 |
try:
|
107 |
os.remove(video_path)
|
|
|
1 |
+
from flask import Flask, render_template, request, url_for, send_from_directory
|
2 |
from google import genai
|
3 |
import re
|
4 |
import subprocess
|
|
|
78 |
time.sleep(2)
|
79 |
continue
|
80 |
|
81 |
+
# Construct the expected output path from Manim
|
82 |
video_path_in_media = os.path.join("media", "videos", code_filename.replace(".py", ""), "720p30", video_filename)
|
83 |
+
# Instead of moving to a read-only directory, move it to /tmp (which is writable)
|
84 |
+
tmp_video_path = os.path.join("/tmp", video_filename)
|
85 |
|
86 |
try:
|
87 |
+
shutil.move(video_path_in_media, tmp_video_path)
|
88 |
except FileNotFoundError:
|
89 |
print("Manim output file not found. Check your manim code and output location.")
|
90 |
time.sleep(2)
|
|
|
94 |
time.sleep(2)
|
95 |
continue
|
96 |
|
97 |
+
# Generate a URL that points to the get_video route
|
98 |
video_url = url_for('get_video', filename=video_filename)
|
99 |
return render_template("result.html", video_url=video_url)
|
100 |
|
|
|
102 |
|
103 |
@app.route("/video/<filename>")
|
104 |
def get_video(filename):
|
105 |
+
video_path = os.path.join("/tmp", filename)
|
106 |
+
response = send_from_directory("/tmp", filename)
|
107 |
|
108 |
+
# Schedule deletion of the video file after 5 seconds
|
109 |
def remove_file():
|
110 |
try:
|
111 |
os.remove(video_path)
|