Spaces:
Sleeping
Sleeping
Commit
·
9ad1d3a
1
Parent(s):
9ec1c48
Change outlook and add hard questions
Browse files- app.py +36 -21
- backend.py +119 -34
- offline_results/exp_ga.csv +0 -0
- offline_results/exp_ga_old.csv +0 -0
- offline_results/exp_gb.csv +0 -0
- offline_results/exp_gb_old.csv +0 -0
app.py
CHANGED
@@ -14,6 +14,12 @@ QUESTIONS = [
|
|
14 |
"Intervention 1",
|
15 |
"Intervention 2",
|
16 |
"Genetic Chain",
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
]
|
18 |
|
19 |
with gr.Blocks(theme="dark") as demo:
|
@@ -23,31 +29,40 @@ with gr.Blocks(theme="dark") as demo:
|
|
23 |
<center> <h4> Please follow the Instruction <a href="https://huggingface.co/spaces/oliverwang15/DAN_AI/blob/main/README.md">HERE</a> </h4> </center>')
|
24 |
|
25 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
26 |
with gr.Row():
|
27 |
-
|
28 |
-
# Update
|
29 |
with gr.Group():
|
30 |
-
gr.Markdown(f'<center><
|
31 |
-
gr.Markdown(f'<center><p>Please First Upload the File</p></center>')
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
-
file = gr.File(label='Upload your .txt or .pdf file here', file_types=['.txt', '.pdf'], file_count = 'multiple')
|
42 |
-
btn_submit_txt_online = gr.Button(value='Submit')
|
43 |
-
# btn_submit_txt.style(full_width=True)
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
answer_type = gr.Radio(choices = ["ChatGPT_txt", "GPT4_txt", 'New_GPT_4_pdf', 'Exp_training', 'Exp_Group_A', 'Exp_Group_B'], label="Answer_type", info="Please select the type of answer you want to show")
|
49 |
-
btn_submit_txt_offline = gr.Button(value='Show Answers')
|
50 |
-
# btn_submit_txt.style(full_width=True)
|
51 |
|
52 |
# Output
|
53 |
with gr.Group():
|
|
|
14 |
"Intervention 1",
|
15 |
"Intervention 2",
|
16 |
"Genetic Chain",
|
17 |
+
"Issues or Challenge Resolved",
|
18 |
+
"Innovations in Methodology",
|
19 |
+
"Impact of Findings",
|
20 |
+
"limitations",
|
21 |
+
"Potential Applications",
|
22 |
+
|
23 |
]
|
24 |
|
25 |
with gr.Blocks(theme="dark") as demo:
|
|
|
29 |
<center> <h4> Please follow the Instruction <a href="https://huggingface.co/spaces/oliverwang15/DAN_AI/blob/main/README.md">HERE</a> </h4> </center>')
|
30 |
|
31 |
with gr.Row():
|
32 |
+
# Update
|
33 |
+
# with gr.Group():
|
34 |
+
# gr.Markdown(f'<center><h1>Input</h1></center>')
|
35 |
+
|
36 |
+
|
37 |
with gr.Row():
|
38 |
+
# Online
|
|
|
39 |
with gr.Group():
|
40 |
+
gr.Markdown(f'<center><h2>Request Online</h2></center>')
|
41 |
+
# gr.Markdown(f'<center><p>Please First Upload the File</p></center>')
|
42 |
+
with gr.Row():
|
43 |
+
with gr.Group():
|
44 |
+
openai_key = gr.Textbox(
|
45 |
+
label='Enter your OpenAI API key here',
|
46 |
+
type='password')
|
47 |
+
with gr.Group():
|
48 |
+
model_selection = gr.Radio(choices = ["ChatGPT", "GPT4"], label="Model Selection", info="Please select the model you want to use")
|
49 |
+
|
50 |
+
file = gr.File(label='Upload your .txt or .pdf file here', file_types=['.txt', '.pdf'], file_count = 'multiple')
|
51 |
+
btn_submit_txt_online = gr.Button(value='Submit')
|
52 |
+
# btn_submit_txt.style(full_width=True)
|
53 |
+
|
54 |
+
# Offline
|
55 |
+
with gr.Group():
|
56 |
+
gr.Markdown(f'<center><h2>Or Load Offline</h2></center>')
|
57 |
+
questions = gr.CheckboxGroup(choices = QUESTIONS, value = QUESTIONS[:6], label="Questions (Please don't change this part now)", info="Please select the question you want to ask")
|
58 |
+
answer_type = gr.Radio(choices = ["ChatGPT_txt", "GPT4_txt", 'New_GPT_4_pdf', 'Exp_training', 'Exp_Group_A', 'Exp_Group_B'], label="Answer_type", info="Please select the type of answer you want to show")
|
59 |
+
btn_submit_txt_offline = gr.Button(value='Show Answers')
|
60 |
+
# btn_submit_txt.style(full_width=True)
|
61 |
|
|
|
|
|
|
|
62 |
|
63 |
+
with gr.Row():
|
64 |
+
with gr.Row():
|
65 |
+
|
|
|
|
|
|
|
66 |
|
67 |
# Output
|
68 |
with gr.Group():
|
backend.py
CHANGED
@@ -8,6 +8,34 @@ import pandas as pd
|
|
8 |
import os,json
|
9 |
import time
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
class Backend:
|
12 |
def __init__(self):
|
13 |
self.agent = OpenAI()
|
@@ -184,7 +212,8 @@ class Backend:
|
|
184 |
# self.current_question -= 1
|
185 |
return "No more questions!", "No more questions!", "No more questions!", "No more questions!", "No more questions!", 'No more questions!', 'No more questions!', 'Still need to click the button above to save the results', None, None
|
186 |
else:
|
187 |
-
res = self.gpt_result[f'Question {self.current_question + 1}']
|
|
|
188 |
question = self.questions[self.current_question]
|
189 |
self.answer = res['answer']
|
190 |
self.highlighted_out = res['original sentences']
|
@@ -208,7 +237,8 @@ class Backend:
|
|
208 |
# self.current_question += 1
|
209 |
return "No more questions!", "No more questions!", "No more questions!", "No more questions!", "No more questions!", 'No more questions!', 'No more questions!', 'Still need to click the button above to save the results', None, None
|
210 |
else:
|
211 |
-
res = self.gpt_result[f'Question {self.current_question + 1}']
|
|
|
212 |
question = self.questions[self.current_question]
|
213 |
self.answer = res['answer']
|
214 |
self.highlighted_out = res['original sentences']
|
@@ -318,43 +348,96 @@ class Backend:
|
|
318 |
else:
|
319 |
return "No answer yet, you need to submit the document first"
|
320 |
|
321 |
-
def phase_df(self, df):
|
322 |
df = json.loads(df.T.to_json())
|
323 |
res_list = []
|
324 |
for key, item in df.items():
|
325 |
tmp_res_list = {}
|
326 |
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
357 |
res_list.append(tmp_res_list)
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
return res_list
|
359 |
|
360 |
def process_file_offline(self, questions, answer_type, progress = gr.Progress()):
|
@@ -377,7 +460,7 @@ class Backend:
|
|
377 |
df = pd.read_csv('./offline_results/exp_gb.csv')
|
378 |
|
379 |
# make the prompt
|
380 |
-
self.res_list = self.phase_df(df)
|
381 |
|
382 |
if answer_type in ['ChatGPT_txt', 'GPT4_txt', 'New_GPT_4_pdf']:
|
383 |
if answer_type == 'ChatGPT_txt' or answer_type == 'GPT4_txt':
|
@@ -403,6 +486,8 @@ class Backend:
|
|
403 |
|
404 |
elif answer_type in ['Exp_training', 'Exp_Group_A', 'Exp_Group_B']:
|
405 |
self.filename_list = df['fn'].tolist()
|
|
|
|
|
406 |
self.text_list = df['content'].tolist()
|
407 |
|
408 |
|
|
|
8 |
import os,json
|
9 |
import time
|
10 |
|
11 |
+
QUESTION_DICT = {
|
12 |
+
"Question 1": "Animal Type",
|
13 |
+
"Question 2": "Exposure Age",
|
14 |
+
"Question 3": "Behavior Test",
|
15 |
+
"intervention_1": "Intervention 1",
|
16 |
+
"intervention_2": "Intervention 2",
|
17 |
+
"Question 5": "Genetic Chain",
|
18 |
+
"Question 6": "Issues or Challenge Resolved",
|
19 |
+
"Question 7": "Innovations in Methodology",
|
20 |
+
"Question 8": "Impact of Findings",
|
21 |
+
"Question 9": "limitations",
|
22 |
+
"Question 10": "Potential Applications",
|
23 |
+
}
|
24 |
+
|
25 |
+
REVERSE_QUESTION_DICT = {
|
26 |
+
"Animal Type": "Question 1",
|
27 |
+
"Exposure Age": "Question 2",
|
28 |
+
"Behavior Test": "Question 3",
|
29 |
+
"Intervention 1": "Question 4",
|
30 |
+
"Intervention 2": "Question 5",
|
31 |
+
"Genetic Chain": "Question 6",
|
32 |
+
"Issues or Challenge Resolved": "Question 7",
|
33 |
+
"Innovations in Methodology": "Question 8",
|
34 |
+
"Impact of Findings": "Question 9",
|
35 |
+
"limitations": "Question 10",
|
36 |
+
"Potential Applications": "Question 11",
|
37 |
+
}
|
38 |
+
|
39 |
class Backend:
|
40 |
def __init__(self):
|
41 |
self.agent = OpenAI()
|
|
|
212 |
# self.current_question -= 1
|
213 |
return "No more questions!", "No more questions!", "No more questions!", "No more questions!", "No more questions!", 'No more questions!', 'No more questions!', 'Still need to click the button above to save the results', None, None
|
214 |
else:
|
215 |
+
# res = self.gpt_result[f'Question {self.current_question + 1}']
|
216 |
+
res = self.gpt_result[list(self.gpt_result.keys())[self.current_question]]
|
217 |
question = self.questions[self.current_question]
|
218 |
self.answer = res['answer']
|
219 |
self.highlighted_out = res['original sentences']
|
|
|
237 |
# self.current_question += 1
|
238 |
return "No more questions!", "No more questions!", "No more questions!", "No more questions!", "No more questions!", 'No more questions!', 'No more questions!', 'Still need to click the button above to save the results', None, None
|
239 |
else:
|
240 |
+
# res = self.gpt_result[f'Question {self.current_question + 1}']
|
241 |
+
res = self.gpt_result[list(self.gpt_result.keys())[self.current_question]]
|
242 |
question = self.questions[self.current_question]
|
243 |
self.answer = res['answer']
|
244 |
self.highlighted_out = res['original sentences']
|
|
|
348 |
else:
|
349 |
return "No answer yet, you need to submit the document first"
|
350 |
|
351 |
+
def phase_df(self, df, questions):
|
352 |
df = json.loads(df.T.to_json())
|
353 |
res_list = []
|
354 |
for key, item in df.items():
|
355 |
tmp_res_list = {}
|
356 |
|
357 |
+
if 'Question 1' in item and "Animal Type" in questions:
|
358 |
+
tep_res_list_q1 = {
|
359 |
+
'answer': item['Question 1'],
|
360 |
+
'original sentences': eval(item['Question 1_original_sentences']),
|
361 |
+
}
|
362 |
+
tmp_res_list['Question 1'] = tep_res_list_q1
|
363 |
+
|
364 |
+
if 'Question 2' in item and 'Exposure Age' in questions:
|
365 |
+
tep_res_list_q2 = {
|
366 |
+
'answer': item['Question 2'],
|
367 |
+
'original sentences': eval(item['Question 2_original_sentences']),
|
368 |
+
}
|
369 |
+
tmp_res_list['Question 2'] = tep_res_list_q2
|
370 |
+
|
371 |
+
if 'Question 3' in item and 'Behavior Test' in questions:
|
372 |
+
tep_res_list_q3 = {
|
373 |
+
'answer': item['Question 3'],
|
374 |
+
'original sentences': eval(item['Question 3_original_sentences']),
|
375 |
+
}
|
376 |
+
tmp_res_list['Question 3'] = tep_res_list_q3
|
377 |
+
|
378 |
+
if 'intervention_1' in item and "Intervention 1" in questions:
|
379 |
+
tep_res_list_q4 = {
|
380 |
+
'answer': item['intervention_1'],
|
381 |
+
'original sentences': eval(item['Question 4intervention_1_original_sentences']),
|
382 |
+
}
|
383 |
+
tmp_res_list['Question 4'] = tep_res_list_q4
|
384 |
+
|
385 |
+
if 'intervention_2' in item and "Intervention 2" in questions:
|
386 |
+
tep_res_list_q5 = {
|
387 |
+
'answer': item['intervention_2'],
|
388 |
+
'original sentences': eval(item['Question 4intervention_2_original_sentences']),
|
389 |
+
}
|
390 |
+
tmp_res_list['Question 5'] = tep_res_list_q5
|
391 |
+
|
392 |
+
if 'Question 5' in item and "Genetic Chain" in questions:
|
393 |
+
tep_res_list_q6 = {
|
394 |
+
'answer': item['Question 5'],
|
395 |
+
'original sentences': eval(item['Question 5_original_sentences']),
|
396 |
+
}
|
397 |
+
tmp_res_list['Question 6'] = tep_res_list_q6
|
398 |
+
|
399 |
+
if 'Question 6' in item and "Issues or Challenge Resolved" in questions:
|
400 |
+
tep_res_list_q7 = {
|
401 |
+
'answer': item['Question 6'],
|
402 |
+
'original sentences': eval(item['Question 6_original_sentences']),
|
403 |
+
}
|
404 |
+
tmp_res_list['Question 7'] = tep_res_list_q7
|
405 |
+
|
406 |
+
if 'Question 7' in item and "Innovations in Methodology" in questions:
|
407 |
+
tep_res_list_q8 = {
|
408 |
+
'answer': item['Question 7'],
|
409 |
+
'original sentences': eval(item['Question 7_original_sentences']),
|
410 |
+
}
|
411 |
+
tmp_res_list['Question 8'] = tep_res_list_q8
|
412 |
+
|
413 |
+
if 'Question 8' in item and "Impact of Findings" in questions:
|
414 |
+
tep_res_list_q9 = {
|
415 |
+
'answer': item['Question 8'],
|
416 |
+
'original sentences': eval(item['Question 8_original_sentences']),
|
417 |
+
}
|
418 |
+
tmp_res_list['Question 9'] = tep_res_list_q9
|
419 |
+
|
420 |
+
if 'Question 9' in item and "limitations" in questions:
|
421 |
+
tep_res_list_q10 = {
|
422 |
+
'answer': item['Question 9'],
|
423 |
+
'original sentences': eval(item['Question 9_original_sentences']),
|
424 |
+
}
|
425 |
+
tmp_res_list['Question 10'] = tep_res_list_q10
|
426 |
+
|
427 |
+
if 'Question 10' in item and "Potential Applications" in questions:
|
428 |
+
tep_res_list_q11 = {
|
429 |
+
'answer': item['Question 10'],
|
430 |
+
'original sentences': eval(item['Question 10_original_sentences']),
|
431 |
+
}
|
432 |
+
tmp_res_list['Question 11'] = tep_res_list_q11
|
433 |
+
|
434 |
res_list.append(tmp_res_list)
|
435 |
+
|
436 |
+
# checking
|
437 |
+
for i in questions:
|
438 |
+
if REVERSE_QUESTION_DICT[i] not in tmp_res_list:
|
439 |
+
raise gr.Error(f"Question {i} is not in the answer list, Please don't select it!")
|
440 |
+
|
441 |
return res_list
|
442 |
|
443 |
def process_file_offline(self, questions, answer_type, progress = gr.Progress()):
|
|
|
460 |
df = pd.read_csv('./offline_results/exp_gb.csv')
|
461 |
|
462 |
# make the prompt
|
463 |
+
self.res_list = self.phase_df(df, questions)
|
464 |
|
465 |
if answer_type in ['ChatGPT_txt', 'GPT4_txt', 'New_GPT_4_pdf']:
|
466 |
if answer_type == 'ChatGPT_txt' or answer_type == 'GPT4_txt':
|
|
|
486 |
|
487 |
elif answer_type in ['Exp_training', 'Exp_Group_A', 'Exp_Group_B']:
|
488 |
self.filename_list = df['fn'].tolist()
|
489 |
+
if "Passage" not in self.filename_list[0]:
|
490 |
+
self.filename_list = [f"[ Passage {i + 1}/{len(self.filename_list)} ] {self.filename_list[i]}" for i in range(len(self.filename_list))]
|
491 |
self.text_list = df['content'].tolist()
|
492 |
|
493 |
|
offline_results/exp_ga.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
offline_results/exp_ga_old.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
offline_results/exp_gb.csv
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
offline_results/exp_gb_old.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|