Spanicin commited on
Commit
3830020
·
verified ·
1 Parent(s): 3114eb3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +82 -60
app.py CHANGED
@@ -508,71 +508,93 @@ def generate_video():
508
  ref_pose_video.save(ref_pose_video_path)
509
  print('ref_pose_video_path',ref_pose_video_path)
510
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
  except Exception as e:
512
  app.logger.error(f"An error occurred: {e}")
513
  return "An error occurred", 500
514
-
515
- # Example of using the class with some hypothetical paths
516
- args = AnimationConfig(driven_audio_path=driven_audio_path, source_image_path=source_image_path, result_folder=result_folder, pose_style=pose_style, expression_scale=expression_scale,enhancer=enhancer,still=still,preprocess=preprocess,ref_pose_video_path=ref_pose_video_path, image_hardcoded=image_hardcoded)
517
-
518
- if torch.cuda.is_available() and not args.cpu:
519
- args.device = "cuda"
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
- # base64_video = main(args)
531
- # return jsonify({"base64_video": base64_video})
532
-
533
- #else:
534
- # return 'Unsupported HTTP method', 405
535
-
536
- @app.route("/status", methods=["GET"])
537
- def check_generation_status():
538
- global TEMP_DIR
539
- global start_time
540
- response = {"base64_video": "","text_prompt":"", "status": ""}
541
- process_id = request.args.get('process_id', None)
542
-
543
- # process_id is required to check the status for that specific process
544
- if process_id:
545
- generation_thread = app.config.get('generation_thread')
546
- if generation_thread and generation_thread.ident == int(process_id) and generation_thread.is_alive():
547
- return jsonify({"status": "in_progress"}), 200
548
- elif app.config.get('temp_response'):
549
- # app.config['temp_response']['status'] = 'completed'
550
- final_response = app.config['temp_response']
551
- response["base64_video"] = final_response
552
- response["text_prompt"] = app.config.get('text_prompt')
553
- response["duration"] = app.config.get('final_video_duration')
554
- response["status"] = "completed"
555
-
556
- final_video_path = app.config['final_video_path']
557
- print('final_video_path',final_video_path)
558
-
559
-
560
- if final_video_path and os.path.exists(final_video_path):
561
- os.remove(final_video_path)
562
- print("Deleted video file:", final_video_path)
563
-
564
- # TEMP_DIR.cleanup()
565
- preprocess_dir = os.path.join("/tmp", "preprocess_data")
566
- custom_cleanup(TEMP_DIR.name, preprocess_dir)
567
-
568
- print("Temporary files cleaned up, but preprocess_data is retained.")
569
 
570
- end_time = time.time()
571
- total_time = round(end_time - start_time, 2)
572
- print("Total time taken for execution:", total_time, " seconds")
573
- response["time_taken"] = total_time
574
- return jsonify(response)
575
- return jsonify({"error":"No process id provided"})
576
 
577
  @app.route("/health", methods=["GET"])
578
  def health_status():
 
508
  ref_pose_video.save(ref_pose_video_path)
509
  print('ref_pose_video_path',ref_pose_video_path)
510
 
511
+
512
+ # Example of using the class with some hypothetical paths
513
+ args = AnimationConfig(driven_audio_path=driven_audio_path, source_image_path=source_image_path, result_folder=result_folder, pose_style=pose_style, expression_scale=expression_scale,enhancer=enhancer,still=still,preprocess=preprocess,ref_pose_video_path=ref_pose_video_path, image_hardcoded=image_hardcoded)
514
+
515
+ if torch.cuda.is_available() and not args.cpu:
516
+ args.device = "cuda"
517
+ else:
518
+ args.device = "cpu"
519
+
520
+ generation_thread = threading.Thread(target=main, args=(args,))
521
+ app.config['generation_thread'] = generation_thread
522
+ generation_thread.start()
523
+ # response_data = {"message": "Video generation started",
524
+ # "process_id": generation_thread.ident}
525
+
526
+ # return jsonify(response_data)
527
+
528
+ while generation_thread.is_alive():
529
+ if app.config.get('temp_response'):
530
+ final_response = app.config['temp_response']
531
+ response_data = {
532
+ "base64_video": final_response,
533
+ "text_prompt": app.config.get('text_prompt'),
534
+ "duration": app.config.get('final_video_duration'),
535
+ "status": "completed"
536
+ }
537
+ final_video_path = app.config['final_video_path']
538
+ print('final_video_path', final_video_path)
539
+
540
+ if final_video_path and os.path.exists(final_video_path):
541
+ os.remove(final_video_path)
542
+ print("Deleted video file:", final_video_path)
543
+
544
+ preprocess_dir = os.path.join("/tmp", "preprocess_data")
545
+ custom_cleanup(TEMP_DIR.name, preprocess_dir)
546
+
547
+ end_time = time.time()
548
+ total_time = round(end_time - start_time, 2)
549
+ print("Total time taken for execution:", total_time, " seconds")
550
+ response_data["time_taken"] = total_time
551
+
552
+ return jsonify(response_data)
553
+
554
  except Exception as e:
555
  app.logger.error(f"An error occurred: {e}")
556
  return "An error occurred", 500
 
 
 
 
 
 
 
 
 
 
 
 
 
 
557
 
558
+ # @app.route("/status", methods=["GET"])
559
+ # def check_generation_status():
560
+ # global TEMP_DIR
561
+ # global start_time
562
+ # response = {"base64_video": "","text_prompt":"", "status": ""}
563
+ # process_id = request.args.get('process_id', None)
564
+
565
+ # # process_id is required to check the status for that specific process
566
+ # if process_id:
567
+ # generation_thread = app.config.get('generation_thread')
568
+ # if generation_thread and generation_thread.ident == int(process_id) and generation_thread.is_alive():
569
+ # return jsonify({"status": "in_progress"}), 200
570
+ # elif app.config.get('temp_response'):
571
+ # # app.config['temp_response']['status'] = 'completed'
572
+ # final_response = app.config['temp_response']
573
+ # response["base64_video"] = final_response
574
+ # response["text_prompt"] = app.config.get('text_prompt')
575
+ # response["duration"] = app.config.get('final_video_duration')
576
+ # response["status"] = "completed"
577
+
578
+ # final_video_path = app.config['final_video_path']
579
+ # print('final_video_path',final_video_path)
580
+
581
+
582
+ # if final_video_path and os.path.exists(final_video_path):
583
+ # os.remove(final_video_path)
584
+ # print("Deleted video file:", final_video_path)
585
+
586
+ # # TEMP_DIR.cleanup()
587
+ # preprocess_dir = os.path.join("/tmp", "preprocess_data")
588
+ # custom_cleanup(TEMP_DIR.name, preprocess_dir)
589
+
590
+ # print("Temporary files cleaned up, but preprocess_data is retained.")
 
 
 
 
 
 
 
591
 
592
+ # end_time = time.time()
593
+ # total_time = round(end_time - start_time, 2)
594
+ # print("Total time taken for execution:", total_time, " seconds")
595
+ # response["time_taken"] = total_time
596
+ # return jsonify(response)
597
+ # return jsonify({"error":"No process id provided"})
598
 
599
  @app.route("/health", methods=["GET"])
600
  def health_status():