Spaces:
Sleeping
Sleeping
File size: 1,696 Bytes
f3adb3d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
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)
|