chatgpt-vision / upload.py
dipta007's picture
env var name change
25d2247
raw
history blame
866 Bytes
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
import pickle
a = [1, 2, 3]
id = upload_file(pickle.dumps(a), 'chatgpt-vision-007')
print(id)
data = get_file(id, 'chatgpt-vision-007')
print(pickle.loads(data))