Update app.py
Browse files
app.py
CHANGED
@@ -74,6 +74,9 @@ CORS(app)
|
|
74 |
|
75 |
TEMP_DIR = None
|
76 |
start_time = None
|
|
|
|
|
|
|
77 |
|
78 |
app.config['temp_response'] = None
|
79 |
app.config['generation_thread'] = None
|
@@ -288,7 +291,7 @@ def remove_brackets(text):
|
|
288 |
|
289 |
@app.route("/run", methods=['POST'])
|
290 |
def generate_video():
|
291 |
-
global start_time
|
292 |
start_time = time.time()
|
293 |
global TEMP_DIR
|
294 |
TEMP_DIR = create_temp_dir()
|
@@ -395,31 +398,48 @@ def generate_video():
|
|
395 |
final_video_path = app.config['final_video_path']
|
396 |
print('final_video_path',final_video_path)
|
397 |
|
398 |
-
if
|
399 |
-
os.
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
|
|
409 |
|
410 |
-
|
|
|
|
|
|
|
|
|
|
|
411 |
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
418 |
|
419 |
except Exception as e:
|
420 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
421 |
|
422 |
-
# return jsonify(response_data)
|
423 |
|
424 |
|
425 |
# @app.route("/status", methods=["GET"])
|
|
|
74 |
|
75 |
TEMP_DIR = None
|
76 |
start_time = None
|
77 |
+
VIDEO_DIRECTORY = None
|
78 |
+
args = None
|
79 |
+
unique_id = None
|
80 |
|
81 |
app.config['temp_response'] = None
|
82 |
app.config['generation_thread'] = None
|
|
|
291 |
|
292 |
@app.route("/run", methods=['POST'])
|
293 |
def generate_video():
|
294 |
+
global start_time, VIDEO_DIRECTORY
|
295 |
start_time = time.time()
|
296 |
global TEMP_DIR
|
297 |
TEMP_DIR = create_temp_dir()
|
|
|
398 |
final_video_path = app.config['final_video_path']
|
399 |
print('final_video_path',final_video_path)
|
400 |
|
401 |
+
if temp_file_path and temp_file_path.endswith('.mp4'):
|
402 |
+
filename = os.path.basename(temp_file_path)
|
403 |
+
os.makedirs('videos', exist_ok=True)
|
404 |
+
VIDEO_DIRECTORY = os.path.abspath('videos')
|
405 |
+
print("VIDEO_DIRECTORY: ",VIDEO_DIRECTORY)
|
406 |
+
destination_path = os.path.join(VIDEO_DIRECTORY, filename)
|
407 |
+
shutil.copy(temp_file_path, destination_path)
|
408 |
+
video_url = f"/videos/{filename}"
|
409 |
+
|
410 |
+
if final_video_path and os.path.exists(final_video_path):
|
411 |
+
os.remove(final_video_path)
|
412 |
+
print("Deleted video file:", final_video_path)
|
413 |
|
414 |
+
preprocess_dir = os.path.join("/tmp", "preprocess_data")
|
415 |
+
custom_cleanup(TEMP_DIR.name, preprocess_dir)
|
416 |
+
|
417 |
+
print("Temporary files cleaned up, but preprocess_data is retained.")
|
418 |
+
end_time = time.time()
|
419 |
+
time_taken = end_time - start_time
|
420 |
|
421 |
+
print(f"Time taken for endpoint: {time_taken:.2f} seconds")
|
422 |
+
|
423 |
+
return jsonify({
|
424 |
+
"message": "Video processed and saved successfully.",
|
425 |
+
"video_url": video_url,
|
426 |
+
"status": "success"
|
427 |
+
})
|
428 |
+
else:
|
429 |
+
return jsonify({
|
430 |
+
"message": "Failed to process the video.",
|
431 |
+
"status": "error"
|
432 |
+
}), 500
|
433 |
|
434 |
except Exception as e:
|
435 |
return jsonify({'status': 'error', 'message': str(e)}), 500
|
436 |
+
|
437 |
+
|
438 |
+
@app.route("/videos/<string:filename>", methods=['GET'])
|
439 |
+
def serve_video(filename):
|
440 |
+
global VIDEO_DIRECTORY
|
441 |
+
return send_from_directory(VIDEO_DIRECTORY, filename, as_attachment=False)
|
442 |
|
|
|
443 |
|
444 |
|
445 |
# @app.route("/status", methods=["GET"])
|