Spaces:
Runtime error
Runtime error
added share func
Browse files- .gitignore +2 -0
- .streamlit/config.toml +0 -3
- .streamlit/secrets.toml +0 -1
- __pycache__/utils.cpython-310.pyc +0 -0
- app.py +29 -0
- requirements.txt +4 -1
- upload.py +35 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.streamlit
|
| 2 |
+
__pycache__
|
.streamlit/config.toml
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
[server]
|
| 2 |
-
enableXsrfProtection = false
|
| 3 |
-
enableCORS = false
|
|
|
|
|
|
|
|
|
|
|
|
.streamlit/secrets.toml
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
OPENAI_KEY="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"
|
|
|
|
|
|
__pycache__/utils.cpython-310.pyc
DELETED
|
Binary file (541 Bytes)
|
|
|
app.py
CHANGED
|
@@ -1,6 +1,9 @@
|
|
| 1 |
from openai import OpenAI
|
| 2 |
import streamlit as st
|
| 3 |
from utils import im_2_b64
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
RANDOM_SEED = 42
|
| 6 |
|
|
@@ -14,11 +17,37 @@ if "messages" not in st.session_state:
|
|
| 14 |
if "uploader_key" not in st.session_state:
|
| 15 |
st.session_state["uploader_key"] = 0
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def clear_uploader():
|
| 18 |
st.session_state["uploader_key"] += 1
|
| 19 |
st.rerun()
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
with st.sidebar:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
if st.button("Clear chat"):
|
| 23 |
st.session_state.messages = []
|
| 24 |
clear_uploader()
|
|
|
|
| 1 |
from openai import OpenAI
|
| 2 |
import streamlit as st
|
| 3 |
from utils import im_2_b64
|
| 4 |
+
import pickle
|
| 5 |
+
from upload import upload_file, get_file
|
| 6 |
+
import clipboard
|
| 7 |
|
| 8 |
RANDOM_SEED = 42
|
| 9 |
|
|
|
|
| 17 |
if "uploader_key" not in st.session_state:
|
| 18 |
st.session_state["uploader_key"] = 0
|
| 19 |
|
| 20 |
+
if "id" in st.query_params:
|
| 21 |
+
id = st.query_params["id"]
|
| 22 |
+
data = get_file(id, 'chatgpt-vision-007')
|
| 23 |
+
st.session_state.messages = pickle.loads(data)
|
| 24 |
+
|
| 25 |
def clear_uploader():
|
| 26 |
st.session_state["uploader_key"] += 1
|
| 27 |
st.rerun()
|
| 28 |
|
| 29 |
+
def undo():
|
| 30 |
+
if len(st.session_state.messages) > 0:
|
| 31 |
+
st.session_state.messages.pop()
|
| 32 |
+
st.session_state.messages.pop()
|
| 33 |
+
st.rerun()
|
| 34 |
+
|
| 35 |
+
def share():
|
| 36 |
+
data = pickle.dumps(st.session_state.messages)
|
| 37 |
+
id = upload_file(data, 'chatgpt-vision-007')
|
| 38 |
+
return id
|
| 39 |
+
|
| 40 |
with st.sidebar:
|
| 41 |
+
if st.button("Share"):
|
| 42 |
+
id = share()
|
| 43 |
+
url = f"https://umbc-nlp-chatgpt-vision.hf.space/?id={id}"
|
| 44 |
+
# st.code(f"https://umbc-nlp-chatgpt-vision.hf.space/?id={id}")
|
| 45 |
+
clipboard.copy(url)
|
| 46 |
+
st.write(f"URL copied to clipboard: {url}")
|
| 47 |
+
|
| 48 |
+
if st.button("Undo"):
|
| 49 |
+
undo()
|
| 50 |
+
|
| 51 |
if st.button("Clear chat"):
|
| 52 |
st.session_state.messages = []
|
| 53 |
clear_uploader()
|
requirements.txt
CHANGED
|
@@ -1,2 +1,5 @@
|
|
| 1 |
streamlit
|
| 2 |
-
openai
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
streamlit
|
| 2 |
+
openai
|
| 3 |
+
pydrive
|
| 4 |
+
boto3
|
| 5 |
+
clipboard
|
upload.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import uuid
|
| 3 |
+
import boto3
|
| 4 |
+
|
| 5 |
+
s3 = boto3.client(
|
| 6 |
+
's3',
|
| 7 |
+
aws_access_key_id=st.secrets["AWS_ACCESS_KEY"],
|
| 8 |
+
aws_secret_access_key=st.secrets["AWS_SECRET_KEY"]
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
def upload_file(data, bucket=st.secrets["s3_bucket"]):
|
| 12 |
+
file_name = uuid.uuid4().hex
|
| 13 |
+
try:
|
| 14 |
+
key = f"{file_name}.pkl"
|
| 15 |
+
response = s3.put_object(Body=data, Bucket=bucket, Key=key)
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return None
|
| 18 |
+
return file_name
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def get_file(file_name, bucket=st.secrets["s3_bucket"]):
|
| 22 |
+
try:
|
| 23 |
+
response = s3.get_object(Bucket=bucket, Key=f"{file_name}.pkl")
|
| 24 |
+
return response['Body'].read()
|
| 25 |
+
except Exception as e:
|
| 26 |
+
print(e)
|
| 27 |
+
return False
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
import pickle
|
| 31 |
+
a = [1, 2, 3]
|
| 32 |
+
id = upload_file(pickle.dumps(a), 'chatgpt-vision-007')
|
| 33 |
+
print(id)
|
| 34 |
+
data = get_file(id, 'chatgpt-vision-007')
|
| 35 |
+
print(pickle.loads(data))
|