Spaces:
Sleeping
Sleeping
Upload infer_serverless.py
Browse files13 unmodified lines141516171819207 unmodified lines2829303132333443 unmodified lines7879808182838485868788899090 unmodified lines18118218318418518618718818919019119219319421 unmodified lines2162172182192202212222232242252262272282292302312322332342352362374 unmodified lines2422432442452462472481 unmodified line250251252253254255256107 unmodified lines36436536636736836937037137237337437513 unmodified linesfrom datetime import datetimefrom urllib.parse import urlparsefrom mega import Megafrom flask import Flask, request, jsonify, send_file,render_templateimport base64import tempfileimport threading7 unmodified linesfrom multiprocessing import Process, SimpleQueue, set_start_method,get_contextfrom queue import Emptyfrom pydub import AudioSegmentfrom flask_dance.contrib.google import make_google_blueprint, googleimport ioimport runpodimport boto343 unmodified linesf0method_info = "PM is fast, Harvest is good but extremely slow, and Crepe effect is good but requires GPU (Default: PM)"def index():# Check if user is logged inreturn render_template("ui.html")#if google.authorized:# return render_template("index.html", logged_in=True)#else:# return render_template("index.html", logged_in=False)90 unmodified linesresponse=client.upload_file(local_file_path, bucket_name, filename)except client.exceptions.NoSuchKey:return jsonify({'error': 'File not found in the bucket'}), 404except Exception as e:return jsonify({'error': str(e)}), 500# Optional: Send the file directly to the client# return send_file(local_file_path, as_attachment=True)return jsonify({'success': True, 'message': 'File downloaded successfully', 'file_path': local_file_path})21 unmodified linestry:client.download_file(bucket_name, object_key, local_file_path)except client.exceptions.NoSuchKey:return jsonify({'error': 'File not found in the bucket'}), 404except Exception as e:return jsonify({'error': str(e)}), 500# Optional: Send the file directly to the client# return send_file(local_file_path, as_attachment=True)return jsonify({'success': True, 'message': 'File downloaded successfully', 'file_path': local_file_path})def list_weights():directory = 'weights'files = os.listdir(directory)# Extract filenames without their extensionsfilenames = [os.path.splitext(file)[0] for file in files if os.path.isfile(os.path.join(directory, file))]return jsonify(filenames)4 unmodified lines# Retrieve the task status using the unique IDprint(audio_id)status_info = task_status_tracker.get(audio_id, {"status": "Unknown ID", "percentage": 0})return jsonify({"audio_id": audio_id, "status": status_info["status"], "percentage": status_info["percentage"]})processed_audio_storage = {}1 unmodified lineacquired = request_semaphore.acquire(blocking=False)if not acquired:return jsonify({"error": "Too many requests, please try again later"}), 429#task_status_tracker[unique_id] = {"status": "Starting", "percentage": 0}try:107 unmodified linesdef get_processed_audio(audio_id):# Retrieve the path from temporary storage or sessionif audio_id in processed_audio_storage:file_path = processed_audio_storage[audio_id]return send_file(file_path, as_attachment=True)return jsonify({"error": "File not found."}), 404def worker(spk_id, input_audio_path, voice_transform, unique_id, output_queue):try:13 unmodified lines141516171819207 unmodified lines2829303132333443 unmodified lines78798081828390 unmodified lines17417517617717817918018118218318418518618721 unmodified lines2092102112122132142152162172182192202212222232242254 unmodified lines2302312322332342352361 unmodified line238239240241242243244107 unmodified lines35235335435535635713 unmodified linesfrom datetime import datetimefrom urllib.parse import urlparsefrom mega import Megaimport base64import tempfileimport threading7 unmodified linesfrom multiprocessing import Process, SimpleQueue, set_start_method,get_contextfrom queue import Emptyfrom pydub import AudioSegmentimport ioimport runpodimport boto343 unmodified linesf0method_info = "PM is fast, Harvest is good but extremely slow, and Crepe effect is good but requires GPU (Default: PM)"90 unmodified linesresponse=client.upload_file(local_file_path, bucket_name, filename)except client.exceptions.NoSuchKey:return "error: File not found in the bucket"except Exception as e:return "error: File not found in the bucket"# Optional: Send the file directly to the client# return send_file(local_file_path, as_attachment=True)return "success"21 unmodified linestry:client.download_file(bucket_name, object_key, local_file_path)except client.exceptions.NoSuchKey:return "file not in buecket"except Exception as e:return "exception"# Optional: Send the file directly to the client# return send_file(local_file_path, as_attachment=True)return "success"4 unmodified lines# Retrieve the task status using the unique IDprint(audio_id)status_info = task_status_tracker.get(audio_id, {"status": "Unknown ID", "percentage": 0})return "status"processed_audio_storage = {}1 unmodified lineacquired = request_semaphore.acquire(blocking=False)if not acquired:return "error in lock"#task_status_tracker[unique_id] = {"status": "Starting", "percentage": 0}try:107 unmodified linesdef worker(spk_id, input_audio_path, voice_transform, unique_id, output_queue):try:
infer_serverless.py+11-29