Update app.py
Browse files
app.py
CHANGED
|
@@ -17,6 +17,7 @@ from elevenlabs import set_api_key, generate, play, clone, Voice, VoiceSettings
|
|
| 17 |
# Initialize the Flask app
|
| 18 |
app = Flask(__name__)
|
| 19 |
TEMP_DIR = None
|
|
|
|
| 20 |
|
| 21 |
def run_inference(video_path, audio_path, video_out_path,
|
| 22 |
inference_ckpt_path, unet_config_path="configs/unet/second_stage.yaml",
|
|
@@ -110,6 +111,7 @@ def generate_audio(voice_cloning, text_prompt):
|
|
| 110 |
@app.route('/run', methods=['POST'])
|
| 111 |
def generate_video():
|
| 112 |
global TEMP_DIR
|
|
|
|
| 113 |
TEMP_DIR = create_temp_dir()
|
| 114 |
|
| 115 |
if 'video' not in request.files:
|
|
@@ -147,9 +149,25 @@ def generate_video():
|
|
| 147 |
seed=int(request.form.get('seed', 1247))
|
| 148 |
)
|
| 149 |
# Return the output video path or further process the file for download
|
| 150 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
except Exception as e:
|
| 152 |
return jsonify({'error': str(e)}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
@app.route("/health", methods=["GET"])
|
| 155 |
def health_status():
|
|
|
|
| 17 |
# Initialize the Flask app
|
| 18 |
app = Flask(__name__)
|
| 19 |
TEMP_DIR = None
|
| 20 |
+
VIDEO_DIRECTORY = None
|
| 21 |
|
| 22 |
def run_inference(video_path, audio_path, video_out_path,
|
| 23 |
inference_ckpt_path, unet_config_path="configs/unet/second_stage.yaml",
|
|
|
|
| 111 |
@app.route('/run', methods=['POST'])
|
| 112 |
def generate_video():
|
| 113 |
global TEMP_DIR
|
| 114 |
+
global VIDEO_DIRECTORY
|
| 115 |
TEMP_DIR = create_temp_dir()
|
| 116 |
|
| 117 |
if 'video' not in request.files:
|
|
|
|
| 149 |
seed=int(request.form.get('seed', 1247))
|
| 150 |
)
|
| 151 |
# Return the output video path or further process the file for download
|
| 152 |
+
if output_video and output_video.endswith('.mp4'):
|
| 153 |
+
filename = os.path.basename(output_video)
|
| 154 |
+
os.makedirs('videos', exist_ok=True)
|
| 155 |
+
VIDEO_DIRECTORY = os.path.abspath('videos')
|
| 156 |
+
print("VIDEO_DIRECTORY: ",VIDEO_DIRECTORY)
|
| 157 |
+
destination_path = os.path.join(VIDEO_DIRECTORY, filename)
|
| 158 |
+
shutil.copy(output_video, destination_path)
|
| 159 |
+
video_url = f"/videos/{filename}"
|
| 160 |
+
|
| 161 |
+
return jsonify({"message": "Video processed and saved successfully.",
|
| 162 |
+
"output_video": video_url,
|
| 163 |
+
"status": "success"}), 200
|
| 164 |
except Exception as e:
|
| 165 |
return jsonify({'error': str(e)}), 500
|
| 166 |
+
|
| 167 |
+
@app.route("/videos/<string:filename>", methods=['GET'])
|
| 168 |
+
def serve_video(filename):
|
| 169 |
+
global VIDEO_DIRECTORY
|
| 170 |
+
return send_from_directory(VIDEO_DIRECTORY, filename, as_attachment=False)
|
| 171 |
|
| 172 |
@app.route("/health", methods=["GET"])
|
| 173 |
def health_status():
|