Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,7 +60,7 @@ print("✅ Standard OCR model loaded.")
|
|
| 60 |
# --- Phase 1: Text Extraction ---
|
| 61 |
def classify_image_with_gemini(image: Image.Image):
|
| 62 |
"""Uses Gemini to classify an image as a 'document' or 'diagram'."""
|
| 63 |
-
model = genai.GenerativeModel('gemini-
|
| 64 |
prompt = "Is this image primarily a text document or an engineering/technical diagram? Answer with only 'document' or 'diagram'."
|
| 65 |
response = model.generate_content([prompt, image])
|
| 66 |
classification = response.text.strip().lower()
|
|
@@ -69,7 +69,7 @@ def classify_image_with_gemini(image: Image.Image):
|
|
| 69 |
|
| 70 |
def summarize_diagram_with_gemini(image: Image.Image):
|
| 71 |
"""Uses Gemini to generate a summary of an engineering diagram."""
|
| 72 |
-
model = genai.GenerativeModel('gemini-
|
| 73 |
prompt = "You are an engineering assistant for Kochi Metro Rail Limited (KMRL). Describe the contents of this technical diagram or engineering drawing in a concise summary. Identify key components and their apparent purpose."
|
| 74 |
response = model.generate_content([prompt, image])
|
| 75 |
print("✅ Diagram summary successful.")
|
|
@@ -125,7 +125,7 @@ def translate_chunk(chunk):
|
|
| 125 |
# --- Phase 3: Gemini Analysis ---
|
| 126 |
def generate_structured_json(text_to_analyze):
|
| 127 |
"""Generates the detailed JSON analysis."""
|
| 128 |
-
model = genai.GenerativeModel('gemini-
|
| 129 |
prompt = f"You are an AI assistant for KMRL. Analyze this document and extract key info as JSON: {text_to_analyze}"
|
| 130 |
json_schema = {"type": "OBJECT", "properties": {"summary": {"type": "STRING"}, "actions_required": {"type": "ARRAY", "items": {"type": "OBJECT", "properties": {"action": {"type": "STRING"}, "priority": {"type": "STRING", "enum": ["High", "Medium", "Low"]}, "deadline": {"type": "STRING"}, "notes": {"type": "STRING"}}, "required": ["action", "priority", "deadline", "notes"]}}, "departments_to_notify": {"type": "ARRAY", "items": {"type": "STRING"}}, "cross_document_flags": {"type": "ARRAY", "items": {"type": "OBJECT", "properties": {"related_document_type": {"type": "STRING"}, "related_issue": {"type": "STRING"}}, "required": ["related_document_type", "related_issue"]}}}, "required": ["summary", "actions_required", "departments_to_notify", "cross_document_flags"]}
|
| 131 |
generation_config = genai.types.GenerationConfig(response_mime_type="application/json", response_schema=json_schema)
|
|
|
|
| 60 |
# --- Phase 1: Text Extraction ---
|
| 61 |
def classify_image_with_gemini(image: Image.Image):
|
| 62 |
"""Uses Gemini to classify an image as a 'document' or 'diagram'."""
|
| 63 |
+
model = genai.GenerativeModel('gemini-2.5-flash')
|
| 64 |
prompt = "Is this image primarily a text document or an engineering/technical diagram? Answer with only 'document' or 'diagram'."
|
| 65 |
response = model.generate_content([prompt, image])
|
| 66 |
classification = response.text.strip().lower()
|
|
|
|
| 69 |
|
| 70 |
def summarize_diagram_with_gemini(image: Image.Image):
|
| 71 |
"""Uses Gemini to generate a summary of an engineering diagram."""
|
| 72 |
+
model = genai.GenerativeModel('gemini-2.5-flash')
|
| 73 |
prompt = "You are an engineering assistant for Kochi Metro Rail Limited (KMRL). Describe the contents of this technical diagram or engineering drawing in a concise summary. Identify key components and their apparent purpose."
|
| 74 |
response = model.generate_content([prompt, image])
|
| 75 |
print("✅ Diagram summary successful.")
|
|
|
|
| 125 |
# --- Phase 3: Gemini Analysis ---
|
| 126 |
def generate_structured_json(text_to_analyze):
|
| 127 |
"""Generates the detailed JSON analysis."""
|
| 128 |
+
model = genai.GenerativeModel('gemini-2.5-flash')
|
| 129 |
prompt = f"You are an AI assistant for KMRL. Analyze this document and extract key info as JSON: {text_to_analyze}"
|
| 130 |
json_schema = {"type": "OBJECT", "properties": {"summary": {"type": "STRING"}, "actions_required": {"type": "ARRAY", "items": {"type": "OBJECT", "properties": {"action": {"type": "STRING"}, "priority": {"type": "STRING", "enum": ["High", "Medium", "Low"]}, "deadline": {"type": "STRING"}, "notes": {"type": "STRING"}}, "required": ["action", "priority", "deadline", "notes"]}}, "departments_to_notify": {"type": "ARRAY", "items": {"type": "STRING"}}, "cross_document_flags": {"type": "ARRAY", "items": {"type": "OBJECT", "properties": {"related_document_type": {"type": "STRING"}, "related_issue": {"type": "STRING"}}, "required": ["related_document_type", "related_issue"]}}}, "required": ["summary", "actions_required", "departments_to_notify", "cross_document_flags"]}
|
| 131 |
generation_config = genai.types.GenerationConfig(response_mime_type="application/json", response_schema=json_schema)
|