Spaces:
Running
Running
Umang Chaudhry
commited on
Commit
•
93669b9
1
Parent(s):
b32f76b
Merge pull request #100 from vanderbilt-data-science/issue-37-95-96-image_path
Browse files- app.py +16 -7
- requirements.txt +1 -1
app.py
CHANGED
@@ -58,7 +58,7 @@ if authentication_status:
|
|
58 |
st.write(f'Welcome *{name}*')
|
59 |
|
60 |
# Sidebar for navigation
|
61 |
-
page = st.sidebar.radio("Choose a page", ["
|
62 |
|
63 |
# Fetch user data from the database
|
64 |
user_data = get_user_data(username)
|
@@ -73,13 +73,13 @@ if authentication_status:
|
|
73 |
|
74 |
if 'api_key' not in st.session_state:
|
75 |
st.session_state.api_key = ""
|
76 |
-
api_input = st.text_input("OpenAI API Key", value=decrypt(user_data["api_key"].encode()[2:-1], fernet) if user_data and "api_key" in user_data else "", type="password")
|
77 |
encrypted_api_key = str(encrypt(api_input, fernet))
|
78 |
st.session_state.api_key = api_input
|
79 |
|
80 |
-
principles = st.text_input("My Principles", placeholder = "Enter the main principles of your life you wish this response to uphold", value=user_data["principles"] if user_data and "principles" in user_data else "")
|
81 |
writing_style = st.text_input("My Writing Style (Paste Examples)", placeholder = "Provide examples of your writing style here", value=user_data["writing_style"] if user_data and "writing_style" in user_data else "")
|
82 |
-
sources = st.
|
83 |
|
84 |
# Update button
|
85 |
if st.button("Save Changes"):
|
@@ -94,7 +94,7 @@ if authentication_status:
|
|
94 |
st.header('Why do you need an API key?')
|
95 |
st.write('API keys allow sites to track usage and prevent abuse of their services. They help keep things secure. When you request an API key, the site knows the calls are coming from you.')
|
96 |
|
97 |
-
image = '
|
98 |
st.header('How to get an OpenAI API key:')
|
99 |
st.write('1. Go to https://platform.openai.com/account/api-keys')
|
100 |
st.write('2. Log in or create an OpenAI account if you do not have one')
|
@@ -117,7 +117,7 @@ if authentication_status:
|
|
117 |
# Input boxes
|
118 |
|
119 |
with right_col:
|
120 |
-
background_info = st.text_area("Background information on original post (
|
121 |
|
122 |
with left_col:
|
123 |
original_post = st.text_area("Paste Original Post Here \n", height=100)
|
@@ -198,7 +198,9 @@ if authentication_status:
|
|
198 |
os.environ['OPENAI_API_KEY'] = st.session_state.api_key
|
199 |
# add condition to check for passphrase to allow use of DSI api key stored in secrets
|
200 |
if (os.environ["OPENAI_API_KEY"] == st.secrets["secret_passphrase"]):
|
201 |
-
os.environ["OPENAI_API_KEY"] = st.secrets["dsi_openai_key"]
|
|
|
|
|
202 |
chat_mdl = ChatOpenAI(model_name='gpt-4', temperature=0.1)
|
203 |
|
204 |
if chat_mdl is not None:
|
@@ -211,6 +213,13 @@ if authentication_status:
|
|
211 |
|
212 |
elif authentication_status is False:
|
213 |
st.error('Username/password is incorrect')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
|
215 |
elif authentication_status is None:
|
216 |
st.warning('Please enter your username and password')
|
|
|
58 |
st.write(f'Welcome *{name}*')
|
59 |
|
60 |
# Sidebar for navigation
|
61 |
+
page = st.sidebar.radio("Choose a page", ["Account Setup", "OpenAI API Key Setup", "Respond to Post"])
|
62 |
|
63 |
# Fetch user data from the database
|
64 |
user_data = get_user_data(username)
|
|
|
73 |
|
74 |
if 'api_key' not in st.session_state:
|
75 |
st.session_state.api_key = ""
|
76 |
+
api_input = st.text_input("Paste OpenAI API Key", value=decrypt(user_data["api_key"].encode()[2:-1], fernet) if user_data and "api_key" in user_data else "", type="password")
|
77 |
encrypted_api_key = str(encrypt(api_input, fernet))
|
78 |
st.session_state.api_key = api_input
|
79 |
|
80 |
+
principles = st.text_input("My Principles (Paste Principles here)", placeholder = "Enter the main principles of your life you wish this response to uphold", value=user_data["principles"] if user_data and "principles" in user_data else "")
|
81 |
writing_style = st.text_input("My Writing Style (Paste Examples)", placeholder = "Provide examples of your writing style here", value=user_data["writing_style"] if user_data and "writing_style" in user_data else "")
|
82 |
+
sources = st.text_area("Sources (This autopopulates for your reference)", value=st.session_state.sources if 'sources' in st.session_state else '', key = 'sources_key', height = 100)
|
83 |
|
84 |
# Update button
|
85 |
if st.button("Save Changes"):
|
|
|
94 |
st.header('Why do you need an API key?')
|
95 |
st.write('API keys allow sites to track usage and prevent abuse of their services. They help keep things secure. When you request an API key, the site knows the calls are coming from you.')
|
96 |
|
97 |
+
image = 'apikeyex.png'
|
98 |
st.header('How to get an OpenAI API key:')
|
99 |
st.write('1. Go to https://platform.openai.com/account/api-keys')
|
100 |
st.write('2. Log in or create an OpenAI account if you do not have one')
|
|
|
117 |
# Input boxes
|
118 |
|
119 |
with right_col:
|
120 |
+
background_info = st.text_area("Background information on original post (This autopopulates for your reference)", height = 700, value=st.session_state.background_info if 'background_info' in st.session_state else '', key = 'background_info_key')
|
121 |
|
122 |
with left_col:
|
123 |
original_post = st.text_area("Paste Original Post Here \n", height=100)
|
|
|
198 |
os.environ['OPENAI_API_KEY'] = st.session_state.api_key
|
199 |
# add condition to check for passphrase to allow use of DSI api key stored in secrets
|
200 |
if (os.environ["OPENAI_API_KEY"] == st.secrets["secret_passphrase"]):
|
201 |
+
os.environ["OPENAI_API_KEY"] = st.secrets["dsi_openai_key"] #umang key
|
202 |
+
elif (os.environ["OPENAI_API_KEY"] == st.secrets["secret_passphrase2"]):
|
203 |
+
os.environ["OPENAI_API_KEY"] = st.secrets["dsi_openai_key2"] #abbie key
|
204 |
chat_mdl = ChatOpenAI(model_name='gpt-4', temperature=0.1)
|
205 |
|
206 |
if chat_mdl is not None:
|
|
|
213 |
|
214 |
elif authentication_status is False:
|
215 |
st.error('Username/password is incorrect')
|
216 |
+
#added registration module if username/password is incorrect
|
217 |
+
|
218 |
+
try:
|
219 |
+
if authenticator.register_user('New User Registration', preauthorization=False):
|
220 |
+
st.success('User Registered Successfully! Please log in above.')
|
221 |
+
except Exception as e:
|
222 |
+
st.error(e)
|
223 |
|
224 |
elif authentication_status is None:
|
225 |
st.warning('Please enter your username and password')
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
streamlit
|
2 |
streamlit-authenticator
|
3 |
deeplake
|
4 |
deta
|
|
|
1 |
+
streamlit == 1.27.0
|
2 |
streamlit-authenticator
|
3 |
deeplake
|
4 |
deta
|