|
import streamlit as st |
|
import uuid |
|
import boto3 |
|
|
|
s3 = boto3.client( |
|
's3', |
|
aws_access_key_id=st.secrets["AWS_ACCESS_KEY"], |
|
aws_secret_access_key=st.secrets["AWS_SECRET_KEY"] |
|
) |
|
|
|
def upload_file(data, bucket=st.secrets["S3_BUCKET"]): |
|
file_name = uuid.uuid4().hex |
|
try: |
|
key = f"{file_name}.pkl" |
|
response = s3.put_object(Body=data, Bucket=bucket, Key=key) |
|
except Exception as e: |
|
return None |
|
return file_name |
|
|
|
|
|
def get_file(file_name, bucket=st.secrets["S3_BUCKET"]): |
|
try: |
|
response = s3.get_object(Bucket=bucket, Key=f"{file_name}.pkl") |
|
return response['Body'].read() |
|
except Exception as e: |
|
print(e) |
|
return False |
|
|