Spaces:
Sleeping
Sleeping
Upload myinfer_latest.py
Browse files- myinfer_latest.py +16 -1
myinfer_latest.py
CHANGED
|
@@ -49,6 +49,8 @@ MAX_CONCURRENT_REQUESTS = 2 # Adjust this number as needed
|
|
| 49 |
# Initialize the semaphore with the maximum number of concurrent requests
|
| 50 |
request_semaphore = Semaphore(MAX_CONCURRENT_REQUESTS)
|
| 51 |
|
|
|
|
|
|
|
| 52 |
#set_start_method('spawn', force=True)
|
| 53 |
from lib.infer_pack.models import (
|
| 54 |
SynthesizerTrnMs256NSFsid,
|
|
@@ -147,12 +149,20 @@ def cleanup_files(file_paths):
|
|
| 147 |
except Exception as e:
|
| 148 |
print(f"Error deleting {path}: {e}")
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
processed_audio_storage = {}
|
| 151 |
@app.route('/convert_voice', methods=['POST'])
|
| 152 |
def api_convert_voice():
|
| 153 |
acquired = request_semaphore.acquire(blocking=False)
|
|
|
|
| 154 |
if not acquired:
|
| 155 |
return jsonify({"error": "Too many requests, please try again later"}), 429
|
|
|
|
| 156 |
try:
|
| 157 |
|
| 158 |
#if session.get('submitted'):
|
|
@@ -212,11 +222,14 @@ def api_convert_voice():
|
|
| 212 |
#created_files.append(input_audio_path)
|
| 213 |
|
| 214 |
#split audio
|
|
|
|
|
|
|
| 215 |
cut_vocal_and_inst(input_audio_path,spk_id,unique_id)
|
| 216 |
print("audio splitting performed")
|
| 217 |
vocal_path = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/vocals.wav"
|
| 218 |
inst = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/no_vocals.wav"
|
| 219 |
print("*****before making call to convert ", unique_id)
|
|
|
|
| 220 |
#output_queue = SimpleQueue()
|
| 221 |
ctx = get_context('spawn')
|
| 222 |
output_queue = ctx.Queue()
|
|
@@ -229,6 +242,7 @@ def api_convert_voice():
|
|
| 229 |
print("*******waiting for process to complete ")
|
| 230 |
|
| 231 |
output_path = output_queue.get()
|
|
|
|
| 232 |
#if isinstance(output_path, Exception):
|
| 233 |
# print("Exception in worker:", output_path)
|
| 234 |
#else:
|
|
@@ -238,10 +252,11 @@ def api_convert_voice():
|
|
| 238 |
|
| 239 |
processed_audio_storage[unique_id] = output_path1
|
| 240 |
session['processed_audio_id'] = unique_id
|
| 241 |
-
|
| 242 |
print(output_path1)
|
| 243 |
|
| 244 |
#created_files.extend([vocal_path, inst, output_path])
|
|
|
|
| 245 |
return jsonify({"message": "File processed successfully", "audio_id": unique_id}), 200
|
| 246 |
finally:
|
| 247 |
request_semaphore.release()
|
|
|
|
| 49 |
# Initialize the semaphore with the maximum number of concurrent requests
|
| 50 |
request_semaphore = Semaphore(MAX_CONCURRENT_REQUESTS)
|
| 51 |
|
| 52 |
+
task_status_tracker = {}
|
| 53 |
+
|
| 54 |
#set_start_method('spawn', force=True)
|
| 55 |
from lib.infer_pack.models import (
|
| 56 |
SynthesizerTrnMs256NSFsid,
|
|
|
|
| 149 |
except Exception as e:
|
| 150 |
print(f"Error deleting {path}: {e}")
|
| 151 |
|
| 152 |
+
@app.route('/status/<audio_id>', methods=['GET'])
|
| 153 |
+
def get_status(audio_id):
|
| 154 |
+
# Retrieve the task status using the unique ID
|
| 155 |
+
status_info = task_status_tracker.get(audio_id, {"status": "Unknown ID", "percentage": 0})
|
| 156 |
+
return jsonify({"audio_id": audio_id, "status": status_info["status"], "percentage": status_info["percentage"]})
|
| 157 |
+
|
| 158 |
processed_audio_storage = {}
|
| 159 |
@app.route('/convert_voice', methods=['POST'])
|
| 160 |
def api_convert_voice():
|
| 161 |
acquired = request_semaphore.acquire(blocking=False)
|
| 162 |
+
|
| 163 |
if not acquired:
|
| 164 |
return jsonify({"error": "Too many requests, please try again later"}), 429
|
| 165 |
+
task_status_tracker[unique_id] = {"status": "Starting", "percentage": 0}
|
| 166 |
try:
|
| 167 |
|
| 168 |
#if session.get('submitted'):
|
|
|
|
| 222 |
#created_files.append(input_audio_path)
|
| 223 |
|
| 224 |
#split audio
|
| 225 |
+
task_status_tracker[unique_id] = {"status": "Processing: Step 1", "percentage": 30}
|
| 226 |
+
|
| 227 |
cut_vocal_and_inst(input_audio_path,spk_id,unique_id)
|
| 228 |
print("audio splitting performed")
|
| 229 |
vocal_path = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/vocals.wav"
|
| 230 |
inst = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/no_vocals.wav"
|
| 231 |
print("*****before making call to convert ", unique_id)
|
| 232 |
+
task_status_tracker[unique_id] = "Processing: Step 2"
|
| 233 |
#output_queue = SimpleQueue()
|
| 234 |
ctx = get_context('spawn')
|
| 235 |
output_queue = ctx.Queue()
|
|
|
|
| 242 |
print("*******waiting for process to complete ")
|
| 243 |
|
| 244 |
output_path = output_queue.get()
|
| 245 |
+
task_status_tracker[unique_id] = {"status": "Processing: Step 2", "percentage": 80}
|
| 246 |
#if isinstance(output_path, Exception):
|
| 247 |
# print("Exception in worker:", output_path)
|
| 248 |
#else:
|
|
|
|
| 252 |
|
| 253 |
processed_audio_storage[unique_id] = output_path1
|
| 254 |
session['processed_audio_id'] = unique_id
|
| 255 |
+
task_status_tracker[unique_id] = {"status": "Finalizing", "percentage": 100}
|
| 256 |
print(output_path1)
|
| 257 |
|
| 258 |
#created_files.extend([vocal_path, inst, output_path])
|
| 259 |
+
task_status_tracker[unique_id]["status"] = "Completed"
|
| 260 |
return jsonify({"message": "File processed successfully", "audio_id": unique_id}), 200
|
| 261 |
finally:
|
| 262 |
request_semaphore.release()
|