Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,7 +28,7 @@ INPUT: This file is a PDF that first contains the Question Paper and immediately
|
|
| 28 |
TASK:
|
| 29 |
1. Transcribe EXACTLY all the questions FIRST (with their total marks).
|
| 30 |
2. After ALL questions, transcribe the Markscheme exactly, preserving M/A/R notation in brackets.
|
| 31 |
-
3. Always number the questions sequentially (Question 1, Question 2, Question
|
| 32 |
4. After the markscheme, DETECT and FLAG all questions in the markscheme where a graph/diagram is expected. For each, output the question number and the page number in the format below.
|
| 33 |
FORMAT:
|
| 34 |
==== PAPER TOTAL MARKS ====
|
|
@@ -177,14 +177,31 @@ def merge_pdfs(paths, output_path):
|
|
| 177 |
|
| 178 |
def gemini_generate_content(model, prompt_text, file_upload_obj=None, image_obj=None):
|
| 179 |
"""
|
| 180 |
-
Send prompt_text and optionally an uploaded file (or an image object) to the model.
|
| 181 |
Returns textual response and prints progress.
|
| 182 |
"""
|
| 183 |
inputs = [prompt_text]
|
| 184 |
if file_upload_obj:
|
| 185 |
inputs.append(file_upload_obj)
|
| 186 |
if image_obj:
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
print("📡 Sending request to Gemini (prompt length:", len(prompt_text), "chars )")
|
| 189 |
response = model.generate_content(inputs)
|
| 190 |
raw_text = getattr(response, "text", None)
|
|
|
|
| 28 |
TASK:
|
| 29 |
1. Transcribe EXACTLY all the questions FIRST (with their total marks).
|
| 30 |
2. After ALL questions, transcribe the Markscheme exactly, preserving M/A/R notation in brackets.
|
| 31 |
+
3. Always number the questions sequentially (Question 1, Question 2, Question 3, …) **in the order they appear in the PDF**, even if the PDF shows a different number or leaves it blank. Do NOT skip or leave Question: blank. Never start a question other than question 1 ( even if it is labelled in pdf as 8 name it 1)
|
| 32 |
4. After the markscheme, DETECT and FLAG all questions in the markscheme where a graph/diagram is expected. For each, output the question number and the page number in the format below.
|
| 33 |
FORMAT:
|
| 34 |
==== PAPER TOTAL MARKS ====
|
|
|
|
| 177 |
|
| 178 |
def gemini_generate_content(model, prompt_text, file_upload_obj=None, image_obj=None):
|
| 179 |
"""
|
| 180 |
+
Send prompt_text and optionally an uploaded file (or an image object/list) to the model.
|
| 181 |
Returns textual response and prints progress.
|
| 182 |
"""
|
| 183 |
inputs = [prompt_text]
|
| 184 |
if file_upload_obj:
|
| 185 |
inputs.append(file_upload_obj)
|
| 186 |
if image_obj:
|
| 187 |
+
# Handle both single images and lists of images
|
| 188 |
+
if isinstance(image_obj, list):
|
| 189 |
+
# Convert image paths to PIL Image objects
|
| 190 |
+
for img_path in image_obj:
|
| 191 |
+
if isinstance(img_path, str):
|
| 192 |
+
# It's a file path, load as PIL Image
|
| 193 |
+
pil_img = Image.open(img_path)
|
| 194 |
+
inputs.append(pil_img)
|
| 195 |
+
else:
|
| 196 |
+
# It's already an image object
|
| 197 |
+
inputs.append(img_path)
|
| 198 |
+
else:
|
| 199 |
+
# Single image
|
| 200 |
+
if isinstance(image_obj, str):
|
| 201 |
+
pil_img = Image.open(image_obj)
|
| 202 |
+
inputs.append(pil_img)
|
| 203 |
+
else:
|
| 204 |
+
inputs.append(image_obj)
|
| 205 |
print("📡 Sending request to Gemini (prompt length:", len(prompt_text), "chars )")
|
| 206 |
response = model.generate_content(inputs)
|
| 207 |
raw_text = getattr(response, "text", None)
|