Spaces:
Sleeping
Sleeping
Upload myinfer_latest.py
Browse files- myinfer_latest.py +42 -4
myinfer_latest.py
CHANGED
|
@@ -31,6 +31,8 @@ from pydub import AudioSegment
|
|
| 31 |
from flask_dance.contrib.google import make_google_blueprint, google
|
| 32 |
import io
|
| 33 |
|
|
|
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
|
|
@@ -58,6 +60,8 @@ app.config["GOOGLE_OAUTH_CLIENT_ID"] = "144930881143-n3e3ubers3vkq7jc9doe4iirasg
|
|
| 58 |
app.config["GOOGLE_OAUTH_CLIENT_SECRET"] = "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"
|
| 59 |
google_blueprint = make_google_blueprint(scope=["profile", "email"])
|
| 60 |
app.register_blueprint(google_blueprint, url_prefix="/login")
|
|
|
|
|
|
|
| 61 |
|
| 62 |
#set_start_method('spawn', force=True)
|
| 63 |
from lib.infer_pack.models import (
|
|
@@ -82,10 +86,11 @@ f0method_info = "PM is fast, Harvest is good but extremely slow, and Crepe effec
|
|
| 82 |
@app.route("/")
|
| 83 |
def index():
|
| 84 |
# Check if user is logged in
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
| 89 |
|
| 90 |
|
| 91 |
|
|
@@ -175,6 +180,39 @@ def create_song():
|
|
| 175 |
# Assuming we're interested in whether any model has been created
|
| 176 |
#model_exists = len(models) > 0
|
| 177 |
return render_template("ui.html", email=email)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
@app.route("/logout")
|
| 179 |
def logout():
|
| 180 |
# Clear the session
|
|
|
|
| 31 |
from flask_dance.contrib.google import make_google_blueprint, google
|
| 32 |
import io
|
| 33 |
|
| 34 |
+
import boto3
|
| 35 |
+
|
| 36 |
|
| 37 |
|
| 38 |
|
|
|
|
| 60 |
app.config["GOOGLE_OAUTH_CLIENT_SECRET"] = "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"
|
| 61 |
google_blueprint = make_google_blueprint(scope=["profile", "email"])
|
| 62 |
app.register_blueprint(google_blueprint, url_prefix="/login")
|
| 63 |
+
ACCESS_ID = os.getenv('ACCESS_ID', '')
|
| 64 |
+
SECRET_KEY = os.getenv('SECRET_KEY', '')
|
| 65 |
|
| 66 |
#set_start_method('spawn', force=True)
|
| 67 |
from lib.infer_pack.models import (
|
|
|
|
| 86 |
@app.route("/")
|
| 87 |
def index():
|
| 88 |
# Check if user is logged in
|
| 89 |
+
return render_template("ui.html")
|
| 90 |
+
#if google.authorized:
|
| 91 |
+
# return render_template("index.html", logged_in=True)
|
| 92 |
+
#else:
|
| 93 |
+
# return render_template("index.html", logged_in=False)
|
| 94 |
|
| 95 |
|
| 96 |
|
|
|
|
| 180 |
# Assuming we're interested in whether any model has been created
|
| 181 |
#model_exists = len(models) > 0
|
| 182 |
return render_template("ui.html", email=email)
|
| 183 |
+
|
| 184 |
+
@app.route('/download/<filename>', methods=['GET'])
|
| 185 |
+
def download_file(filename):
|
| 186 |
+
# Configure the client with your credentials
|
| 187 |
+
session = boto3.session.Session()
|
| 188 |
+
client = session.client('s3',
|
| 189 |
+
region_name='nyc3',
|
| 190 |
+
endpoint_url='https://nyc3.digitaloceanspaces.com',
|
| 191 |
+
aws_access_key_id=ACCESS_ID,
|
| 192 |
+
aws_secret_access_key=SECRET_KEY)
|
| 193 |
+
|
| 194 |
+
# Define the bucket and object key
|
| 195 |
+
bucket_name = 'sing' # Your bucket name
|
| 196 |
+
object_key = f'{filename}' # Construct the object key
|
| 197 |
+
|
| 198 |
+
# Define the local path to save the file
|
| 199 |
+
local_file_path = os.path.join('weights', filename)
|
| 200 |
+
|
| 201 |
+
# Download the file from the bucket
|
| 202 |
+
try:
|
| 203 |
+
client.download_file(bucket_name, object_key, local_file_path)
|
| 204 |
+
except client.exceptions.NoSuchKey:
|
| 205 |
+
return jsonify({'error': 'File not found in the bucket'}), 404
|
| 206 |
+
except Exception as e:
|
| 207 |
+
return jsonify({'error': str(e)}), 500
|
| 208 |
+
|
| 209 |
+
# Optional: Send the file directly to the client
|
| 210 |
+
# return send_file(local_file_path, as_attachment=True)
|
| 211 |
+
|
| 212 |
+
return jsonify({'success': True, 'message': 'File downloaded successfully', 'file_path': local_file_path})
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
|
| 216 |
@app.route("/logout")
|
| 217 |
def logout():
|
| 218 |
# Clear the session
|