yuki-816 commited on
Commit
3c66cf8
·
1 Parent(s): 0f6520a

Upload streamlit_app.py

Browse files

Update generate_response parameters

Files changed (1) hide show
  1. streamlit_app.py +66 -49
streamlit_app.py CHANGED
@@ -50,13 +50,17 @@ def update_questionnaire_response(user_response, username):
50
  st.success("Your responses have been recorded. Thank you!")
51
 
52
 
53
- def generate_responses(text, chat_model="gpt-3.5-turbo", paper_title="", sci_familiarity="", tech_usage="",
54
- read_news="", language_spoken="", additional_requirements="None"):
 
55
  # Incorporating the parameters into the context
56
  text = text[:2048]
57
  user_context = f"""
58
- The user has {sci_familiarity} with scientific concepts. He/She {tech_usage} uses technology products.
59
- He/She {read_news} read or watch the news. The primary language spoken at his/her home is(are) {language_spoken}.
 
 
 
60
  """
61
 
62
  # print(user_context)
@@ -96,6 +100,7 @@ def survey(user_name):
96
  title = user_name + '_survey'
97
  return ss.StreamlitSurvey(title)
98
 
 
99
  # connect to/create Deta user database
100
  db_key = st.secrets["deta_key"]
101
  deta = Deta(db_key)
@@ -118,25 +123,23 @@ init_sidebar = st.sidebar.empty()
118
 
119
  with init_sidebar:
120
  init_page = option_menu(None,
121
- ["Login", 'Sign Up'],
122
- icons=['lightbulb-fill', 'lightbulb'],
123
- menu_icon="cast",
124
- default_index=0,
125
- styles={})
126
 
127
  if init_page == 'Login':
128
- st.cache_data.clear()
129
  name, authentication_status, username = authenticator.login('Login', 'main')
130
  if authentication_status:
131
  init_sidebar.empty()
 
132
  app_sidebar = st.sidebar.empty()
133
- # st.sidebar.write(f'Welcome {name}')
134
  if 'current_page_name' not in st.session_state:
135
  st.session_state.current_page_name = "Generate Plain Language Summary" # 设置默认页面
136
 
137
  with app_sidebar:
