Spaces:
Sleeping
Sleeping
jeremierostan
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -94,7 +94,8 @@ def handle_pdf_upload(pdf_file):
|
|
94 |
# Return the generated questions for display to the user
|
95 |
return questions
|
96 |
|
97 |
-
|
|
|
98 |
# Extract the paper text for validation
|
99 |
pdf_file_path = pdf_file.name
|
100 |
paper_text = extract_text_from_pdf(pdf_file_path)
|
@@ -105,6 +106,8 @@ def handle_answer_submission(pdf_file, student_code, answers):
|
|
105 |
# Loop over each question-answer pair and validate
|
106 |
questions = generate_questions(paper_text)
|
107 |
verification_status = "Confirmed"
|
|
|
|
|
108 |
for i in range(len(questions)):
|
109 |
validation_result = validate_answer(paper_text, questions[i], answers[i])
|
110 |
answers_summary += f"Question {i+1}: {questions[i]}\nAnswer: {answers[i]}\nValidation: {validation_result}\n\n"
|
@@ -121,7 +124,7 @@ with gr.Blocks() as app:
|
|
121 |
with gr.Row():
|
122 |
# Add an image logo at the top left corner, centered
|
123 |
logo_url = "https://i.ibb.co/S7DCk3K/a-logo-design-with-a-stylized-egyptian-scribe-the-i-L59-Gh-Zn-QASp7v-TUazjdp-A-1-s-Ip-Qq-VRIif-VF5dn.png" # Replace with your actual logo URL
|
124 |
-
gr.Image(logo_url, label="", show_label=False, height=
|
125 |
|
126 |
# PDF Upload Section
|
127 |
pdf_file = gr.File(label="Upload PDF Paper")
|
@@ -147,7 +150,15 @@ with gr.Blocks() as app:
|
|
147 |
# Layout: Upload button right under the file upload, followed by Q/A section
|
148 |
upload_btn.click(fn=handle_pdf_upload, inputs=pdf_file, outputs=[question1, question2, question3, question4])
|
149 |
submit_btn = gr.Button("Submit Answers")
|
|
|
150 |
submit_btn.click(fn=handle_answer_submission, inputs=[pdf_file, student_code, answer1, answer2, answer3, answer4], outputs=output)
|
151 |
|
152 |
# Launch the app
|
153 |
-
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
# Return the generated questions for display to the user
|
95 |
return questions
|
96 |
|
97 |
+
# Update the handle_answer_submission to accept each answer separately
|
98 |
+
def handle_answer_submission(pdf_file, student_code, answer1, answer2, answer3, answer4):
|
99 |
# Extract the paper text for validation
|
100 |
pdf_file_path = pdf_file.name
|
101 |
paper_text = extract_text_from_pdf(pdf_file_path)
|
|
|
106 |
# Loop over each question-answer pair and validate
|
107 |
questions = generate_questions(paper_text)
|
108 |
verification_status = "Confirmed"
|
109 |
+
answers = [answer1, answer2, answer3, answer4]
|
110 |
+
|
111 |
for i in range(len(questions)):
|
112 |
validation_result = validate_answer(paper_text, questions[i], answers[i])
|
113 |
answers_summary += f"Question {i+1}: {questions[i]}\nAnswer: {answers[i]}\nValidation: {validation_result}\n\n"
|
|
|
124 |
with gr.Row():
|
125 |
# Add an image logo at the top left corner, centered
|
126 |
logo_url = "https://i.ibb.co/S7DCk3K/a-logo-design-with-a-stylized-egyptian-scribe-the-i-L59-Gh-Zn-QASp7v-TUazjdp-A-1-s-Ip-Qq-VRIif-VF5dn.png" # Replace with your actual logo URL
|
127 |
+
gr.Image(logo_url, label="", show_label=False, height=200)
|
128 |
|
129 |
# PDF Upload Section
|
130 |
pdf_file = gr.File(label="Upload PDF Paper")
|
|
|
150 |
# Layout: Upload button right under the file upload, followed by Q/A section
|
151 |
upload_btn.click(fn=handle_pdf_upload, inputs=pdf_file, outputs=[question1, question2, question3, question4])
|
152 |
submit_btn = gr.Button("Submit Answers")
|
153 |
+
# Now passing answers individually
|
154 |
submit_btn.click(fn=handle_answer_submission, inputs=[pdf_file, student_code, answer1, answer2, answer3, answer4], outputs=output)
|
155 |
|
156 |
# Launch the app
|
157 |
+
app.launch()
|
158 |
+
|
159 |
+
<a href="https://groq.com" target="_blank" rel="noopener noreferrer">
|
160 |
+
<img
|
161 |
+
src="https://groq.com/wp-content/uploads/2024/03/PBG-mark1-color.svg"
|
162 |
+
alt="Powered by Groq for fast inference."
|
163 |
+
/>
|
164 |
+
</a>
|