Spaces:
Runtime error
Runtime error
update file structure
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
from openai import OpenAI
|
2 |
import streamlit as st
|
3 |
-
from utils import im_2_b64, calculate_cost
|
4 |
import pickle
|
5 |
from upload import upload_file, get_file
|
6 |
|
@@ -34,16 +34,6 @@ if len(st.session_state.messages) == 0 and "id" in st.query_params:
|
|
34 |
for k, v in obj.items():
|
35 |
st.session_state[k] = v
|
36 |
|
37 |
-
def clear_uploader():
|
38 |
-
st.session_state["uploader_key"] += 1
|
39 |
-
st.rerun()
|
40 |
-
|
41 |
-
def undo():
|
42 |
-
if len(st.session_state.messages) > 0:
|
43 |
-
st.session_state.messages.pop()
|
44 |
-
st.session_state.messages.pop()
|
45 |
-
st.session_state.cost.pop()
|
46 |
-
st.rerun()
|
47 |
|
48 |
def share():
|
49 |
obj = {}
|
@@ -63,8 +53,7 @@ with st.sidebar:
|
|
63 |
cols = st.columns(2)
|
64 |
with cols[0]:
|
65 |
if st.button("Restart", type="primary", use_container_width=True):
|
66 |
-
|
67 |
-
clear_uploader()
|
68 |
|
69 |
with cols[1]:
|
70 |
if st.button("Undo", use_container_width=True):
|
|
|
1 |
from openai import OpenAI
|
2 |
import streamlit as st
|
3 |
+
from utils import im_2_b64, calculate_cost, clear_uploader, undo, restart
|
4 |
import pickle
|
5 |
from upload import upload_file, get_file
|
6 |
|
|
|
34 |
for k, v in obj.items():
|
35 |
st.session_state[k] = v
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
def share():
|
39 |
obj = {}
|
|
|
53 |
cols = st.columns(2)
|
54 |
with cols[0]:
|
55 |
if st.button("Restart", type="primary", use_container_width=True):
|
56 |
+
restart()
|
|
|
57 |
|
58 |
with cols[1]:
|
59 |
if st.button("Undo", use_container_width=True):
|
utils.py
CHANGED
@@ -43,3 +43,21 @@ def calculate_cost():
|
|
43 |
total_cost += get_text_cost(content["text"], UNIT_COST[role])
|
44 |
|
45 |
st.session_state.cost.append(total_cost)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
total_cost += get_text_cost(content["text"], UNIT_COST[role])
|
44 |
|
45 |
st.session_state.cost.append(total_cost)
|
46 |
+
|
47 |
+
|
48 |
+
def clear_uploader():
|
49 |
+
st.session_state["uploader_key"] += 1
|
50 |
+
st.rerun()
|
51 |
+
|
52 |
+
def undo():
|
53 |
+
if len(st.session_state.messages) > 0:
|
54 |
+
st.session_state.messages.pop()
|
55 |
+
st.session_state.messages.pop()
|
56 |
+
st.session_state.cost.pop()
|
57 |
+
st.rerun()
|
58 |
+
|
59 |
+
def restart():
|
60 |
+
st.session_state.messages = []
|
61 |
+
st.session_state.cost = []
|
62 |
+
st.query_params.clear()
|
63 |
+
clear_uploader()
|