Update app.py
Browse files
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 |
-
|
| 528 |
|
| 529 |
-
|
|
|
|
|
|
|
|
|
|
| 530 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 559 |
-
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 565 |
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 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():
|