138
- # 'History'
139
- # 'folder2',
140
  page = option_menu(None, ["Generate Plain Language Summary", 'Questionnaire', 'Setup'],
141
  icons=['house', 'question-circle', 'gear'],
142
  menu_icon="None",
@@ -207,6 +210,26 @@ if init_page == 'Login':
207
  else:
208
  submit_text = abstract_text
209
  # Check if the "Submit" button is clicked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
  if st.button("Submit"):
211
  if abstract_text == '' and uploaded_file == None:
212
  st.warning('Please paste Abstract or upload a file.', icon="⚠️")
@@ -221,14 +244,20 @@ if init_page == 'Login':
221
  st.session_state.draft_response_content = generate_responses(
222
  text=submit_text,
223
  paper_title=title_text,
224
- sci_familiarity=user_response[
225
- 'paper_familiarity'],
 
 
 
 
 
226
  tech_usage=user_response[
227
  'tech_usage'],
228
- read_news=user_response[
229
  'news_read'],
230
- language_spoken=user_response[
231
- 'language_spoken'],)
 
232
 
233
  container = st.empty()
234
  # Output from function
@@ -246,15 +275,21 @@ if init_page == 'Login':
246
  st.session_state.draft_response_content = generate_responses(
247
  text=submit_text,
248
  paper_title=title_text,
249
- sci_familiarity=user_response[
250
- 'paper_familiarity'],
 
 
 
 
 
251
  tech_usage=user_response[
252
  'tech_usage'],
253
- read_news=user_response[
254
  'news_read'],
255
- language_spoken=user_response[
256
- 'language_spoken'],
257
- additional_requirements=additional_prompt)
 
258
  container.empty()
259
  container.text_area(label="Plain Language Summary", value=st.session_state.draft_response_content,
260
  height=350)
@@ -284,7 +319,7 @@ if init_page == 'Login':
284
  if 'questionnaire_response' not in st.session_state:
285
  st.session_state['questionnaire_response'] = {}
286
  # print(st.session_state['questionnaire_response'])
287
- page_number = 12
288
  survey_pages = survey.pages(page_number,
289
  on_submit=lambda: update_questionnaire_response(
290
  st.session_state['questionnaire_response'], username))
@@ -340,29 +375,11 @@ if init_page == 'Login':
340
  desired_information.append(other_info)
341
  st.session_state['questionnaire_response']['desired_information'] = desired_information
342
  elif survey_pages.current == 5:
343
- st.write("#### What is your familiarity with the concepts of the paper?")
344
- st.markdown('''
345
- * No Familiarity: entirely unfamiliar, no prior knowledge
346
- * Limited Familiarity: basic awareness of the concepts in the paper, but not in-depth knowledge
347
- * Moderate Familiarity: reasonable understanding of the concepts in the paper, encountered before, or some background knowledge
348
- * Good Familiarity: a solid understanding due to prior exposure or study
349
- * Expert: highly knowledgeable and experienced in the field and has worked extensively with these concepts
350
- ''')
351
- paper_familiarity = survey.select_slider(
352
- label="paper_familiarity",
353
- options=['No Familiarity', 'Limited Familiarity', 'Moderate Familiarity',
354
- 'Good Familiarity', 'Expert Familiarity'],
355
- # min_value=1,
356
- # max_value=5,
357
- label_visibility="collapsed",
358
- )
359
- st.session_state['questionnaire_response']['paper_familiarity'] = paper_familiarity
360
- elif survey_pages.current == 6:
361
  st.write("#### what is your level of english proficiency?")
362
  english_proficiency = st.slider("English Proficiency (1-5):", min_value=1, max_value=5, value=1)
363
  st.session_state['questionnaire_response']['english_proficiency'] = english_proficiency
364
 
365
- elif survey_pages.current == 7:
366
  st.write("#### What is the primary language spoken in your home? (click from the list and others)")
367
  languages = ['English', 'Spanish', ]
368
  language_options = {}
@@ -378,7 +395,7 @@ if init_page == 'Login':
378
  language_spoken.append(other_language)
379
  st.session_state['questionnaire_response']['language_spoken'] = language_spoken
380
 
381
- elif survey_pages.current == 8:
382
  st.write("#### Do you speak other languages? How fluent are you in each language?")
383
  language_fluency = {}
384
  language_index = 1
@@ -405,7 +422,7 @@ if init_page == 'Login':
405
  language_fluency.update({other_language: fluency})
406
  st.session_state['questionnaire_response']['other_language'] = language_fluency
407
 
408
- elif survey_pages.current == 9:
409
  st.write(
410
  "#### How much do you use technology (computers, cell phones, tablets, GPS, internet, etc.)?")
411
  st.markdown('''
@@ -424,7 +441,7 @@ if init_page == 'Login':
424
  label_visibility="collapsed",
425
  )
426
  st.session_state['questionnaire_response']['tech_usage'] = tech_usage
427
- elif survey_pages.current == 10:
428
  st.write("#### How often do you read or watch/listen to the news?")
429
  news_read = survey.radio(
430
  label="news_read",
@@ -435,11 +452,11 @@ if init_page == 'Login':
435
  horizontal=False,
436
  )
437
  st.session_state['questionnaire_response']['news_read'] = news_read
438
- elif survey_pages.current == 11:
439
  st.write("#### How many books do you read or listen to a month?")
440
  books_read = survey.radio(
441
  label="books_read",
442
- options=["None", "1-3", "4-6", "7+"],
443
  index=0,
444
  label_visibility="collapsed",
445
  horizontal=True,
 
50
  st.success("Your responses have been recorded. Thank you!")
51
 
52
 
53
+ def generate_responses(text, chat_model="gpt-3.5-turbo", paper_title="", level_education="",
54
+ paper_familiarity="", english_proficiency="", language_spoken="", tech_usage="",
55
+ news_read="", books_read="", additional_requirements="None"):
56
  # Incorporating the parameters into the context
57
  text = text[:2048]
58
  user_context = f"""
59
+ The user has achieved an education level up tp {level_education}. For the given paper content and concept, the user
60
+ describes his/her understanding as {paper_familiarity}. In daily routine, the user describes the frequency of using
61
+ technology such as computers, cell phones, and tablets as {tech_usage}. The user's primary language spoken at home is
62
+ {language_spoken}, and has {english_proficiency} level of English proficiency. The user {news_read} reads or watches
63
+ the news and reads approximately {books_read} books in a month.
64
  """
65
 
66
  # print(user_context)
 
100
  title = user_name + '_survey'
101
  return ss.StreamlitSurvey(title)
102
 
103
+
104
  # connect to/create Deta user database
105
  db_key = st.secrets["deta_key"]
106
  deta = Deta(db_key)
 
123
 
124
  with init_sidebar:
125
  init_page = option_menu(None,
126
+ ["Login", 'Sign Up'],
127
+ icons=['lightbulb-fill', 'lightbulb'],
128
+ menu_icon="cast",
129
+ default_index=0,
130
+ styles={})
131
 
132
  if init_page == 'Login':
 
133
  name, authentication_status, username = authenticator.login('Login', 'main')
134
  if authentication_status:
135
  init_sidebar.empty()
136
+ st.sidebar.write(f'**Welcome** {name}')
137
  app_sidebar = st.sidebar.empty()
138
+
139
  if 'current_page_name' not in st.session_state:
140
  st.session_state.current_page_name = "Generate Plain Language Summary" # 设置默认页面
141
 
142
  with app_sidebar:
 
 
143
  page = option_menu(None, ["Generate Plain Language Summary", 'Questionnaire', 'Setup'],
144
  icons=['house', 'question-circle', 'gear'],
145
  menu_icon="None",
 
210
  else:
211
  submit_text = abstract_text
212
  # Check if the "Submit" button is clicked
213
+
214
+ st.write("#### What is your familiarity with the concepts of the paper?")
215
+ st.markdown('''
216
+ * No Familiarity: entirely unfamiliar, no prior knowledge
217
+ * Limited Familiarity: basic awareness of the concepts in the paper, but not in-depth knowledge
218
+ * Moderate Familiarity: reasonable understanding of the concepts in the paper, encountered before, or some background knowledge
219
+ * Good Familiarity: a solid understanding due to prior exposure or study
220
+ * Expert: highly knowledgeable and experienced in the field and has worked extensively with these concepts
221
+ ''')
222
+ paper_familiarity = st.select_slider(
223
+ label="paper_familiarity",
224
+ options=['No Familiarity', 'Limited Familiarity', 'Moderate Familiarity',
225
+ 'Good Familiarity', 'Expert Familiarity'],
226
+ label_visibility="collapsed",
227
+ )
228
+
229
+ if 'paper_familiarity' not in st.session_state:
230
+ st.session_state['paper_familiarity'] = ''
231
+ st.session_state['paper_familiarity'] = paper_familiarity
232
+
233
  if st.button("Submit"):
234
  if abstract_text == '' and uploaded_file == None:
235
  st.warning('Please paste Abstract or upload a file.', icon="⚠️")
 
244
  st.session_state.draft_response_content = generate_responses(
245
  text=submit_text,
246
  paper_title=title_text,
247
+ level_education=user_response[
248
+ 'level_education'],
249
+ paper_familiarity=st.session_state['paper_familiarity'],
250
+ english_proficiency=user_response[
251
+ 'english_proficiency'],
252
+ language_spoken=user_response[
253
+ 'language_spoken'],
254
  tech_usage=user_response[
255
  'tech_usage'],
256
+ news_read=user_response[
257
  'news_read'],
258
+ books_read=user_response[
259
+ 'books_read'],
260
+ )
261
 
262
  container = st.empty()
263
  # Output from function
 
275
  st.session_state.draft_response_content = generate_responses(
276
  text=submit_text,
277
  paper_title=title_text,
278
+ level_education=user_response[
279
+ 'level_education'],
280
+ paper_familiarity=st.session_state['paper_familiarity'],
281
+ english_proficiency=user_response[
282
+ 'english_proficiency'],
283
+ language_spoken=user_response[
284
+ 'language_spoken'],
285
  tech_usage=user_response[
286
  'tech_usage'],
287
+ news_read=user_response[
288
  'news_read'],
289
+ books_read=user_response[
290
+ 'books_read'],
291
+ additional_requirements=additional_prompt,
292
+ )
293
  container.empty()
294
  container.text_area(label="Plain Language Summary", value=st.session_state.draft_response_content,
295
  height=350)
 
319
  if 'questionnaire_response' not in st.session_state:
320
  st.session_state['questionnaire_response'] = {}
321
  # print(st.session_state['questionnaire_response'])
322
+ page_number = 11
323
  survey_pages = survey.pages(page_number,
324
  on_submit=lambda: update_questionnaire_response(
325
  st.session_state['questionnaire_response'], username))
 
375
  desired_information.append(other_info)
376
  st.session_state['questionnaire_response']['desired_information'] = desired_information
377
  elif survey_pages.current == 5:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
378
  st.write("#### what is your level of english proficiency?")
379
  english_proficiency = st.slider("English Proficiency (1-5):", min_value=1, max_value=5, value=1)
380
  st.session_state['questionnaire_response']['english_proficiency'] = english_proficiency
381
 
382
+ elif survey_pages.current == 6:
383
  st.write("#### What is the primary language spoken in your home? (click from the list and others)")
384
  languages = ['English', 'Spanish', ]
385
  language_options = {}
 
395
  language_spoken.append(other_language)
396
  st.session_state['questionnaire_response']['language_spoken'] = language_spoken
397
 
398
+ elif survey_pages.current == 7:
399
  st.write("#### Do you speak other languages? How fluent are you in each language?")
400
  language_fluency = {}
401
  language_index = 1
 
422
  language_fluency.update({other_language: fluency})
423
  st.session_state['questionnaire_response']['other_language'] = language_fluency
424
 
425
+ elif survey_pages.current == 8:
426
  st.write(
427
  "#### How much do you use technology (computers, cell phones, tablets, GPS, internet, etc.)?")
428
  st.markdown('''
 
441
  label_visibility="collapsed",
442
  )
443
  st.session_state['questionnaire_response']['tech_usage'] = tech_usage
444
+ elif survey_pages.current == 9:
445
  st.write("#### How often do you read or watch/listen to the news?")
446
  news_read = survey.radio(
447
  label="news_read",
 
452
  horizontal=False,
453
  )
454
  st.session_state['questionnaire_response']['news_read'] = news_read
455
+ elif survey_pages.current == 10:
456
  st.write("#### How many books do you read or listen to a month?")
457
  books_read = survey.radio(
458
  label="books_read",
459
+ options=["0", "1-3", "4-6", "7+"],
460
  index=0,
461
  label_visibility="collapsed",
462
  horizontal=True,