smjain commited on
Commit
a0c67cd
1 Parent(s): e38a7f3

Upload myinfer_latest.py

Browse files
Files changed (1) hide show
  1. myinfer_latest.py +13 -2
myinfer_latest.py CHANGED
@@ -104,7 +104,14 @@ def clean():
104
  gr.Dropdown.update(value=""),
105
  gr.Slider.update(visible=False)
106
  )
107
-
 
 
 
 
 
 
 
108
 
109
 
110
  @app.route('/convert_voice', methods=['POST'])
@@ -118,7 +125,7 @@ def api_convert_voice():
118
  file = request.files['file']
119
  if file.filename == '':
120
  return jsonify({"error": "No selected file"}), 400
121
-
122
  # Save the file to a temporary path
123
  unique_id = uuid.uuid4()
124
 
@@ -126,6 +133,8 @@ def api_convert_voice():
126
  input_audio_path = os.path.join(tmp, f"{spk_id}_input_audio_{unique_id}.{filename.split('.')[-1]}")
127
  file.save(input_audio_path)
128
 
 
 
129
  #split audio
130
  cut_vocal_and_inst(input_audio_path,spk_id)
131
  print("audio splitting performed")
@@ -136,8 +145,10 @@ def api_convert_voice():
136
  output_path1= combine_vocal_and_inst(output_path,inst)
137
  print(output_path1)
138
 
 
139
 
140
  if os.path.exists(output_path1):
 
141
  return send_file(output_path1, as_attachment=True)
142
  else:
143
  return jsonify({"error": "File not found."}), 404
 
104
  gr.Dropdown.update(value=""),
105
  gr.Slider.update(visible=False)
106
  )
107
+ # Function to delete files
108
+ def cleanup_files(file_paths):
109
+ for path in file_paths:
110
+ try:
111
+ os.remove(path)
112
+ print(f"Deleted {path}")
113
+ except Exception as e:
114
+ print(f"Error deleting {path}: {e}")
115
 
116
 
117
  @app.route('/convert_voice', methods=['POST'])
 
125
  file = request.files['file']
126
  if file.filename == '':
127
  return jsonify({"error": "No selected file"}), 400
128
+ created_files = []
129
  # Save the file to a temporary path
130
  unique_id = uuid.uuid4()
131
 
 
133
  input_audio_path = os.path.join(tmp, f"{spk_id}_input_audio_{unique_id}.{filename.split('.')[-1]}")
134
  file.save(input_audio_path)
135
 
136
+ created_files.append(input_audio_path)
137
+
138
  #split audio
139
  cut_vocal_and_inst(input_audio_path,spk_id)
140
  print("audio splitting performed")
 
145
  output_path1= combine_vocal_and_inst(output_path,inst)
146
  print(output_path1)
147
 
148
+ created_files.extend([vocal_path, inst_path, output_path])
149
 
150
  if os.path.exists(output_path1):
151
+
152
  return send_file(output_path1, as_attachment=True)
153
  else:
154
  return jsonify({"error": "File not found."}), 404