amoldwalunj commited on
Commit
f4c3ccc
·
1 Parent(s): 29710b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +211 -145
app.py CHANGED
@@ -11,7 +11,7 @@ import json
11
 
12
  os.environ["api_key"] == st.secrets["api_key"]
13
 
14
- #os.environ["OPENAI_API_KEY"] = api_key
15
  openai.api_key = os.getenv("api_key")
16
 
17
  os.environ["GSPREAD_CREDENTIALS"]= st.secrets["GSPREAD_CREDENTIALS"]
@@ -62,7 +62,7 @@ if page == 'Review Analysis':
62
  sheet_url = st.text_input('Enter the URL of your Google Sheet')
63
 
64
  # Add this in the part of your Streamlit app where the user can select the model
65
- models = ["gpt-3.5-turbo", "gpt-4"]
66
  selected_model = st.selectbox("Choose a model:", models)
67
 
68
  user_char_limit = st.number_input("Enter character limit for chunk:", value=9000, step=500)
@@ -291,7 +291,7 @@ if page == 'Feature Benefits':
291
  # prompt = st.text_area("Edit the prompt:", value=default_prompt, height=200)
292
 
293
  # Add this in the part of your Streamlit app where the user can select the model
294
- models = ["gpt-3.5-turbo", "gpt-4"]
295
  selected_model = st.selectbox("Choose a model:", models)
296
 
297
  # Extract sheet ID from URL
@@ -494,7 +494,7 @@ if page == 'Identify Avatars':
494
  sheet = gc.open_by_key(sheet_id)
495
 
496
  # Add this in the part of your Streamlit app where the user can select the model
497
- models = ["gpt-3.5-turbo", "gpt-4"]
498
  selected_model = st.selectbox("Choose a model:", models)
499
 
500
 
@@ -647,7 +647,7 @@ if page == 'Tone of Voice Manual':
647
  sheet = gc.open_by_key(sheet_id)
648
 
649
  # Add this in the part of your Streamlit app where the user can select the model
650
- models = ["gpt-3.5-turbo", "gpt-4"]
651
  selected_model = st.selectbox("Choose a model:", models)
652
 
653
  # Add the prompt
@@ -776,7 +776,7 @@ if page == 'review summary':
776
  sheet_url = st.text_input('Enter the URL of your Google Sheet')
777
 
778
  # Add this in the part of your Streamlit app where the user can select the model
779
- models = ["gpt-3.5-turbo", "gpt-4"]
780
  selected_model = st.selectbox("Choose a model:", models)
781
 
782
  # Set default prompts
@@ -989,197 +989,263 @@ if page == 'review summary':
989
  st.error(f"An error occurred while writing to Google Sheets: {e}")
990
 
991
 
992
- if page == 'question_answers':
993
- st.title('question answers')
994
 
995
- #gc = gspread.service_account(filename='arctic-rite-381810-e8bee8664772.json')
996
- gc = gspread.service_account_from_dict(credentials_dict)
997
 
998
- # Ask user for Google Sheet URL
999
- sheet_url = st.text_input('Enter the URL of your Google Sheet')
1000
 
1001
- # Add this in the part of your Streamlit app where the user can select the model
1002
- models = ["gpt-3.5-turbo", "gpt-4"]
1003
- selected_model = st.selectbox("Choose a model:", models)
1004
 
1005
- # Extract sheet ID from URL
1006
- sheet_id = sheet_url.split('/')[5]
1007
- # Open the Google spreadsheet
1008
- sheet = gc.open_by_key(sheet_id)
1009
 
1010
- # Select sheet named 'Listing'
1011
- worksheet = sheet.worksheet('Listing')
1012
- # Get all records of the data
1013
- df = get_as_dataframe(worksheet)
1014
 
1015
- # Convert DataFrame to strings
1016
- df_str = df.astype(str)
1017
 
1018
- title = df[df.eq('Title').any(axis=1)].iloc[0, 2]
1019
- bullets = [df[df.eq(f"Bullet #{i}").any(axis=1)].iloc[0, 2] for i in range(1, 6)]
1020
 
