Spaces:
Sleeping
Sleeping
File size: 5,578 Bytes
478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d f079b05 478965d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
import warnings
warnings.filterwarnings("ignore")
import os, json
import gradio as gr
import pandas as pd
from backend import Backend
QUESTIONS = [
"Animal Type",
"Exposure Age",
"Behavior Test",
"Intervention 1",
"Intervention 2",
"Genetic Chain",
]
with gr.Blocks(theme="dark") as demo:
backend = Backend()
with gr.Row():
with gr.Row():
# Update
with gr.Group():
gr.Markdown(f'<center><h1>Input</h1></center>')
gr.Markdown(f'<center><p>Please First Upload the File</p></center>')
openai_key = gr.Textbox(
label='Enter your OpenAI API key here',
type='password')
file = gr.File(label='Upload your .txt file here', file_types=['.txt'])
questions = gr.CheckboxGroup(choices = QUESTIONS, value = QUESTIONS, label="Questions", info="Please select the question you want to ask")
btn_submit_txt = gr.Button(value='Submit txt')
btn_submit_txt.style(full_width=True)
# Output
with gr.Group():
gr.Markdown(f'<center><h1>Output</h1></center>')
gr.Markdown(f'<center><p>The answer to your question is :</p></center>')
question_box = gr.Textbox(label='Question')
answer_box = gr.Textbox(label='Answer')
reference_box = gr.Textbox(label='Reference')
highlighted_text = gr.outputs.HTML(label="Highlighted Text")
with gr.Row():
btn_last_question = gr.Button(value='Last Question')
btn_next_question = gr.Button(value='Next Question')
# Correctness
with gr.Group():
gr.Markdown(f'<center><h1>Correct the Result</h1></center>')
gr.Markdown(f'<center><p>Please Correct the Results</p></center>')
with gr.Row():
save_results = gr.Textbox(placeholder = "Still need to click the button above to save the results", label = 'Save Results')
with gr.Group():
gr.Markdown(f'<center><p>Please Choose: </p></center>')
answer_correct = gr.Radio(choices = ["Correct", "Incorrect"], label='Is the Generated Answer Correct?', info="Pease select whether the generated text is correct")
correct_answer = gr.Textbox(placeholder = "Please judge on the generated answer", label = 'Correct Answer', interactive = True)
reference_correct = gr.Radio(choices = ["Correct", "Incorrect"], label="Is the Reference Correct?", info="Pease select whether the reference is correct")
correct_reference = gr.Textbox(placeholder = "Please judge on the generated answer", label = 'Correct Reference', interactive = True)
btn_submit_correctness = gr.Button(value='Submit Correctness')
btn_submit_correctness.style(full_width=True)
# Download
with gr.Group():
gr.Markdown(f'<center><h1>Download</h1></center>')
gr.Markdown(f'<center><p>Download the processed data and corrected data</p></center>')
answer_file = gr.File(label='Download processed data', file_types=['.xlsx'])
btn_download_answer = gr.Button(value='Download processed data')
btn_download_answer.style(full_width=True)
corrected_file = gr.File(label='Download corrected data', file_types=['.xlsx'])
btn_download_corrected = gr.Button(value='Download corrected data')
btn_download_corrected.style(full_width=True)
with gr.Row():
reset = gr.Button(value='Reset')
reset.style(full_width=True)
# Answer change
answer_correct.input(
backend.change_correct_answer,
inputs = [answer_correct],
outputs = [correct_answer],
)
reference_correct.input(
backend.change_correct_reference,
inputs = [reference_correct],
outputs = [correct_reference],
)
# Submit button
btn_submit_txt.click(
backend.process_file,
inputs=[file, questions, openai_key],
outputs=[question_box, answer_box, reference_box, highlighted_text, correct_answer, correct_reference],
)
btn_submit_correctness.click( # TODO
backend.process_results,
inputs=[answer_correct, correct_answer, reference_correct, correct_reference],
outputs=[save_results],
)
# Switch question button
btn_last_question.click(
backend.process_last,
outputs=[question_box, answer_box, reference_box, highlighted_text, correct_answer, correct_reference, save_results, answer_correct, reference_correct],
)
btn_next_question.click(
backend.process_next,
outputs=[question_box, answer_box, reference_box, highlighted_text, correct_answer, correct_reference, save_results, answer_correct, reference_correct],
)
# Download button
btn_download_answer.click(
backend.download_answer,
outputs=[answer_file],
)
btn_download_corrected.click(
backend.download_corrected,
outputs=[corrected_file],
)
demo.queue()
demo.launch(show_error=True, show_tips=True) |