Spaces:
Sleeping
Sleeping
Upload myinfer_latest.py
Browse files30 unmodified lines31323334353621 unmodified lines58596061626318 unmodified lines8283848586878889909183 unmodified lines17517617717817918030 unmodified linesfrom flask_dance.contrib.google import make_google_blueprint, googleimport io21 unmodified linesapp.config["GOOGLE_OAUTH_CLIENT_SECRET"] = "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"google_blueprint = make_google_blueprint(scope=["profile", "email"])app.register_blueprint(google_blueprint, url_prefix="/login")#set_start_method('spawn', force=True)from lib.infer_pack.models import (18 unmodified lines@app.route("/")def index():# Check if user is logged inif google.authorized:return render_template("index.html", logged_in=True)else:return render_template("index.html", logged_in=False)83 unmodified lines# Assuming we're interested in whether any model has been created#model_exists = len(models) > 0return render_template("ui.html", email=email)@app.route("/logout")def logout():# Clear the session30 unmodified lines313233343536373821 unmodified lines606162636465666718 unmodified lines868788899091929394959683 unmodified lines18018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721830 unmodified linesfrom flask_dance.contrib.google import make_google_blueprint, googleimport ioimport boto321 unmodified linesapp.config["GOOGLE_OAUTH_CLIENT_SECRET"] = "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"google_blueprint = make_google_blueprint(scope=["profile", "email"])app.register_blueprint(google_blueprint, url_prefix="/login")ACCESS_ID = os.getenv('ACCESS_ID', '')SECRET_KEY = os.getenv('SECRET_KEY', '')#set_start_method('spawn', force=True)from lib.infer_pack.models import (18 unmodified lines@app.route("/")def index():# Check if user is logged inreturn render_template("ui.html")#if google.authorized:# return render_template("index.html", logged_in=True)#else:# return render_template("index.html", logged_in=False)83 unmodified lines# Assuming we're interested in whether any model has been created#model_exists = len(models) > 0return render_template("ui.html", email=email)@app.route('/download/<filename>', methods=['GET'])def download_file(filename):# Configure the client with your credentialssession = boto3.session.Session()client = session.client('s3',region_name='nyc3',endpoint_url='https://nyc3.digitaloceanspaces.com',aws_access_key_id=ACCESS_ID,aws_secret_access_key=SECRET_KEY)# Define the bucket and object keybucket_name = 'sing' # Your bucket nameobject_key = f'{filename}' # Construct the object key# Define the local path to save the filelocal_file_path = os.path.join('weights', filename)# Download the file from the buckettry:client.download_file(bucket_name, object_key, local_file_path)except client.exceptions.NoSuchKey:return jsonify({'error': 'File not found in the bucket'}), 404except Exception as e:return jsonify({'error': str(e)}), 500# Optional: Send the file directly to the client# return send_file(local_file_path, as_attachment=True)return jsonify({'success': True, 'message': 'File downloaded successfully', 'file_path': local_file_path})@app.route("/logout")def logout():# Clear the session
myinfer_latest.py+42-4