False45 commited on
Commit
24a731d
·
1 Parent(s): 7916855

feat: enforce strict math domain filtering for images and text

Browse files
Files changed (1) hide show
  1. src/services/gemini_service.py +8 -6
src/services/gemini_service.py CHANGED
@@ -210,12 +210,13 @@ class GeminiVisionService:
210
  prompt = (
211
  "You are a math OCR expert. Extract ALL mathematical content from this image.\n\n"
212
  "Rules:\n"
213
- "1. Convert handwritten or printed math into clean text.\n"
214
- "2. Use standard notation: x², √, π, ±, ∫, Σ, etc.\n"
215
- "3. If it's an equation, write it as: equation\n"
216
- "4. If it's a word problem, transcribe it exactly.\n"
217
- "5. If there are multiple problems, number them.\n"
218
- "6. Return ONLY the extracted math — no commentary.\n"
 
219
  )
220
 
221
  config = types.GenerateContentConfig(safety_settings=_get_safety_settings())
@@ -241,6 +242,7 @@ class GeminiVisionService:
241
 
242
  prompt = (
243
  "You are an Indian math teacher. Look at this image.\n\n"
 
244
  "Step 1: Extract the math problem from the image.\n"
245
  "Step 2: Solve it step-by-step in whiteboard style.\n\n"
246
  "Format your response as:\n"
 
210
  prompt = (
211
  "You are a math OCR expert. Extract ALL mathematical content from this image.\n\n"
212
  "Rules:\n"
213
+ "1. If the image does NOT contain any math, physics, or quantitative concepts (e.g., it is a picture of a dog, car, person, or normal text), you MUST reply exactly with: REJECTED: This image does not appear to contain a math problem. Please upload a picture of a math question.\n"
214
+ "2. Convert handwritten or printed math into clean text.\n"
215
+ "3. Use standard notation: x², √, π, ±, ∫, Σ, etc.\n"
216
+ "4. If it's an equation, write it as: equation\n"
217
+ "5. If it's a word problem, transcribe it exactly.\n"
218
+ "6. If there are multiple problems, number them.\n"
219
+ "7. Return ONLY the extracted math — no commentary.\n"
220
  )
221
 
222
  config = types.GenerateContentConfig(safety_settings=_get_safety_settings())
 
242
 
243
  prompt = (
244
  "You are an Indian math teacher. Look at this image.\n\n"
245
+ "IMPORTANT DOMAIN RULE: If the image does NOT contain a math problem, physics problem, or quantitative concept, you MUST ignore the steps below and respond exactly with: REJECTED: This image does not appear to contain a math problem. Please upload a picture of a math question.\n\n"
246
  "Step 1: Extract the math problem from the image.\n"
247
  "Step 2: Solve it step-by-step in whiteboard style.\n\n"
248
  "Format your response as:\n"