meraj12 commited on
Commit
8cfb35c
·
verified ·
1 Parent(s): 8d6ad31

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -31
app.py CHANGED
@@ -1,31 +1,39 @@
1
- import streamlit as st
2
- import requests
3
- from io import BytesIO
4
-
5
- # Title of the app
6
- st.title('Voice Cloning App')
7
-
8
- # File uploader widget for uploading the voice recording
9
- uploaded_file = st.file_uploader("Upload an audio file (MP3, WAV)", type=['mp3', 'wav'])
10
-
11
- # Function to send audio file to the backend (Google Colab)
12
- def send_to_backend(audio_file):
13
- # Make sure your Google Colab or API is set up to accept POST requests with audio data
14
- url = 'https://<your-backend-url>' # replace with your backend API URL
15
- files = {'file': audio_file}
16
- response = requests.post(url, files=files)
17
- return response
18
-
19
- # Display the uploaded file and send it for processing
20
- if uploaded_file is not None:
21
- st.audio(uploaded_file, format='audio/wav')
22
-
23
- # Process the file and return the cloned voice (assuming backend returns a file URL or the file itself)
24
- with st.spinner("Processing..."):
25
- result = send_to_backend(uploaded_file)
26
- if result.status_code == 200:
27
- # If the result is successful, display the cloned audio
28
- st.success('Voice cloned successfully!')
29
- st.audio(result.content, format='audio/wav')
30
- else:
31
- st.error("Error in processing the voice cloning. Please try again.")
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, render_template, jsonify
2
+ import os
3
+
4
+ app = Flask(__name__)
5
+
6
+ # Set up the folder where audio files will be saved
7
+ UPLOAD_FOLDER = 'uploads/'
8
+ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
9
+ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
10
+
11
+ # Allowed file extensions
12
+ ALLOWED_EXTENSIONS = {'wav', 'mp3', 'ogg'}
13
+
14
+ # Check if the file is allowed
15
+ def allowed_file(filename):
16
+ return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
17
+
18
+ @app.route('/')
19
+ def index():
20
+ return render_template('index.html')
21
+
22
+ @app.route('/upload', methods=['POST'])
23
+ def upload_audio():
24
+ if 'file' not in request.files:
25
+ return jsonify({"message": "No file part"}), 400
26
+
27
+ file = request.files['file']
28
+ if file.filename == '':
29
+ return jsonify({"message": "No selected file"}), 400
30
+
31
+ if file and allowed_file(file.filename):
32
+ filename = os.path.join(app.config['UPLOAD_FOLDER'], file.filename)
33
+ file.save(filename)
34
+ return jsonify({"message": "File uploaded successfully", "filename": file.filename}), 200
35
+ else:
36
+ return jsonify({"message": "Invalid file type. Only WAV, MP3, and OGG are allowed."}), 400
37
+
38
+ if __name__ == "__main__":
39
+ app.run(debug=True)