Spaces:
Sleeping
Sleeping
Zekun Wu
commited on
Commit
•
a60d2b1
1
Parent(s):
46a37a0
update
Browse files
app.py
CHANGED
@@ -26,6 +26,24 @@ def generate_one_completion(message, temperature):
|
|
26 |
|
27 |
import json
|
28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
def generate_prompt_from_profile(profile, version="TestTakersSummary"):
|
31 |
with open('prompts.json') as f:
|
@@ -162,26 +180,6 @@ def main_app():
|
|
162 |
else:
|
163 |
st.write("Please upload a profile JSON file or use the example profile.")
|
164 |
|
165 |
-
# if st.session_state['analysis']:
|
166 |
-
# st.markdown(st.session_state['analysis'])
|
167 |
-
# #st.markdown("### Analysis:")
|
168 |
-
# #analysis_container = st.container()
|
169 |
-
# # with analysis_container:
|
170 |
-
# #st.markdown(st.session_state['analysis'].choices[0].message.content)
|
171 |
-
#
|
172 |
-
# st.markdown("### Token Usage:")
|
173 |
-
# token_usage_container = st.expander("Show Token Usage Details")
|
174 |
-
# with token_usage_container:
|
175 |
-
# total_tokens = st.session_state['analysis'].usage.total_tokens
|
176 |
-
# prompt_tokens = st.session_state['analysis'].usage.prompt_tokens
|
177 |
-
# completion_tokens = st.session_state['analysis'].usage.completion_tokens
|
178 |
-
# costs = (0.01 / 1000) * prompt_tokens + (0.03 / 1000) * completion_tokens
|
179 |
-
# st.write(f'**Total tokens:** {total_tokens}')
|
180 |
-
# st.progress(completion_tokens / 1000)
|
181 |
-
# st.write(f'**Prompt tokens:** {prompt_tokens}')
|
182 |
-
# st.write(f'**Completion tokens:** {completion_tokens}')
|
183 |
-
# st.write(f'**Generation costs ($):** {costs}')
|
184 |
-
|
185 |
|
186 |
# Function to verify credentials and set the session state
|
187 |
def verify_credentials():
|
@@ -231,6 +229,7 @@ def sidebar_components():
|
|
231 |
|
232 |
st.markdown("### Choose the Definition:")
|
233 |
st.session_state['definition'] = st.selectbox("Select Definition", [1, 2])
|
|
|
234 |
|
235 |
# File uploader
|
236 |
st.markdown("### Upload a profile JSON file")
|
@@ -265,30 +264,8 @@ def sidebar_components():
|
|
265 |
st.sidebar.markdown(
|
266 |
"Hello, we hope you learned something about yourself in this report. This chat is here so you can ask any questions you have about your report! It’s also a great tool to get ideas about how you can use the information in your report for your personal development and achieving your current goals.")
|
267 |
|
268 |
-
# question_message = generate_prompt_from_profile(st.session_state['profile'])
|
269 |
-
# question_message.append(
|
270 |
-
# {"role": "system", "content": st.session_state['analysis'].choices[0].message.content})
|
271 |
-
# question_prompt = (
|
272 |
-
# f"Based on the earlier profile summary and analysis results about the individual, "
|
273 |
-
# f"generate two insightful questions that could be asked by that individual for further discussion about themself:\n\n"
|
274 |
-
# f"Provide me the questions in different new line."
|
275 |
-
# f"Suggested Questions:\n"
|
276 |
-
# )
|
277 |
-
# question_message.append({"role": "user", "content": question_prompt})
|
278 |
-
|
279 |
-
# questions = generate_one_completion(question_message, 0)
|
280 |
-
#
|
281 |
-
# questions_list = [question.strip() for question in questions.choices[0].message.content.split('\n')
|
282 |
-
# if question.strip()]
|
283 |
-
|
284 |
-
# questions_list = []
|
285 |
-
# print(questions_list)
|
286 |
-
# # Prepare the questions for Markdown display
|
287 |
-
# questions_markdown = "\n\n".join(
|
288 |
-
# [f"Q{question}" for index, question in enumerate(questions_list[:2])])
|
289 |
-
|
290 |
# Name to be included in the questions
|
291 |
-
name = st.session_state['profile']['bio_information'].get('Name', 'the individual')
|
292 |
|
293 |
# List of question templates where {} will be replaced with the name
|
294 |
question_templates = [
|
@@ -323,8 +300,10 @@ def sidebar_components():
|
|
323 |
|
324 |
if st.sidebar.button('Submit'):
|
325 |
if user_input:
|
326 |
-
|
327 |
-
|
|
|
|
|
328 |
response = execute_query(index, chat_prompt_template, user_input)
|
329 |
|
330 |
st.sidebar.markdown(response)
|
@@ -337,6 +316,9 @@ if 'show_chat' not in st.session_state:
|
|
337 |
if 'definition' not in st.session_state:
|
338 |
st.session_state['definition'] = 1
|
339 |
|
|
|
|
|
|
|
340 |
if 'profile' not in st.session_state:
|
341 |
st.session_state['profile'] = None
|
342 |
|
|
|
26 |
|
27 |
import json
|
28 |
|
29 |
+
def get_profile_str(profile):
|
30 |
+
bio_info = profile['bio_information']
|
31 |
+
main_profile = profile['main_profile']
|
32 |
+
red_flag = profile['red_flag']
|
33 |
+
motivation = profile['motivation']
|
34 |
+
profile_str = f"Bio Information:\n"
|
35 |
+
for key, value in bio_info.items():
|
36 |
+
profile_str += f"- {key.replace('_', ' ').title()}: {value}\n"
|
37 |
+
profile_str += f"\nMain Profile:\n"
|
38 |
+
for key, value in main_profile.items():
|
39 |
+
profile_str += f"- {key.title()}: {value['score']} - {value['summary']}\n"
|
40 |
+
profile_str += f"\nRed Flags:\n"
|
41 |
+
for key, value in red_flag.items():
|
42 |
+
profile_str += f"- {key.title()}: {value['score']} - {value['summary']}\n"
|
43 |
+
profile_str += f"\nMotivation:\n"
|
44 |
+
for key, value in motivation.items():
|
45 |
+
profile_str += f"- {key.title()}: {value['score']} - {value['summary']}\n"
|
46 |
+
return profile_str
|
47 |
|
48 |
def generate_prompt_from_profile(profile, version="TestTakersSummary"):
|
49 |
with open('prompts.json') as f:
|
|
|
180 |
else:
|
181 |
st.write("Please upload a profile JSON file or use the example profile.")
|
182 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
|
184 |
# Function to verify credentials and set the session state
|
185 |
def verify_credentials():
|
|
|
229 |
|
230 |
st.markdown("### Choose the Definition:")
|
231 |
st.session_state['definition'] = st.selectbox("Select Definition", [1, 2])
|
232 |
+
st.session_state['chat_context'] = st.selectbox("Select Chat Context", ["analysis", "profile"])
|
233 |
|
234 |
# File uploader
|
235 |
st.markdown("### Upload a profile JSON file")
|
|
|
264 |
st.sidebar.markdown(
|
265 |
"Hello, we hope you learned something about yourself in this report. This chat is here so you can ask any questions you have about your report! It’s also a great tool to get ideas about how you can use the information in your report for your personal development and achieving your current goals.")
|
266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
267 |
# Name to be included in the questions
|
268 |
+
# name = st.session_state['profile']['bio_information'].get('Name', 'the individual')
|
269 |
|
270 |
# List of question templates where {} will be replaced with the name
|
271 |
question_templates = [
|
|
|
300 |
|
301 |
if st.sidebar.button('Submit'):
|
302 |
if user_input:
|
303 |
+
if st.session_state['chat_context'] == "profile":
|
304 |
+
chat_prompt_template = create_chat_prompt_template(get_profile_str(st.session_state['profile']),st.session_state['definition'])
|
305 |
+
else:
|
306 |
+
chat_prompt_template = create_chat_prompt_template(st.session_state['analysis'],st.session_state['definition'])
|
307 |
response = execute_query(index, chat_prompt_template, user_input)
|
308 |
|
309 |
st.sidebar.markdown(response)
|
|
|
316 |
if 'definition' not in st.session_state:
|
317 |
st.session_state['definition'] = 1
|
318 |
|
319 |
+
if 'chat_context' not in st.session_state:
|
320 |
+
st.session_state['chat_context'] = "analysis"
|
321 |
+
|
322 |
if 'profile' not in st.session_state:
|
323 |
st.session_state['profile'] = None
|
324 |
|