DAN_AI / app.py
oliverwang15's picture
updates on the new prompt and better features
35c1e05
raw
history blame
5.58 kB
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)