File size: 866 Bytes
3d98680
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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))