1021
- backend_search_terms = df[df.astype(str).apply(lambda x: 'Backend Search Terms' in ' '.join(x), axis=1)].iloc[0, 2] if len(df[df.astype(str).apply(lambda x: 'Backend Search Terms' in ' '.join(x), axis=1)]) > 0 else None
1022
 
1023
- image_text_row = df[df.eq('Image Text').any(axis=1)]
1024
- image_text = list(image_text_row.dropna(axis=1).iloc[0, :])
1025
 
1026
- a_plus_desc_mask = df.astype(str).apply(lambda x: 'A+ Description' in ' '.join(x), axis=1)
1027
- if a_plus_desc_mask.any():
1028
- a_plus_desc_row = df[a_plus_desc_mask].index[0]
1029
- a_plus_desc = df.iloc[a_plus_desc_row:, :].fillna('').values.flatten()
1030
- a_plus_desc = ' '.join(a_plus_desc).strip()
1031
- else:
1032
- a_plus_desc = None
1033
 
1034
- legacy_desc = df[df.astype(str).apply(lambda x: 'Legacy Product Description' in ' '.join(x), axis=1)].iloc[0, 2] if len(df[df.astype(str).apply(lambda x: 'Legacy Product Description' in ' '.join(x), axis=1)]) > 0 else None
1035
 
1036
- image_text_string = ' '.join(image_text)
1037
 
1038
- bullet_str = ""
1039
- for i, bullet in enumerate(bullets, 1):
1040
- bullet_str += f"Bullet #{i}: {bullet}\n"
1041
 
1042
- # Display default prompt to user
1043
- default_prompt = """Below is data of our products for amazon listing:
1044
- ------------------------------------
1045
- Title: {}\n
1046
- bullet_str: {}\n
1047
- Legacy Product Description: {}\n
1048
- A+ Description: {}\n
1049
- Image_text: {}\n
1050
- backend_search_terms: {}\n
1051
- -------------------------------------
1052
 
1053
- Please create question-answers pairs for amazon listing using this data.
1054
- Please segregate them theme wise. themes names should not be features or benefits and create 1 or more questions answer pairs for each theme.
1055
- questions generated should be potential questions in customer mind before buying product.
1056
- please create at least 20 question-answers pairs.
1057
- """.format(title, bullet_str, legacy_desc, a_plus_desc, image_text_string, backend_search_terms)
1058
 
1059
- prompt = st.text_area("Edit the prompt:", value=default_prompt, height=200)
1060
 
1061
 
1062
 
1063
- # If the user has input a URL, fetch the data from Google Sheets
1064
- if st.button('generate'):
1065
 
1066
- messages = [
1067
- {"role": "system", "content": "You are helpful assistant"},
1068
- {"role": "user", "content": prompt}
1069
- ]
1070
 
1071
 
1072
 
1073
- model_response = get_chatgpt_response(messages, selected_model)
1074
 
1075
- question_answers= model_response
1076
 
1077
- st.session_state.question_answers = question_answers
1078
 
1079
- st.write(question_answers)
1080
 
1081
- def parse_qa(text):
1082
- try:
1083
- # Split the text into themes
1084
- themes = re.split(r'\nTheme: ', text)[1:]
1085
 
1086
- output = []
1087
- for theme in themes:
1088
- theme_lines = theme.split('\n')
1089
- theme_name = theme_lines[0]
1090
- qa_pairs = theme_lines[1:]
1091
 
1092
- # Extract question and answer pairs
1093
- for qa in qa_pairs:
1094
- if qa.startswith('Q'):
1095
- question = qa.split(': ', 1)[1]
1096
- elif qa.startswith('A'):
1097
- answer = qa.split(': ', 1)[1]
1098
- output.append((theme_name, question, answer))
1099
- return output, True
1100
- except Exception as e:
1101
- return text, False # Return the full text and a flag indicating the parsing failed
1102
 
1103
 
1104
 
1105
- # # Create a button that will trigger writing to Google Sheets
1106
- # if st.button('Write output to sheet'):
1107
 
