Spaces:
Sleeping
Sleeping
Upload myinfer_latest.py
Browse files24 unmodified lines2526272829303152 unmodified lines84858687888978 unmodified lines1681691701711721731742 unmodified lines1771781791801811821831 unmodified line1851861871881891901911 unmodified line19319419519619719819925 unmodified lines22522622722822923023124 unmodified linesimport uuidfrom threading import Semaphorefrom threading import Lock52 unmodified linesf0method_mode.insert(2, "rmvpe")f0method_info = "PM is fast, Harvest is good but extremely slow, Rvmpe is alternative to harvest (might be better), and Crepe effect is good but requires GPU (Default: PM)"def load_hubert():global hubert_modelmodels, _, _ = checkpoint_utils.load_model_ensemble_and_task(78 unmodified linesfile = request.files['file']if file.filename == '':return jsonify({"error": "No selected file"}), 400created_files = []# Save the file to a temporary pathunique_id = str(uuid.uuid4())print(unique_id)2 unmodified linesinput_audio_path = os.path.join(tmp, f"{spk_id}_input_audio_{unique_id}.{filename.split('.')[-1]}")file.save(input_audio_path)created_files.append(input_audio_path)#split audiocut_vocal_and_inst(input_audio_path,spk_id,unique_id)1 unmodified linevocal_path = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/vocals.wav"inst = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/no_vocals.wav"print("*****before making call to convert ", unique_id)output_path = convert_voice(spk_id, vocal_path, voice_transform,unique_id)output_path1= combine_vocal_and_inst(output_path,inst,unique_id)processed_audio_storage[unique_id] = output_path11 unmodified lineprint(output_path1)created_files.extend([vocal_path, inst, output_path])return jsonify({"message": "File processed successfully", "audio_id": unique_id}), 200finally:request_semaphore.release()25 unmodified linesreturn send_file(file_path, as_attachment=True)return jsonify({"error": "File not found."}), 404def convert_voice(spk_id, input_audio_path, voice_transform,unique_id):get_vc(spk_id,0.5)print("*****before makinf call to vc ", unique_id)24 unmodified lines2526272829303152 unmodified lines848586878889909178 unmodified lines1701711721731741751762 unmodified lines1791801811821831841851 unmodified line1871881891901911921931941951961971981992002012021 unmodified line20420520620720820921025 unmodified lines23623723823924024124224324424524624724824925024 unmodified linesimport uuidfrom threading import Semaphorefrom threading import Lockfrom multiprocessing import Process, Queue52 unmodified linesf0method_mode.insert(2, "rmvpe")f0method_info = "PM is fast, Harvest is good but extremely slow, Rvmpe is alternative to harvest (might be better), and Crepe effect is good but requires GPU (Default: PM)"def load_hubert():global hubert_modelmodels, _, _ = checkpoint_utils.load_model_ensemble_and_task(78 unmodified linesfile = request.files['file']if file.filename == '':return jsonify({"error": "No selected file"}), 400#created_files = []# Save the file to a temporary pathunique_id = str(uuid.uuid4())print(unique_id)2 unmodified linesinput_audio_path = os.path.join(tmp, f"{spk_id}_input_audio_{unique_id}.{filename.split('.')[-1]}")file.save(input_audio_path)#created_files.append(input_audio_path)#split audiocut_vocal_and_inst(input_audio_path,spk_id,unique_id)1 unmodified linevocal_path = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/vocals.wav"inst = f"output/{spk_id}_{unique_id}/{split_model}/{spk_id}_input_audio_{unique_id}/no_vocals.wav"print("*****before making call to convert ", unique_id)output_queue = Queue()# Create and start the processp = Process(target=worker, args=(spk_id, input_audio_path, voice_transform, unique_id, output_queue))p.start()# Wait for the process to finish and get the resultp.join()output_path = output_queue.get()#output_path = convert_voice(spk_id, vocal_path, voice_transform,unique_id)output_path1= combine_vocal_and_inst(output_path,inst,unique_id)processed_audio_storage[unique_id] = output_path11 unmodified lineprint(output_path1)#created_files.extend([vocal_path, inst, output_path])return jsonify({"message": "File processed successfully", "audio_id": unique_id}), 200finally:request_semaphore.release()25 unmodified linesreturn 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):"""Worker function to be executed in a separate process."""# Call the convert_voice functionoutput_audio_path = convert_voice(spk_id, input_audio_path, voice_transform, unique_id)# Put the result in the queue to be retrieved by the main processoutput_queue.put(output_audio_path)def convert_voice(spk_id, input_audio_path, voice_transform,unique_id):get_vc(spk_id,0.5)print("*****before makinf call to vc ", unique_id)
myinfer_latest.py+25-6