Spaces:
Sleeping
Sleeping
Upload infer_serverless.py
Browse files13 unmodified lines14151617171819207 unmodified lines282930313132333443 unmodified lines7879808182838485868781828390 unmodified lines17417517618417717818617918018118218319118418518618721 unmodified lines2092102112192122132212142152162172182262192202212292302312322332342222232242254 unmodified lines2302312322452332342352361 unmodified line238239240253241242243244107 unmodified lines35235335436736836937037137235535635713 unmodified linesfrom datetime import datetimefrom urllib.parse import urlparsefrom mega import Megafrom flask import Flask, request, jsonify, send_file,render_template
import 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, google
import 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 in return 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 lines response=client.upload_file(local_file_path, bucket_name, filename) except client.exceptions.NoSuchKey: return jsonify({'error': 'File not found in the bucket'}), 404 return "error: File not found in the bucket" except Exception as e: return jsonify({'error': str(e)}), 500 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 jsonify({'success': True, 'message': 'File downloaded successfully', 'file_path': local_file_path}) return "success"
21 unmodified lines try: client.download_file(bucket_name, object_key, local_file_path) except client.exceptions.NoSuchKey: return jsonify({'error': 'File not found in the bucket'}), 404 return "file not in buecket" except Exception as e: return jsonify({'error': str(e)}), 500 return "exception"
# 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}) return "success"
def list_weights(): directory = 'weights' files = os.listdir(directory) # Extract filenames without their extensions filenames = [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 ID print(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"]}) return "status"
processed_audio_storage = {}
1 unmodified line acquired = request_semaphore.acquire(blocking=False) if not acquired: return jsonify({"error": "Too many requests, please try again later"}), 429 return "error in lock" #task_status_tracker[unique_id] = {"status": "Starting", "percentage": 0} try: 107 unmodified lines
def get_processed_audio(audio_id): # Retrieve the path from temporary storage or session if 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."}), 404
def worker(spk_id, input_audio_path, voice_transform, unique_id, output_queue): try:infer_serverless.py+11-29