Update app.py
Browse files233 unmodified lines234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349233 unmodified linesif 5>1:print(raw_body)'''nlist = ast.literal_eval(cleaned)datalst=[]for line in range(len(nlist)):datalst.append({"type": nlist[line][0].strip(),"content": nlist[line][1].strip(),"animation": nlist[line][2].strip().replace(" ",""),"duration": nlist[line][3]})data={"video_settings": {"background_color": "#0f0f23","text_color": "WHITE","highlight_color": "YELLOW","font": "CMU Serif","text_size": 36,"equation_size": 42,"title_size": 48},"slides":datalst}''''''# Now proceed with video generation using 'data'print(json.dumps(data, indent=2)) # For debugging# ✅ Final validationif "slides" not in data or not data["slides"]:return jsonify({"error": "No slides provided in request"}), 400print(f"✅ Parsed {len(data['slides'])} slides successfully.")# Validate inputif "slides" not in data or not data["slides"]:return jsonify({"error": "No slides provided in request"}), 400print(f"Received request with {len(data['slides'])} slides")# Create unique temporary directorytimestamp = datetime.now().strftime("%Y%m%d_%H%M%S")temp_work_dir = os.path.join(TEMP_DIR, f"manim_{timestamp}")os.makedirs(temp_work_dir, exist_ok=True)# Generate Manim scriptscript_path = os.path.join(temp_work_dir, "scene.py")create_manim_script(data, script_path)print(f"Created Manim script at {script_path}")# Render video using subprocessquality = 'l' # l=low, m=medium, h=highrender_command = ["manim",f"-q{quality}","--disable_caching","--media_dir", temp_work_dir,script_path,"GeneratedMathScene"]print(f"Running command: {' '.join(render_command)}")result = subprocess.run(render_command,capture_output=True,text=True,cwd=temp_work_dir,timeout=120)if result.returncode != 0:error_msg = result.stderr or result.stdoutprint(f"Manim rendering failed: {error_msg}")return jsonify({"error": "Manim rendering failed","details": error_msg}), 500print("Manim rendering completed successfully")# Find generated videoquality_map = {'l': '480p15', 'm': '720p30', 'h': '1080p60'}video_quality = quality_map.get(quality, '480p15')video_path = os.path.join(temp_work_dir,"videos","scene",video_quality,"GeneratedMathScene.mp4")if not os.path.exists(video_path):print(f"Video not found at expected path: {video_path}")return jsonify({"error": "Video file not found after rendering","expected_path": video_path}), 500print(f"Video found at: {video_path}")# Copy to media directoryoutput_filename = f"math_video_{timestamp}.mp4"output_path = os.path.join(MEDIA_DIR, output_filename)shutil.copy(video_path, output_path)print(f"Video copied to: {output_path}")# Clean up temp directorytry:shutil.rmtree(temp_work_dir)print("Cleaned up temp directory")except Exception as e:print(f"Failed to clean temp dir: {e}")'''# Return video file as bloboutput_path="https://videos.pexels.com/video-files/3173312/3173312-uhd_2560_1440_30fps.mp4"233 unmodified lines234235236237238239240233 unmodified linesif 5>1:print(raw_body)# Return video file as bloboutput_path="https://videos.pexels.com/video-files/3173312/3173312-uhd_2560_1440_30fps.mp4"
app.py+1-110