smjain commited on
Commit
b480b95
1 Parent(s): 6691270

Upload myinfer_latest.py

Browse files
Files changed (1) hide show
  1. myinfer_latest.py +10 -2
myinfer_latest.py CHANGED
@@ -22,6 +22,9 @@ import werkzeug
22
  from pydub import AudioSegment
23
  import uuid
24
  from threading import Semaphore
 
 
 
25
 
26
 
27
 
@@ -34,7 +37,7 @@ shutil.rmtree(tmp, ignore_errors=True)
34
  os.makedirs(tmp, exist_ok=True)
35
  os.environ["TEMP"] = tmp
36
  split_model="htdemucs"
37
-
38
  # Define the maximum number of concurrent requests
39
  MAX_CONCURRENT_REQUESTS = 2 # Adjust this number as needed
40
 
@@ -166,7 +169,7 @@ def api_convert_voice():
166
  vocal_path = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/vocals.wav"
167
  inst = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/no_vocals.wav"
168
  print("*****before making call to convert ", unique_id)
169
- output_path = convert_voice(spk_id, vocal_path, voice_transform,unique_id)
170
  output_path1= combine_vocal_and_inst(output_path,inst,unique_id)
171
 
172
  processed_audio_storage[unique_id] = output_path1
@@ -184,6 +187,11 @@ def api_convert_voice():
184
  #else:
185
  # return jsonify({"error": "File not found."}), 404
186
 
 
 
 
 
 
187
  @app.route('/')
188
  def upload_form():
189
  return render_template('ui.html')
 
22
  from pydub import AudioSegment
23
  import uuid
24
  from threading import Semaphore
25
+ from threading import Lock
26
+
27
+
28
 
29
 
30
 
 
37
  os.makedirs(tmp, exist_ok=True)
38
  os.environ["TEMP"] = tmp
39
  split_model="htdemucs"
40
+ convert_voice_lock = Lock()
41
  # Define the maximum number of concurrent requests
42
  MAX_CONCURRENT_REQUESTS = 2 # Adjust this number as needed
43
 
 
169
  vocal_path = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/vocals.wav"
170
  inst = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/no_vocals.wav"
171
  print("*****before making call to convert ", unique_id)
172
+ output_path = convert_voice_thread_safe(spk_id, vocal_path, voice_transform,unique_id)
173
  output_path1= combine_vocal_and_inst(output_path,inst,unique_id)
174
 
175
  processed_audio_storage[unique_id] = output_path1
 
187
  #else:
188
  # return jsonify({"error": "File not found."}), 404
189
 
190
+ def convert_voice_thread_safe(spk_id, vocal_path, voice_transform, unique_id):
191
+ with convert_voice_lock:
192
+ return convert_voice(spk_id, vocal_path, voice_transform, unique_id)
193
+
194
+
195
  @app.route('/')
196
  def upload_form():
197
  return render_template('ui.html')