sreepathi-ravikumar commited on
Commit
dbe2b49
·
verified ·
1 Parent(s): 12fb87b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -110
app.py CHANGED
@@ -234,116 +234,7 @@ def generate_video():
234
  if 5>1:
235
  print(raw_body)
236
 
237
- '''
238
- nlist = ast.literal_eval(cleaned)
239
- datalst=[]
240
- for line in range(len(nlist)):
241
- datalst.append({
242
- "type": nlist[line][0].strip(),
243
- "content": nlist[line][1].strip(),
244
- "animation": nlist[line][2].strip().replace(" ",""),
245
- "duration": nlist[line][3]
246
- })
247
-
248
- data={
249
- "video_settings": {
250
- "background_color": "#0f0f23",
251
- "text_color": "WHITE",
252
- "highlight_color": "YELLOW",
253
- "font": "CMU Serif",
254
- "text_size": 36,
255
- "equation_size": 42,
256
- "title_size": 48
257
- },
258
- "slides":datalst}'''
259
- '''# Now proceed with video generation using 'data'
260
- print(json.dumps(data, indent=2)) # For debugging
261
- # ✅ Final validation
262
- if "slides" not in data or not data["slides"]:
263
- return jsonify({"error": "No slides provided in request"}), 400
264
-
265
- print(f"✅ Parsed {len(data['slides'])} slides successfully.")
266
-
267
- # Validate input
268
- if "slides" not in data or not data["slides"]:
269
- return jsonify({"error": "No slides provided in request"}), 400
270
-
271
- print(f"Received request with {len(data['slides'])} slides")
272
-
273
- # Create unique temporary directory
274
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
275
- temp_work_dir = os.path.join(TEMP_DIR, f"manim_{timestamp}")
276
- os.makedirs(temp_work_dir, exist_ok=True)
277
-
278
- # Generate Manim script
279
- script_path = os.path.join(temp_work_dir, "scene.py")
280
- create_manim_script(data, script_path)
281
- print(f"Created Manim script at {script_path}")
282
-
283
- # Render video using subprocess
284
- quality = 'l' # l=low, m=medium, h=high
285
- render_command = [
286
- "manim",
287
- f"-q{quality}",
288
- "--disable_caching",
289
- "--media_dir", temp_work_dir,
290
- script_path,
291
- "GeneratedMathScene"
292
- ]
293
-
294
- print(f"Running command: {' '.join(render_command)}")
295
-
296
- result = subprocess.run(
297
- render_command,
298
- capture_output=True,
299
- text=True,
300
- cwd=temp_work_dir,
301
- timeout=120
302
- )
303
-
304
- if result.returncode != 0:
305
- error_msg = result.stderr or result.stdout
306
- print(f"Manim rendering failed: {error_msg}")
307
- return jsonify({
308
- "error": "Manim rendering failed",
309
- "details": error_msg
310
- }), 500
311
-
312
- print("Manim rendering completed successfully")
313
-
314
- # Find generated video
315
- quality_map = {'l': '480p15', 'm': '720p30', 'h': '1080p60'}
316
- video_quality = quality_map.get(quality, '480p15')
317
-
318
- video_path = os.path.join(
319
- temp_work_dir,
320
- "videos",
321
- "scene",
322
- video_quality,
323
- "GeneratedMathScene.mp4"
324
- )
325
-
326
- if not os.path.exists(video_path):
327
- print(f"Video not found at expected path: {video_path}")
328
- return jsonify({
329
- "error": "Video file not found after rendering",
330
- "expected_path": video_path
331
- }), 500
332
-
333
- print(f"Video found at: {video_path}")
334
-
335
- # Copy to media directory
336
- output_filename = f"math_video_{timestamp}.mp4"
337
- output_path = os.path.join(MEDIA_DIR, output_filename)
338
- shutil.copy(video_path, output_path)
339
- print(f"Video copied to: {output_path}")
340
-
341
- # Clean up temp directory
342
- try:
343
- shutil.rmtree(temp_work_dir)
344
- print("Cleaned up temp directory")
345
- except Exception as e:
346
- print(f"Failed to clean temp dir: {e}")'''
347
 
348
  # Return video file as blob
349
  output_path="https://videos.pexels.com/video-files/3173312/3173312-uhd_2560_1440_30fps.mp4"
 
234
  if 5>1:
235
  print(raw_body)
236
 
237
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
 
239
  # Return video file as blob
240
  output_path="https://videos.pexels.com/video-files/3173312/3173312-uhd_2560_1440_30fps.mp4"