1108
- # final_output= st.session_state.question_answers
1109
 
1110
- # st.write("Button clicked, processing data...")
1111
 
1112
- # sheet_id = sheet_url.split('/')[5] # Open the Google spreadsheet
1113
- # sheet = gc.open_by_key(sheet_id)
1114
 
1115
 
1116
 
1117
 
1118
 
1119
- # try:
1120
- # # Check if the "tone_of_voice_manual" worksheet already exists
1121
- # worksheet_output = None
1122
- # for wks in sheet.worksheets():
1123
- # if wks.title == 'question_answers':
1124
- # worksheet_output = wks
1125
- # break
1126
 
1127
- # # If the worksheet does not exist, create a new one
1128
- # if worksheet_output is None:
1129
- # worksheet_output = sheet.add_worksheet(title="question_answers", rows="100", cols="20")
1130
 
1131
- # # Read the existing data from the worksheet
1132
- # existing_data = get_as_dataframe(worksheet_output)
1133
 
1134
- # # Remove empty columns from the existing data
1135
- # existing_data = existing_data.dropna(how='all', axis=1)
1136
 
1137
- # # Prepare a list to store the tone of voice manual data
1138
- # question_answers_data = [final_output]
1139
 
1140
- # # Convert the list of tone of voice manual data into a DataFrame
1141
- # new_data = pd.DataFrame(question_answers_data, columns=['question_answers'])
1142
 
1143
- # # Append the new data to the existing data
1144
- # updated_data = pd.concat([existing_data, new_data], axis=1)
1145
 
1146
- # # Clear the worksheet before writing the updated data
1147
- # worksheet_output.clear()
1148
 
1149
- # # Write the updated data to the "tone_of_voice_manual" worksheet
1150
- # set_with_dataframe(worksheet_output, updated_data)
1151
- # st.write("Data written successfully to Google Sheets.")
1152
- # except Exception as e:
1153
- # st.error(f"An error occurred while writing to Google Sheets: {e}")
1154
 
1155
- if st.button('Write output to sheet'):
1156
- final_output, parsed_successfully = parse_qa(st.session_state.question_answers)
1157
 
1158
- st.write("Button clicked, processing data...")
1159
 
1160
- sheet_id = sheet_url.split('/')[5] # Open the Google spreadsheet
1161
- sheet = gc.open_by_key(sheet_id)
1162
 
1163
- try:
1164
- worksheet_output = None
1165
- for wks in sheet.worksheets():
1166
- if wks.title == 'question_answers':
1167
- worksheet_output = wks
1168
- break
1169
 
1170
- if worksheet_output is None:
1171
- worksheet_output = sheet.add_worksheet(title="question_answers", rows="100", cols="20")
1172
 
1173
- if parsed_successfully:
1174
- new_data = pd.DataFrame(final_output, columns=['Theme', 'Question', 'Answer'])
1175
- else:
1176
- new_data = pd.DataFrame([final_output], columns=['Output'])
1177
 
