Skip to content

A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.

fix(image_to_structured_data): remove unresolved merge conflict markers

Rudy Celeklif2e896d9294c
diff --git a/OCR/image_to_structured_data/.env.example b/OCR/image_to_structured_data/.env.example
index bcb47db..95109a5 100644
--- a/OCR/image_to_structured_data/.env.example
+++ b/OCR/image_to_structured_data/.env.example
@@ -1,6 +1,3 @@
-<<<<<<< HEAD
-=======
# Mistral API key used for visual extraction with Mistral Large 3.
# Get one free at https://console.mistral.ai
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
MISTRAL_API_KEY=your_mistral_key_here
\ No newline at end of file
diff --git a/OCR/image_to_structured_data/app.py b/OCR/image_to_structured_data/app.py
index 4fb1e5b..fbf0a9c 100644
--- a/OCR/image_to_structured_data/app.py
+++ b/OCR/image_to_structured_data/app.py
@@ -1,11 +1,8 @@
-<<<<<<< HEAD
-=======
"""
Image-to-Structured-Data Extractor Streamlit app: upload an image and extract
validated, structured JSON from it using Mistral Large 3 and Instructor.
"""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
import streamlit as st
from processor import extract_structured_data
from schemas import ProductCollection, InvoiceCollection
@@ -19,13 +16,6 @@ st.set_page_config(page_title="Mistral Vision Extractor", layout="wide")
st.title("📸 Image-to-Structured-Data")
st.write("Using **Mistral Large 3** for high-fidelity visual OCR and structured extraction.")
-<<<<<<< HEAD
-with st.sidebar:
- # Use the MISTRAL_API_KEY from .env if available
- api_key = st.text_input("Mistral API Key", value=os.getenv("MISTRAL_API_KEY", ""), type="password")
- schema_choice = st.selectbox("Select Extraction Schema", ["Product", "Invoice"])
-
-=======
api_key = os.getenv("MISTRAL_API_KEY", "")
with st.sidebar:
@@ -33,7 +23,6 @@ with st.sidebar:
st.warning("MISTRAL_API_KEY is not set in your .env file.")
schema_choice = st.selectbox("Select Extraction Schema", ["Product", "Invoice"])
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
# These names now match the updated import above
schema_map = {
"Product": ProductCollection,
diff --git a/OCR/image_to_structured_data/processor.py b/OCR/image_to_structured_data/processor.py
index 2fb336b..5eaf0bf 100644
--- a/OCR/image_to_structured_data/processor.py
+++ b/OCR/image_to_structured_data/processor.py
@@ -1,10 +1,6 @@
import base64
import instructor
-<<<<<<< HEAD
-from mistralai import Mistral
-=======
from mistralai.client import Mistral
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
from PIL import Image
import io
@@ -21,10 +17,7 @@ def process_and_encode_image(image_file, max_size=(2048, 2048)):
return base64.b64encode(buffered.getvalue()).decode('utf-8')
def extract_structured_data(image_file, schema_model, api_key: str):
-<<<<<<< HEAD
-=======
"""Send the image to Mistral Large 3 and return data validated against the given schema."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
client = instructor.from_mistral(Mistral(api_key=api_key))
base64_image = process_and_encode_image(image_file)
diff --git a/OCR/image_to_structured_data/schemas.py b/OCR/image_to_structured_data/schemas.py
index 12db5de..284298f 100644
--- a/OCR/image_to_structured_data/schemas.py
+++ b/OCR/image_to_structured_data/schemas.py
@@ -2,18 +2,12 @@ from pydantic import BaseModel, Field
from typing import List, Optional
class ProductAttribute(BaseModel):
-<<<<<<< HEAD
-=======
"""A single key-value attribute describing a product."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
key: str
value: str
class StructuredProduct(BaseModel):
-<<<<<<< HEAD
-=======
"""A single product extracted from an image, with pricing and attributes."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
name: str
brand: Optional[str]
price: Optional[float]
@@ -27,10 +21,7 @@ class ProductCollection(BaseModel):
products: List[StructuredProduct]
class InvoiceData(BaseModel):
-<<<<<<< HEAD
-=======
"""A single invoice extracted from an image, with vendor, total, and line items."""
->>>>>>> 1d1e9f137cfd1123edbae5d8e955ce0b9c7fcf4a
vendor_name: str
date: str
total_amount: float