from flask import Flask, request, jsonify from flask_cors import CORS import os from werkzeug.utils import secure_filename from app_rvc import SoniTranslate app = Flask(__name__) CORS(app) UPLOAD_FOLDER = "uploads" if not os.path.exists(UPLOAD_FOLDER): os.makedirs(UPLOAD_FOLDER) # Autentifikační klíč (API klíč) API_KEY = "MY_SECRET_API_KEY" @app.route("/process_video", methods=["POST"]) def process_video(): # Ověření API klíče api_key = request.headers.get("Authorization") if api_key != f"Bearer {API_KEY}": return jsonify({"status": "error", "message": "Invalid API key"}), 403 # Ověření vstupních dat if "video" not in request.files or "target_language" not in request.form: return jsonify({"status": "error", "message": "Missing parameters"}), 400 video_file = request.files["video"] target_language = request.form["target_language"] # Uložení videa filename = secure_filename(video_file.filename) file_path = os.path.join(UPLOAD_FOLDER, filename) video_file.save(file_path) try: # Inicializace SoniTranslate a spuštění zpracování translator = SoniTranslate(cpu_mode=False) result = translator.multilingual_media_conversion( media_file=file_path, target_language=target_language, is_gui=False, ) return jsonify({"status": "success", "result": result}), 200 except Exception as e: return jsonify({"status": "error", "message": str(e)}), 500 finally: # Smazání dočasného souboru os.remove(file_path) if __name__ == "__main__": app.run(host="0.0.0.0", port=5000, debug=True)