1178
- worksheet_output.clear()
1179
- set_with_dataframe(worksheet_output, new_data)
1180
- st.write("Data written successfully to Google Sheets.")
1181
- except Exception as e:
1182
- st.error(f"An error occurred while writing to Google Sheets: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1183
 
1184
 
1185
  if page == 'feature_mapping':
@@ -1191,7 +1257,7 @@ if page == 'feature_mapping':
1191
  sheet_url = st.text_input('Enter the URL of your Google Sheet')
1192
 
1193
  # Add this in the part of your Streamlit app where the user can select the model
1194
- models = ["gpt-3.5-turbo", "gpt-4"]
1195
  selected_model = st.selectbox("Choose a model:", models)
1196
 
1197
  # Extract sheet ID from URL
@@ -1315,7 +1381,7 @@ if page == 'benefit_mapping':
1315
  sheet_url = st.text_input('Enter the URL of your Google Sheet')
1316
 
1317
  # Add this in the part of your Streamlit app where the user can select the model
1318
- models = ["gpt-3.5-turbo", "gpt-4"]
1319
  selected_model = st.selectbox("Choose a model:", models)
1320
 
1321
  # Extract sheet ID from URL
@@ -1447,7 +1513,7 @@ def page_combined_features_and_benefits():
1447
  for url in sheet_urls:
1448
  st.write(url)
1449
 
1450
- models = ["gpt-3.5-turbo", "gpt-4"]
1451
  selected_model = st.selectbox("Choose a model:", models)
1452
 
1453
  user_char_limit = st.number_input("Enter character limit for chunk:", value=9000, step=500)
 
11
 
12
  os.environ["api_key"] == st.secrets["api_key"]
13
 
14
+ #os.environ["OPENAI_API_KEY"] = api_key
15
  openai.api_key = os.getenv("api_key")
16
 
17
  os.environ["GSPREAD_CREDENTIALS"]= st.secrets["GSPREAD_CREDENTIALS"]
 
62
  sheet_url = st.text_input('Enter the URL of your Google Sheet')
63
 
64
  # Add this in the part of your Streamlit app where the user can select the model
65
+ models = ["gpt-3.5-turbo", "gpt-4", "gpt-3.5-turbo-16k"]
66
  selected_model = st.selectbox("Choose a model:", models)
67
 
68
  user_char_limit = st.number_input("Enter character limit for chunk:", value=9000, step=500)
 
291
  # prompt = st.text_area("Edit the prompt:", value=default_prompt, height=200)
292
 
293
  # Add this in the part of your Streamlit app where the user can select the model
294
+ models = ["gpt-3.5-turbo", "gpt-4", "gpt-3.5-turbo-16k"]
295
  selected_model = st.selectbox("Choose a model:", models)
296
 
297
  # Extract sheet ID from URL
 
494
  sheet = gc.open_by_key(sheet_id)
495
 
496
  # Add this in the part of your Streamlit app where the user can select the model
497
+ models = ["gpt-3.5-turbo", "gpt-4", "gpt-3.5-turbo-16k"]
498
  selected_model = st.selectbox("Choose a model:", models)
499
 
500
 
 
647
  sheet = gc.open_by_key(sheet_id)
648
 
649
  # Add this in the part of your Streamlit app where the user can select the model
650
+ models = ["gpt-3.5-turbo", "gpt-4", "gpt-3.5-turbo-16k"]
651
  selected_model = st.selectbox("Choose a model:", models)
652
 
653
  # Add the prompt
 
776
  sheet_url = st.text_input('Enter the URL of your Google Sheet')
777
 
778
  # Add this in the part of your Streamlit app where the user can select the model
779
+ models = ["gpt-3.5-turbo", "gpt-4", "gpt-3.5-turbo-16k"]
780
  selected_model = st.selectbox("Choose a model:", models)
781
 
782
  # Set default prompts
 
989
  st.error(f"An error occurred while writing to Google Sheets: {e}")
990
 
991
 
992
+ # if page == 'question_answers':
993
+ # st.title('question answers')
994
 
995
+ # #gc = gspread.service_account(filename='arctic-rite-381810-e8bee8664772.json')
996
+ # gc = gspread.service_account_from_dict(credentials_dict)
997
 
998
+ # # Ask user for Google Sheet URL
999
+ # sheet_url = st.text_input('Enter the URL of your Google Sheet')
1000
 
1001
+ # # Add this in the part of your Streamlit app where the user can select the model
1002
+ # models = ["gpt-3.5-turbo", "gpt-4"]
1003
+ # selected_model = st.selectbox("Choose a model:", models)
1004
 
1005
+ # # Extract sheet ID from URL
1006
+ # sheet_id = sheet_url.split('/')[5]
1007
+ # # Open the Google spreadsheet
1008
+ # sheet = gc.open_by_key(sheet_id)
1009
 
1010
+ # # Select sheet named 'Listing'
1011
+ # worksheet = sheet.worksheet('Listing')
1012
+ # # Get all records of the data
1013
+ # df = get_as_dataframe(worksheet)
1014
 
1015
+ # # Convert DataFrame to strings
1016
+ # df_str = df.astype(str)
1017
 
1018
+ # title = df[df.eq('Title').any(axis=1)].iloc[0, 2]
1019
+ # bullets = [df[df.eq(f"Bullet #{i}").any(axis=1)].iloc[0, 2] for i in range(1, 6)]
1020
 
1021
+ # backend_search_terms = df[df.astype(str).apply(lambda x: 'Backend Search Terms' in ' '.join(x), axis=1)].iloc[0, 2] if len(df[df.astype(str).apply(lambda x: 'Backend Search Terms' in ' '.join(x), axis=1)]) > 0 else None
1022
 
1023
+ # image_text_row = df[df.eq('Image Text').any(axis=1)]
1024
+ # image_text = list(image_text_row.dropna(axis=1).iloc[0, :])
1025
 
1026
+ # a_plus_desc_mask = df.astype(str).apply(lambda x: 'A+ Description' in ' '.join(x), axis=1)
1027
+ # if a_plus_desc_mask.any():
1028
+ # a_plus_desc_row = df[a_plus_desc_mask].index[0]
1029
+ # a_plus_desc = df.iloc[a_plus_desc_row:, :].fillna('').values.flatten()
1030
+ # a_plus_desc = ' '.join(a_plus_desc).strip()
1031
+ # else:
1032
+ # a_plus_desc = None
1033
 
1034
+ # legacy_desc = df[df.astype(str).apply(lambda x: 'Legacy Product Description' in ' '.join(x), axis=1)].iloc[0, 2] if len(df[df.astype(str).apply(lambda x: 'Legacy Product Description' in ' '.join(x), axis=1)]) > 0 else None
1035
 
1036
+ # image_text_string = ' '.join(image_text)
1037
 
1038
+ # bullet_str = ""
1039
+ # for i, bullet in enumerate(bullets, 1):
1040
+ # bullet_str += f"Bullet #{i}: {bullet}\n"
1041
 
1042
+ # # Display default prompt to user
1043
+ # default_prompt = """Below is data of our products for amazon listing:
1044
+ # ------------------------------------
1045
+ # Title: {}\n
1046
+ # bullet_str: {}\n
1047
+ # Legacy Product Description: {}\n
1048
+ # A+ Description: {}\n
1049
+ # Image_text: {}\n
1050
+ # backend_search_terms: {}\n
1051
+ # -------------------------------------
1052
 
1053
+ # Please create question-answers pairs for amazon listing using this data.
1054
+ # Please segregate them theme wise. themes names should not be features or benefits and create 1 or more questions answer pairs for each theme.
1055
+ # questions generated should be potential questions in customer mind before buying product.
1056
+ # please create at least 20 question-answers pairs.
1057
+ # """.format(title, bullet_str, legacy_desc, a_plus_desc, image_text_string, backend_search_terms)
1058
 
1059
+ # prompt = st.text_area("Edit the prompt:", value=default_prompt, height=200)
1060
 
1061
 
1062
 
1063
+ # # If the user has input a URL, fetch the data from Google Sheets
1064
+ # if st.button('generate'):
1065
 
1066
+ # messages = [
1067
+ # {"role": "system", "content": "You are helpful assistant"},
1068
+ # {"role": "user", "content": prompt}
1069
+ # ]
1070
 
1071
 
1072
 
1073
+ # model_response = get_chatgpt_response(messages, selected_model)
1074
 
1075
+ # question_answers= model_response
1076
 
1077
+ # st.session_state.question_answers = question_answers
1078
 
1079
+ # st.write(question_answers)
1080
 
1081
+ # def parse_qa(text):
1082
+ # try:
1083
+ # # Split the text into themes
1084
+ # themes = re.split(r'\nTheme: ', text)[1:]
1085
 
1086
+ # output = []
1087
+ # for theme in themes:
1088
+ # theme_lines = theme.split('\n')
1089
+ # theme_name = theme_lines[0]
1090
+ # qa_pairs = theme_lines[1:]
1091
 
1092
+ # # Extract question and answer pairs
1093
+ # for qa in qa_pairs:
1094
+ # if qa.startswith('Q'):
1095
+ # question = qa.split(': ', 1)[1]
1096
+ # elif qa.startswith('A'):
1097
+ # answer = qa.split(': ', 1)[1]
1098
+ # output.append((theme_name, question, answer))
1099
+ # return output, True
1100
+ # except Exception as e:
1101
+ # return text, False # Return the full text and a flag indicating the parsing failed
1102
 
1103
 
1104
 
1105
+ # # # Create a button that will trigger writing to Google Sheets
1106
+ # # if st.button('Write output to sheet'):
1107
 
1108
+ # # final_output= st.session_state.question_answers
1109
 
1110
+ # # st.write("Button clicked, processing data...")
1111
 
1112
+ # # sheet_id = sheet_url.split('/')[5] # Open the Google spreadsheet
1113
+ # # sheet = gc.open_by_key(sheet_id)
1114
 
1115
 
1116
 
1117
 
1118
 
1119
+ # # try:
1120
+ # # # Check if the "tone_of_voice_manual" worksheet already exists
1121
+ # # worksheet_output = None
1122
+ # # for wks in sheet.worksheets():
1123
+ # # if wks.title == 'question_answers':
1124
+ # # worksheet_output = wks
1125
+ # # break
1126
 
1127
+ # # # If the worksheet does not exist, create a new one
1128
+ # # if worksheet_output is None:
1129
+ # # worksheet_output = sheet.add_worksheet(title="question_answers", rows="100", cols="20")
1130
 
1131
+ # # # Read the existing data from the worksheet
1132
+ # # existing_data = get_as_dataframe(worksheet_output)
1133
 
1134
+ # # # Remove empty columns from the existing data
1135
+ # # existing_data = existing_data.dropna(how='all', axis=1)
1136
 
1137
+ # # # Prepare a list to store the tone of voice manual data
1138
+ # # question_answers_data = [final_output]
1139
 
1140
+ # # # Convert the list of tone of voice manual data into a DataFrame
1141
+ # # new_data = pd.DataFrame(question_answers_data, columns=['question_answers'])
1142
 
1143
+ # # # Append the new data to the existing data
1144
+ # # updated_data = pd.concat([existing_data, new_data], axis=1)
1145
 
1146
+ # # # Clear the worksheet before writing the updated data
1147
+ # # worksheet_output.clear()
1148
 
1149
+ # # # Write the updated data to the "tone_of_voice_manual" worksheet
1150
+ # # set_with_dataframe(worksheet_output, updated_data)
1151
+ # # st.write("Data written successfully to Google Sheets.")
1152
+ # # except Exception as e:
1153
+ # # st.error(f"An error occurred while writing to Google Sheets: {e}")
1154
 
1155
+ # if st.button('Write output to sheet'):
1156
+ # final_output, parsed_successfully = parse_qa(st.session_state.question_answers)
1157
 
1158
+ # st.write("Button clicked, processing data...")
1159
 
1160
+ # sheet_id = sheet_url.split('/')[5] # Open the Google spreadsheet
1161
+ # sheet = gc.open_by_key(sheet_id)
1162
 
1163
+ # try:
1164
+ # worksheet_output = None
1165
+ # for wks in sheet.worksheets():
1166
+ # if wks.title == 'question_answers':
1167
+ # worksheet_output = wks
1168
+ # break
1169
 
1170
+ # if worksheet_output is None:
1171
+ # worksheet_output = sheet.add_worksheet(title="question_answers", rows="100", cols="20")
1172
 
1173
+ # if parsed_successfully:
1174
+ # new_data = pd.DataFrame(final_output, columns=['Theme', 'Question', 'Answer'])
1175
+ # else:
1176
+ # new_data = pd.DataFrame([final_output], columns=['Output'])
1177
 
1178
+ # worksheet_output.clear()
1179
+ # set_with_dataframe(worksheet_output, new_data)
1180
+ # st.write("Data written successfully to Google Sheets.")
1181
+ # except Exception as e:
1182
+ # st.error(f"An error occurred while writing to Google Sheets: {e}")
1183
+
1184
+ if page == 'question_answers':
1185
+ st.title('question answers')
1186
+
1187
+ #gc = gspread.service_account(filename='arctic-rite-381810-e8bee8664772.json')
1188
+ gc = gspread.service_account(filename='arctic-rite-381810-b124ba8c96a9.json')
1189
+
1190
+ sheet_url = st.text_input('Enter the URL of your Google Sheet')
1191
+
1192
+ models = ["gpt-3.5-turbo", "gpt-4", "gpt-3.5-turbo-16k"]
1193
+ selected_model = st.selectbox("Choose a model:", models)
1194
+
1195
+ # Extract sheet ID from URL
1196
+ sheet_id = sheet_url.split('/')[5]
1197
+ # Open the Google spreadsheet
1198
+ sheet = gc.open_by_key(sheet_id)
1199
+
1200
+ # Select sheet named 'Listing'
1201
+ worksheet = sheet.worksheet('Q&A')
1202
+ # Get all records of the data
1203
+ df = get_as_dataframe(worksheet)
1204
+
1205
+ df= df.dropna(subset = ['Question', 'Answer'])
1206
+
1207
+ st.write(df)
1208
+
1209
+ question_answer = "\n".join(["Question: {}\nAnswer: {}".format(q, a) for q, a in zip(df['Question'], df['Answer'])])
1210
+
1211
+ #st.write(question_answer)
1212
+
1213
+ st.write(len(question_answer))
1214
+
1215
+ # Display default prompt to user
1216
+ default_prompt = """Below is question-answer pairs from amazon listing:
1217
+ ------------------------------------
1218
+ {}
1219
+ -------------------------------------
1220
+ please analyze these question-answer pairs and group them theme-wise. you have find themes and then group question-answer pairs as per theme. Don't miss any question pair given above. give numbering to questions.
1221
+ """.format(question_answer)
1222
+
1223
+ prompt = st.text_area("Edit the prompt:", value=default_prompt, height=200)
1224
+
1225
+ # If the user has input a URL, fetch the data from Google Sheets
1226
+ if st.button('generate'):
1227
+
1228
+ messages = [
1229
+ {"role": "system", "content": "You are helpful assistant"},
1230
+ {"role": "user", "content": prompt}
1231
+ ]
1232
+
1233
+ model_response = get_chatgpt_response(messages, selected_model)
1234
+
1235
+ question_answers= model_response
1236
+
1237
+ st.session_state.question_answers = question_answers
1238
+
1239
+ st.write(question_answers)
1240
+
1241
+
1242
+ if st.button('Write output to sheet'):
1243
+ question_answers = st.session_state.question_answers
1244
+ # Create a new Google Sheets file
1245
+ new_worksheet = sheet.add_worksheet(title="QnA_analyzed", rows="100", cols="20")
1246
+
1247
+ # Add rows one by one
1248
+ new_worksheet.append_row(['question_answers', question_answers])
1249
 
1250
 
1251
  if page == 'feature_mapping':
 
1257
  sheet_url = st.text_input('Enter the URL of your Google Sheet')
1258
 
1259
  # Add this in the part of your Streamlit app where the user can select the model
1260
+ models = ["gpt-3.5-turbo", "gpt-4", "gpt-3.5-turbo-16k"]
1261
  selected_model = st.selectbox("Choose a model:", models)
1262
 
1263
  # Extract sheet ID from URL
 
1381
  sheet_url = st.text_input('Enter the URL of your Google Sheet')
1382
 
1383
  # Add this in the part of your Streamlit app where the user can select the model
1384
+ models = ["gpt-3.5-turbo", "gpt-4", "gpt-3.5-turbo-16k"]
1385
  selected_model = st.selectbox("Choose a model:", models)
1386
 
1387
  # Extract sheet ID from URL
 
1513
  for url in sheet_urls:
1514
  st.write(url)
1515
 
1516
+ models = ["gpt-3.5-turbo", "gpt-4", "gpt-3.5-turbo-16k"]
1517
  selected_model = st.selectbox("Choose a model:", models)
1518
 
1519
  user_char_limit = st.number_input("Enter character limit for chunk:", value=9000, step=500)