Spaces:
Runtime error
Runtime error
fixed copy
Browse files- app.py +21 -22
- requirements.txt +1 -2
- upload.py +0 -8
app.py
CHANGED
|
@@ -3,9 +3,6 @@ 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 |
|
| 10 |
|
| 11 |
st.title("ChatGPT with Vision")
|
|
@@ -18,9 +15,11 @@ if "uploader_key" not in st.session_state:
|
|
| 18 |
st.session_state["uploader_key"] = 0
|
| 19 |
|
| 20 |
if "id" in st.query_params:
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
| 24 |
|
| 25 |
def clear_uploader():
|
| 26 |
st.session_state["uploader_key"] += 1
|
|
@@ -35,28 +34,29 @@ def undo():
|
|
| 35 |
def share():
|
| 36 |
data = pickle.dumps(st.session_state.messages)
|
| 37 |
id = upload_file(data, 'chatgpt-vision-007')
|
| 38 |
-
|
|
|
|
| 39 |
|
| 40 |
with st.sidebar:
|
| 41 |
if st.button("Share"):
|
| 42 |
-
|
| 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 |
-
|
| 52 |
-
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
with st.expander("Advanced Configuration"):
|
| 56 |
st.subheader("Temperature")
|
| 57 |
-
temperature = st.slider(label="x", min_value=0.1, max_value=1.0, value=0.
|
| 58 |
st.subheader("Max Tokens")
|
| 59 |
-
max_tokens = st.slider(label="x", min_value=32, max_value=1024, value=256, step=32, label_visibility='
|
|
|
|
|
|
|
| 60 |
|
| 61 |
with st.expander("Image Input", expanded=True):
|
| 62 |
images = st.file_uploader(
|
|
@@ -122,13 +122,12 @@ if prompt := st.chat_input("Type a message", key="chat_input", disabled=chat_inp
|
|
| 122 |
{"role": m["role"], "content": m["content"]}
|
| 123 |
for m in st.session_state.messages
|
| 124 |
]
|
| 125 |
-
# print("api call", messages)
|
| 126 |
chat_input_disabled = True
|
| 127 |
stream = client.chat.completions.create(
|
| 128 |
model="gpt-4-vision-preview",
|
| 129 |
messages=messages,
|
| 130 |
stream=True,
|
| 131 |
-
seed=
|
| 132 |
temperature=temperature,
|
| 133 |
max_tokens=max_tokens,
|
| 134 |
)
|
|
|
|
| 3 |
from utils import im_2_b64
|
| 4 |
import pickle
|
| 5 |
from upload import upload_file, get_file
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
st.title("ChatGPT with Vision")
|
|
|
|
| 15 |
st.session_state["uploader_key"] = 0
|
| 16 |
|
| 17 |
if "id" in st.query_params:
|
| 18 |
+
with st.spinner("Loading chat..."):
|
| 19 |
+
id = st.query_params["id"]
|
| 20 |
+
data = get_file(id, 'chatgpt-vision-007')
|
| 21 |
+
st.session_state.messages = pickle.loads(data)
|
| 22 |
+
st.query_params.clear()
|
| 23 |
|
| 24 |
def clear_uploader():
|
| 25 |
st.session_state["uploader_key"] += 1
|
|
|
|
| 34 |
def share():
|
| 35 |
data = pickle.dumps(st.session_state.messages)
|
| 36 |
id = upload_file(data, 'chatgpt-vision-007')
|
| 37 |
+
url = f"https://umbc-nlp-chatgpt-vision.hf.space/?id={id}"
|
| 38 |
+
st.success(f"Share URL: {url}")
|
| 39 |
|
| 40 |
with st.sidebar:
|
| 41 |
if st.button("Share"):
|
| 42 |
+
share()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
cols = st.columns(2)
|
| 45 |
+
with cols[0]:
|
| 46 |
+
if st.button("Undo"):
|
| 47 |
+
undo()
|
| 48 |
+
with cols[1]:
|
| 49 |
+
if st.button("Clear chat"):
|
| 50 |
+
st.session_state.messages = []
|
| 51 |
+
clear_uploader()
|
| 52 |
|
| 53 |
with st.expander("Advanced Configuration"):
|
| 54 |
st.subheader("Temperature")
|
| 55 |
+
temperature = st.slider(label="x", min_value=0.1, max_value=1.0, value=0.2, step=0.1, label_visibility='collapsed')
|
| 56 |
st.subheader("Max Tokens")
|
| 57 |
+
max_tokens = st.slider(label="x", min_value=32, max_value=1024, value=256, step=32, label_visibility='collapsed')
|
| 58 |
+
st.subheader("Random Seed")
|
| 59 |
+
random_seed = st.number_input("Seed", min_value=0, max_value=1000000, value=42, step=1, label_visibility='collapsed')
|
| 60 |
|
| 61 |
with st.expander("Image Input", expanded=True):
|
| 62 |
images = st.file_uploader(
|
|
|
|
| 122 |
{"role": m["role"], "content": m["content"]}
|
| 123 |
for m in st.session_state.messages
|
| 124 |
]
|
|
|
|
| 125 |
chat_input_disabled = True
|
| 126 |
stream = client.chat.completions.create(
|
| 127 |
model="gpt-4-vision-preview",
|
| 128 |
messages=messages,
|
| 129 |
stream=True,
|
| 130 |
+
seed=random_seed,
|
| 131 |
temperature=temperature,
|
| 132 |
max_tokens=max_tokens,
|
| 133 |
)
|
requirements.txt
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
streamlit
|
| 2 |
openai
|
| 3 |
pydrive
|
| 4 |
-
boto3
|
| 5 |
-
clipboard
|
|
|
|
| 1 |
streamlit
|
| 2 |
openai
|
| 3 |
pydrive
|
| 4 |
+
boto3
|
|
|
upload.py
CHANGED
|
@@ -25,11 +25,3 @@ def get_file(file_name, bucket=st.secrets["S3_BUCKET"]):
|
|
| 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))
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
print(e)
|
| 27 |
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|