atz21 commited on
Commit
f93c15f
Β·
verified Β·
1 Parent(s): 0fb264f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import google.generativeai as genai
3
+
4
+ # πŸ”‘ Hugging Face Spaces Secret will inject API key
5
+ import os
6
+ GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
7
+ genai.configure(api_key=GEMINI_API_KEY)
8
+
9
+ model = genai.GenerativeModel("gemini-2.5-pro", generation_config={"temperature": 0})
10
+
11
+ def transcribe_files(qp_file, ms_file, ans_file):
12
+ uploaded_as = genai.upload_file(path=ans_file.name, display_name="Answer Sheet")
13
+ transcription_instructions = """
14
+ Persona: You are an expert transcriptionist...
15
+ (same rules as before)
16
+ """
17
+ response = model.generate_content([transcription_instructions, uploaded_as])
18
+ transcription = getattr(response, "text", None)
19
+ if not transcription and response.candidates:
20
+ transcription = response.candidates[0].content.parts[0].text
21
+ return transcription or "No transcription generated."
22
+
23
+ def grade_files(qp_file, ms_file, ans_file, transcription):
24
+ uploaded_qp = genai.upload_file(path=qp_file.name, display_name="Question Paper")
25
+ uploaded_ms = genai.upload_file(path=ms_file.name, display_name="Marking Scheme")
26
+ grading_system = "Instructions to Examiners..."
27
+ response = model.generate_content([
28
+ f"You are an examiner. Grade:\n{grading_system}",
29
+ uploaded_qp,
30
+ uploaded_ms,
31
+ transcription
32
+ ])
33
+ grading = getattr(response, "text", None)
34
+ if not grading and response.candidates:
35
+ grading = response.candidates[0].content.parts[0].text
36
+ return grading or "No grading generated."
37
+
38
+ with gr.Blocks() as demo:
39
+ gr.Markdown("## πŸ“˜ Automated Transcription & Grading System")
40
+ with gr.Row():
41
+ qp = gr.File(label="Upload Question Paper (PDF)")
42
+ ms = gr.File(label="Upload Marking Scheme (PDF)")
43
+ ans = gr.File(label="Upload Answer Sheet (PDF)")
44
+ transcribe_btn = gr.Button("πŸ” Transcribe")
45
+ transcription_output = gr.Textbox(label="Transcription", lines=20)
46
+ grade_btn = gr.Button("βœ… Grade")
47
+ grading_output = gr.Textbox(label="Grading Result", lines=20)
48
+
49
+ transcribe_btn.click(fn=transcribe_files, inputs=[qp, ms, ans], outputs=transcription_output)
50
+ grade_btn.click(fn=grade_files, inputs=[qp, ms, ans, transcription_output], outputs=grading_output)
51
+
52
+ demo.launch()