Zekun Wu commited on
Commit
228f205
1 Parent(s): b6e7533
Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -1,13 +1,22 @@
 
1
  import streamlit as st
2
  import os
3
  import json
4
  from openai import AzureOpenAI
5
  from model import create_models, configure_settings, load_documents_and_create_index, \
6
  create_chat_prompt_template, execute_query
 
7
 
8
  client = AzureOpenAI(azure_endpoint="https://personality-service.openai.azure.com/",
9
  api_key=os.getenv("AZURE_OPENAI_KEY"), api_version="2024-02-15-preview")
10
 
 
 
 
 
 
 
 
11
 
12
  # Function to generate a completion using OpenAI API
13
  def generate_one_completion(message, temperature):
@@ -171,6 +180,15 @@ def main_app():
171
 
172
  st.session_state['analysis'] = response
173
  st.session_state['show_chat'] = True
 
 
 
 
 
 
 
 
 
174
  st.rerun()
175
 
176
  # display the response
@@ -261,8 +279,8 @@ def sidebar_components():
261
  # st.session_state['profile'] = json.load(uploaded_file)
262
  else:
263
  st.sidebar.title("Chat with Our Career Advisor")
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')
@@ -306,8 +324,19 @@ def sidebar_components():
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)
310
 
 
 
 
 
 
 
 
 
 
 
311
  # Initialize session state variables with default values if not already set
312
  session_defaults = {
313
  'show_chat': None,
 
1
+ import pandas as pd
2
  import streamlit as st
3
  import os
4
  import json
5
  from openai import AzureOpenAI
6
  from model import create_models, configure_settings, load_documents_and_create_index, \
7
  create_chat_prompt_template, execute_query
8
+ from datasets import Dataset, DatasetDict, load_dataset, concatenate_datasets
9
 
10
  client = AzureOpenAI(azure_endpoint="https://personality-service.openai.azure.com/",
11
  api_key=os.getenv("AZURE_OPENAI_KEY"), api_version="2024-02-15-preview")
12
 
13
+ TOKEN = os.getenv('hf_token')
14
+ def store_feedback(user_input, response, feedback, rating,repo):
15
+ dataset = load_dataset(repo, use_auth_token=TOKEN, download_mode="force_redownload", ignore_verifications=True)
16
+ new_entry = pd.DataFrame({"user_input": [user_input], "response": [response], "feedback": [feedback], "rating": [rating]})
17
+ new_dataset = Dataset.from_pandas(new_entry)
18
+ updated_dataset = concatenate_datasets([dataset["train"], new_dataset])
19
+ updated_dataset.push_to_hub(repo, private=False, use_auth_token=TOKEN)
20
 
21
  # Function to generate a completion using OpenAI API
22
  def generate_one_completion(message, temperature):
 
180
 
181
  st.session_state['analysis'] = response
182
  st.session_state['show_chat'] = True
183
+
184
+ # Ask for feedback
185
+ feedback = st.text_input("Provide your feedback on the response:")
186
+ rating = st.slider("Rate the response:", 0, 10, 5)
187
+
188
+ if st.sidebar.button('Submit Feedback'):
189
+ store_feedback(str(prompt), response, feedback, rating, "wu981526092/feedback_report")
190
+ st.sidebar.success("Feedback submitted successfully!")
191
+
192
  st.rerun()
193
 
194
  # display the response
 
279
  # st.session_state['profile'] = json.load(uploaded_file)
280
  else:
281
  st.sidebar.title("Chat with Our Career Advisor")
282
+ #st.sidebar.markdown(
283
+ #"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.")
284
 
285
  # Name to be included in the questions
286
  # name = st.session_state['profile']['bio_information'].get('Name', 'the individual')
 
324
  chat_prompt_template = create_chat_prompt_template(st.session_state['analysis'],st.session_state['definition'])
325
  response = execute_query(index, chat_prompt_template, user_input)
326
 
327
+ # Display the response
328
  st.sidebar.markdown(response)
329
 
330
+ # Ask for feedback
331
+ feedback = st.sidebar.text_input("Provide your feedback on the response:")
332
+ rating = st.sidebar.slider("Rate the response:", 0, 10, 5)
333
+
334
+ if st.sidebar.button('Submit Feedback'):
335
+ store_feedback(user_input, response, feedback, rating, "wu981526092/feedback_report")
336
+ st.sidebar.success("Feedback submitted successfully!")
337
+
338
+
339
+
340
  # Initialize session state variables with default values if not already set
341
  session_defaults = {
342
  'show_chat': None,