Spanicin commited on
Commit
cd9bf20
·
verified ·
1 Parent(s): 318ef56

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -45
app.py CHANGED
@@ -520,55 +520,79 @@ def generate_video():
520
  else:
521
  args.device = "cpu"
522
 
523
- generation_thread = threading.Thread(target=main, args=(args,))
524
- app.config['generation_thread'] = generation_thread
525
- generation_thread.start()
526
- response_data = {"message": "Video generation started",
527
- "process_id": generation_thread.ident}
528
 
529
- return jsonify(response_data)
 
 
 
530
 
 
 
 
 
 
 
531
 
532
- @app.route("/status", methods=["GET"])
533
- def check_generation_status():
534
- global TEMP_DIR
535
- global start_time
536
- response = {"base64_video": "","text_prompt":"", "status": ""}
537
- process_id = request.args.get('process_id', None)
538
-
539
- # process_id is required to check the status for that specific process
540
- if process_id:
541
- generation_thread = app.config.get('generation_thread')
542
- if generation_thread and generation_thread.ident == int(process_id) and generation_thread.is_alive():
543
- return jsonify({"status": "in_progress"}), 200
544
- elif app.config.get('temp_response'):
545
- # app.config['temp_response']['status'] = 'completed'
546
- final_response = app.config['temp_response']
547
- response["base64_video"] = final_response
548
- response["text_prompt"] = app.config.get('text_prompt')
549
- response["duration"] = app.config.get('final_video_duration')
550
- response["status"] = "completed"
551
-
552
- final_video_path = app.config['final_video_path']
553
- print('final_video_path',final_video_path)
554
-
555
-
556
- if final_video_path and os.path.exists(final_video_path):
557
- os.remove(final_video_path)
558
- print("Deleted video file:", final_video_path)
559
-
560
- # TEMP_DIR.cleanup()
561
- preprocess_dir = os.path.join("/tmp", "preprocess_data")
562
- custom_cleanup(TEMP_DIR.name, preprocess_dir)
563
-
564
- print("Temporary files cleaned up, but preprocess_data is retained.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
565
 
566
- end_time = time.time()
567
- total_time = round(end_time - start_time, 2)
568
- print("Total time taken for execution:", total_time, " seconds")
569
- response["time_taken"] = total_time
570
- return jsonify(response)
571
- return jsonify({"error":"No process id provided"})
572
 
573
  @app.route("/health", methods=["GET"])
574
  def health_status():
 
520
  else:
521
  args.device = "cpu"
522
 
523
+ # generation_thread = threading.Thread(target=main, args=(args,))
524
+ # app.config['generation_thread'] = generation_thread
525
+ # generation_thread.start()
526
+ # response_data = {"message": "Video generation started",
527
+ # "process_id": generation_thread.ident}
528
 
529
+ try:
530
+ base64_video, temp_file_path, duration = main(args)
531
+ final_video_path = app.config['final_video_path']
532
+ print('final_video_path',final_video_path)
533
 
534
+ if final_video_path and os.path.exists(final_video_path):
535
+ os.remove(final_video_path)
536
+ print("Deleted video file:", final_video_path)
537
+
538
+ preprocess_dir = os.path.join("/tmp", "preprocess_data")
539
+ custom_cleanup(TEMP_DIR.name, preprocess_dir)
540
 
541
+ print("Temporary files cleaned up, but preprocess_data is retained.")
542
+
543
+ return jsonify({
544
+ 'base64_video': base64_video,
545
+ 'text_prompt': text_prompt,
546
+ 'duration': duration,
547
+ 'status': 'completed'
548
+ })
549
+
550
+ except Exception as e:
551
+ return jsonify({'status': 'error', 'message': str(e)}), 500
552
+
553
+ # return jsonify(response_data)
554
+
555
+
556
+ # @app.route("/status", methods=["GET"])
557
+ # def check_generation_status():
558
+ # global TEMP_DIR
559
+ # global start_time
560
+ # response = {"base64_video": "","text_prompt":"", "status": ""}
561
+ # process_id = request.args.get('process_id', None)
562
+
563
+ # # process_id is required to check the status for that specific process
564
+ # if process_id:
565
+ # generation_thread = app.config.get('generation_thread')
566
+ # if generation_thread and generation_thread.ident == int(process_id) and generation_thread.is_alive():
567
+ # return jsonify({"status": "in_progress"}), 200
568
+ # elif app.config.get('temp_response'):
569
+ # # app.config['temp_response']['status'] = 'completed'
570
+ # final_response = app.config['temp_response']
571
+ # response["base64_video"] = final_response
572
+ # response["text_prompt"] = app.config.get('text_prompt')
573
+ # response["duration"] = app.config.get('final_video_duration')
574
+ # response["status"] = "completed"
575
+
576
+ # final_video_path = app.config['final_video_path']
577
+ # print('final_video_path',final_video_path)
578
+
579
+
580
+ # if final_video_path and os.path.exists(final_video_path):
581
+ # os.remove(final_video_path)
582
+ # print("Deleted video file:", final_video_path)
583
+
584
+ # # TEMP_DIR.cleanup()
585
+ # preprocess_dir = os.path.join("/tmp", "preprocess_data")
586
+ # custom_cleanup(TEMP_DIR.name, preprocess_dir)
587
+
588
+ # print("Temporary files cleaned up, but preprocess_data is retained.")
589
 
590
+ # end_time = time.time()
591
+ # total_time = round(end_time - start_time, 2)
592
+ # print("Total time taken for execution:", total_time, " seconds")
593
+ # response["time_taken"] = total_time
594
+ # return jsonify(response)
595
+ # return jsonify({"error":"No process id provided"})
596
 
597
  @app.route("/health", methods=["GET"])
598
  def health_status():