Truong-Phuc commited on
Commit
0d8aa3d
1 Parent(s): 0ace885

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -6
app.py CHANGED
@@ -10,6 +10,9 @@ def file_selector(folder_path=r'./Dataset'):
10
  filenames = os.listdir(folder_path)
11
  return filenames, folder_path
12
 
 
 
 
13
  def revert_question_type_id(txt_question_type):
14
  if txt_question_type == 'What':
15
  return 0
@@ -112,7 +115,7 @@ txt_goto = col_4.selectbox(label='Sample', label_visibility='collapsed', options
112
  btn_goto = col_5.button(label=':fast_forward: Move to', use_container_width=True)
113
 
114
  if len(df) != 0:
115
- col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8, col_9, col_10 = st.columns(spec=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
116
  txt_context = st.text_area(height=200, label='Your context:', value=df['context'][st.session_state.idx])
117
 
118
  col_11, col_12, col_13 = st.columns([4.5, 1, 4.5])
@@ -157,13 +160,13 @@ if len(df) != 0:
157
  d_difficulty = col_eval_5.selectbox(label='[D] Difficulty:', options=options, index=options.index(d_difficulty_value))
158
 
159
  if btn_generate_distractor:
160
- if filename_input == 'BiologyQA_demo.csv':
161
  expert = 'biologist'
162
- elif filename_input == 'GeographyQA_demo.csv':
163
  expert = 'geographer'
164
- elif filename_input == 'HistoryQA_demo.csv':
165
  expert = 'historian'
166
- elif filename_input == 'CivicEduQA_demo.csv':
167
  expert = 'civic educator'
168
  url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent'
169
  headers = {'Content-Type': 'application/json'}
@@ -225,7 +228,10 @@ if len(df) != 0:
225
  df['d_difficulty'][st.session_state.idx] = d_difficulty
226
 
227
  df.to_csv(f'./Dataset/{filename_input}', index=None, encoding='utf-8-sig')
228
- st.rerun()
 
 
 
229
 
230
  if btn_goto:
231
  st.session_state.idx = txt_goto - 1
 
10
  filenames = os.listdir(folder_path)
11
  return filenames, folder_path
12
 
13
+ def convert_df(df):
14
+ return df.to_csv(index=False).encode('utf-8-sig')
15
+
16
  def revert_question_type_id(txt_question_type):
17
  if txt_question_type == 'What':
18
  return 0
 
115
  btn_goto = col_5.button(label=':fast_forward: Move to', use_container_width=True)
116
 
117
  if len(df) != 0:
118
+ # col_1, col_2, col_3, col_4, col_5, col_6, col_7, col_8, col_9, col_10 = st.columns(spec=[1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
119
  txt_context = st.text_area(height=200, label='Your context:', value=df['context'][st.session_state.idx])
120
 
121
  col_11, col_12, col_13 = st.columns([4.5, 1, 4.5])
 
160
  d_difficulty = col_eval_5.selectbox(label='[D] Difficulty:', options=options, index=options.index(d_difficulty_value))
161
 
162
  if btn_generate_distractor:
163
+ if filename_input == 'BiologyQA.csv':
164
  expert = 'biologist'
165
+ elif filename_input == 'GeographyQA.csv':
166
  expert = 'geographer'
167
+ elif filename_input == 'HistoryQA.csv':
168
  expert = 'historian'
169
+ elif filename_input == 'CivicEduQA.csv':
170
  expert = 'civic educator'
171
  url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent'
172
  headers = {'Content-Type': 'application/json'}
 
228
  df['d_difficulty'][st.session_state.idx] = d_difficulty
229
 
230
  df.to_csv(f'./Dataset/{filename_input}', index=None, encoding='utf-8-sig')
231
+ csv_file = convert_df(df=df)
232
+ col_6.download_button(data=csv_file, label=':arrow_down_small: Download file', use_container_width=True, file_name="processed.csv", mime="text/csv")
233
+
234
+ # st.rerun()
235
 
236
  if btn_goto:
237
  st.session_state.idx = txt_goto - 1