Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,45 +34,44 @@ Rules:
|
|
| 34 |
6. Do not give marks outside the markscheme.
|
| 35 |
Output must be a structured grading report with reasoning.
|
| 36 |
"""
|
| 37 |
-
|
| 38 |
-
# ---------- CORE FUNCTION ----------
|
| 39 |
def grade_student(qp_file, ms_file, ans_file):
|
| 40 |
try:
|
| 41 |
-
#
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
# Step 1: Transcription
|
| 47 |
model = genai.GenerativeModel("gemini-2.5-pro", generation_config={"temperature": 0})
|
|
|
|
| 48 |
transcription_resp = model.generate_content([TRANSCRIPTION_PROMPT, ans_uploaded])
|
| 49 |
transcription = getattr(transcription_resp, "text", None) or transcription_resp.candidates[0].content.parts[0].text
|
| 50 |
|
| 51 |
-
# Step 2: Grading
|
| 52 |
grading_resp = model.generate_content([GRADING_PROMPT, qp_uploaded, ms_uploaded, transcription])
|
| 53 |
grading = getattr(grading_resp, "text", None) or grading_resp.candidates[0].content.parts[0].text
|
| 54 |
|
| 55 |
return transcription, grading
|
| 56 |
-
|
| 57 |
except Exception as e:
|
| 58 |
-
return "❌ Error during processing:
|
| 59 |
-
|
| 60 |
|
| 61 |
-
# ---------- GRADIO UI ----------
|
| 62 |
demo = gr.Interface(
|
| 63 |
fn=grade_student,
|
| 64 |
inputs=[
|
| 65 |
-
gr.File(label="Upload Question Paper (PDF)", type="
|
| 66 |
-
gr.File(label="Upload Mark Scheme (PDF)", type="
|
| 67 |
-
gr.File(label="Upload Student Answer Sheet (PDF)", type="
|
| 68 |
],
|
| 69 |
outputs=[
|
| 70 |
gr.Markdown(label="Student Transcription"),
|
| 71 |
gr.Textbox(label="Grading Report")
|
| 72 |
],
|
| 73 |
title="📘 AI Teacher Assistant",
|
| 74 |
-
description="Upload a Question Paper, Mark Scheme, and Student Answer Sheet. The app transcribes
|
| 75 |
)
|
| 76 |
|
| 77 |
if __name__ == "__main__":
|
| 78 |
-
demo.launch()
|
|
|
|
| 34 |
6. Do not give marks outside the markscheme.
|
| 35 |
Output must be a structured grading report with reasoning.
|
| 36 |
"""
|
|
|
|
|
|
|
| 37 |
def grade_student(qp_file, ms_file, ans_file):
|
| 38 |
try:
|
| 39 |
+
# Get file paths
|
| 40 |
+
qp_path = qp_file.name
|
| 41 |
+
ms_path = ms_file.name
|
| 42 |
+
ans_path = ans_file.name
|
| 43 |
+
|
| 44 |
+
# Upload to Gemini
|
| 45 |
+
qp_uploaded = genai.upload_file(path=qp_path, display_name="Question Paper")
|
| 46 |
+
ms_uploaded = genai.upload_file(path=ms_path, display_name="Marking Scheme")
|
| 47 |
+
ans_uploaded = genai.upload_file(path=ans_path, display_name="Answer Sheet")
|
| 48 |
|
|
|
|
| 49 |
model = genai.GenerativeModel("gemini-2.5-pro", generation_config={"temperature": 0})
|
| 50 |
+
|
| 51 |
transcription_resp = model.generate_content([TRANSCRIPTION_PROMPT, ans_uploaded])
|
| 52 |
transcription = getattr(transcription_resp, "text", None) or transcription_resp.candidates[0].content.parts[0].text
|
| 53 |
|
|
|
|
| 54 |
grading_resp = model.generate_content([GRADING_PROMPT, qp_uploaded, ms_uploaded, transcription])
|
| 55 |
grading = getattr(grading_resp, "text", None) or grading_resp.candidates[0].content.parts[0].text
|
| 56 |
|
| 57 |
return transcription, grading
|
|
|
|
| 58 |
except Exception as e:
|
| 59 |
+
return f"❌ Error during processing: {e}", ""
|
|
|
|
| 60 |
|
|
|
|
| 61 |
demo = gr.Interface(
|
| 62 |
fn=grade_student,
|
| 63 |
inputs=[
|
| 64 |
+
gr.File(label="Upload Question Paper (PDF)", type="filepath"),
|
| 65 |
+
gr.File(label="Upload Mark Scheme (PDF)", type="filepath"),
|
| 66 |
+
gr.File(label="Upload Student Answer Sheet (PDF)", type="filepath"),
|
| 67 |
],
|
| 68 |
outputs=[
|
| 69 |
gr.Markdown(label="Student Transcription"),
|
| 70 |
gr.Textbox(label="Grading Report")
|
| 71 |
],
|
| 72 |
title="📘 AI Teacher Assistant",
|
| 73 |
+
description="Upload a Question Paper, Mark Scheme, and Student Answer Sheet. The app transcribes and grades answers."
|
| 74 |
)
|
| 75 |
|
| 76 |
if __name__ == "__main__":
|
| 77 |
+
demo.launch()
|