Myranda commited on
Commit
a7669c5
1 Parent(s): b5eafbd

Merge pull request #111 from vanderbilt-data-science/issues-10567

Browse files
Files changed (1) hide show
  1. app.py +8 -7
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", ["Account Setup", "OpenAI API Key Setup", "Respond to Post"])
62
 
63
  # Fetch user data from the database
64
  user_data = get_user_data(username)
@@ -77,15 +77,15 @@ if authentication_status:
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"):
86
  db.put({"key": username, "principles": principles, "writing_style": writing_style, "api_key": encrypted_api_key})
87
 
88
- if page == "OpenAI API Key Setup":
89
  st.title("OpenAI API Key Setup")
90
 
91
  st.header('What is an API key?')
@@ -117,10 +117,11 @@ if authentication_status:
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)
 
124
 
125
  chat_mdl = None
126
  draft_response = ''
@@ -136,7 +137,7 @@ if authentication_status:
136
 
137
  if chat_mdl is not None:
138
  if user_data is None:
139
- draft_response, background_text = generate_custom_response(original_post, chat_mdl, "", "")
140
  st.session_state.draft_response = draft_response.content
141
  st.session_state.background_text = background_text
142
  #st.session_state.sources_text = sources_text
@@ -144,7 +145,7 @@ if authentication_status:
144
  #st.session_state.sources = sources_text
145
  st.rerun()
146
  else:
147
- draft_response, background_text = generate_custom_response(original_post, chat_mdl, user_data['principles'], user_data['writing_style'])
148
  st.session_state.draft_response = draft_response.content
149
  st.session_state.background_text = background_text
150
  #st.session_state.sources_text = sources_text
 
58
  st.write(f'Welcome *{name}*')
59
 
60
  # Sidebar for navigation
61
+ page = st.sidebar.radio("Choose a page", ["Account Setup", "API Key Help", "Respond to Post"])
62
 
63
  # Fetch user data from the database
64
  user_data = get_user_data(username)
 
77
  encrypted_api_key = str(encrypt(api_input, fernet))
78
  st.session_state.api_key = api_input
79
 
80
+ principles = st.text_area("My Principles (Paste Principles here)", height = 100, 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_area("My Writing Style (Paste Examples)", height = 100, 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"):
86
  db.put({"key": username, "principles": principles, "writing_style": writing_style, "api_key": encrypted_api_key})
87
 
88
+ if page == "API Key Help":
89
  st.title("OpenAI API Key Setup")
90
 
91
  st.header('What is an API key?')
 
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 = 780, 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)
124
+ word_limit = st.text_input("Word Limit for Response", placeholder = "Please provide a word limit for the response")
125
 
126
  chat_mdl = None
127
  draft_response = ''
 
137
 
138
  if chat_mdl is not None:
139
  if user_data is None:
140
+ draft_response, background_text = generate_custom_response(original_post, chat_mdl, "", "", word_limit)
141
  st.session_state.draft_response = draft_response.content
142
  st.session_state.background_text = background_text
143
  #st.session_state.sources_text = sources_text
 
145
  #st.session_state.sources = sources_text
146
  st.rerun()
147
  else:
148
+ draft_response, background_text = generate_custom_response(original_post, chat_mdl, user_data['principles'], user_data['writing_style'], word_limit)
149
  st.session_state.draft_response = draft_response.content
150
  st.session_state.background_text = background_text
151
  #st.session_state.sources_text = sources_text