Spaces:
Sleeping
Sleeping
Upload myinfer_latest.py
Browse files30 unmodified lines313233343536373821 unmodified lines606162636465666718 unmodified lines86878889858687889091929394959683 unmodified lines18018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721830 unmodified linesfrom flask_dance.contrib.google import make_google_blueprint, googleimport io
import boto3
21 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 in return render_template("ui.html") if google.authorized: return render_template("index.html", logged_in=True) else: return render_template("index.html", logged_in=False) #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) > 0 return render_template("ui.html", email=email) @app.route('/download/<filename>', methods=['GET'])def download_file(filename): # Configure the client with your credentials session = 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 key bucket_name = 'sing' # Your bucket name object_key = f'{filename}' # Construct the object key
# Define the local path to save the file local_file_path = os.path.join('weights', filename)
# Download the file from the bucket try: client.download_file(bucket_name, object_key, local_file_path) except client.exceptions.NoSuchKey: return jsonify({'error': 'File not found in the bucket'}), 404 except 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 sessionmyinfer_latest.py+42-4