smjain commited on
Commit
145f349
1 Parent(s): 39ae4ac

Upload 2 files

Browse files
Files changed (2) hide show
  1. myinfer_latest.py +25 -9
  2. ui.html +35 -0
myinfer_latest.py CHANGED
@@ -14,7 +14,7 @@ from scipy.io import wavfile
14
  from datetime import datetime
15
  from urllib.parse import urlparse
16
  from mega import Mega
17
- from flask import Flask, request, jsonify, send_file
18
  import base64
19
  import tempfile
20
  import os
@@ -113,10 +113,10 @@ def cleanup_files(file_paths):
113
  except Exception as e:
114
  print(f"Error deleting {path}: {e}")
115
 
116
-
117
  @app.route('/convert_voice', methods=['POST'])
118
  def api_convert_voice():
119
- spk_id = request.form['spk_id']
120
  voice_transform = request.form['voice_transform']
121
 
122
  # The file part
@@ -143,16 +143,32 @@ def api_convert_voice():
143
 
144
  output_path = convert_voice(spk_id, vocal_path, voice_transform)
145
  output_path1= combine_vocal_and_inst(output_path,inst)
 
 
 
 
146
  print(output_path1)
147
 
148
  created_files.extend([vocal_path, inst, 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
155
-
 
 
 
 
 
 
 
 
 
 
 
156
 
157
 
158
  def convert_voice(spk_id, input_audio_path, voice_transform):
 
14
  from datetime import datetime
15
  from urllib.parse import urlparse
16
  from mega import Mega
17
+ from flask import Flask, request, jsonify, send_file,session
18
  import base64
19
  import tempfile
20
  import os
 
113
  except Exception as e:
114
  print(f"Error deleting {path}: {e}")
115
 
116
+ processed_audio_storage = {}
117
  @app.route('/convert_voice', methods=['POST'])
118
  def api_convert_voice():
119
+ spk_id = request.form['spk_id']+'.pth'
120
  voice_transform = request.form['voice_transform']
121
 
122
  # The file part
 
143
 
144
  output_path = convert_voice(spk_id, vocal_path, voice_transform)
145
  output_path1= combine_vocal_and_inst(output_path,inst)
146
+
147
+ processed_audio_storage[unique_id] = output_path1
148
+ session['processed_audio_id'] = unique_id
149
+
150
  print(output_path1)
151
 
152
  created_files.extend([vocal_path, inst, output_path])
153
+ return jsonify({"message": "File processed successfully", "audio_id": unique_id}), 200
154
+
155
+ #if os.path.exists(output_path1):
156
 
157
+ # return send_file(output_path1, as_attachment=True)
158
+ #else:
159
+ # return jsonify({"error": "File not found."}), 404
160
+
161
+ @app.route('/')
162
+ def upload_form():
163
+ return render_template('ui.html')
164
+
165
+ @app.route('/get_processed_audio/<audio_id>')
166
+ def get_processed_audio(audio_id):
167
+ # Retrieve the path from temporary storage or session
168
+ if audio_id in processed_audio_storage:
169
+ file_path = processed_audio_storage[audio_id]
170
+ return send_file(file_path, as_attachment=True)
171
+ return jsonify({"error": "File not found."}), 404
172
 
173
 
174
  def convert_voice(spk_id, input_audio_path, voice_transform):
ui.html ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!-- Include jQuery for simplicity -->
2
+ <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
3
+
4
+ <script>
5
+ $(document).ready(function() {
6
+ $('#uploadForm').submit(function(e) {
7
+ e.preventDefault();
8
+ var formData = new FormData(this);
9
+
10
+ $.ajax({
11
+ url: '/convert_voice',
12
+ type: 'POST',
13
+ data: formData,
14
+ success: function(data) {
15
+ if (data.audio_id) {
16
+ // Update the source of the processed audio element
17
+ $('#processedAudio source').attr('src', '/get_processed_audio/' + data.audio_id);
18
+ $('#processedAudio')[0].load();
19
+ $('#processedAudio')[0].play();
20
+ }
21
+ },
22
+ cache: false,
23
+ contentType: false,
24
+ processData: false
25
+ });
26
+ });
27
+ });
28
+ </script>
29
+
30
+ <!-- Processed Audio Playback -->
31
+ <h3>Processed Audio:</h3>
32
+ <audio id="processedAudio" controls>
33
+ <source src="" type="audio/wav">
34
+ Your browser does not support the audio element.
35
+ </audio>