OCR Text Extraction
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,7 @@
|
||||
import os
|
||||
from sqlalchemy import create_engine, Column, Integer, String, Text, DateTime, Boolean, ForeignKey, LargeBinary
|
||||
import urllib.parse
|
||||
from sqlalchemy import create_engine, Column, Integer, String, Text, DateTime, Boolean, ForeignKey, LargeBinary, Enum as SqlEnum
|
||||
from sqlalchemy.dialects.postgresql import JSONB
|
||||
from sqlalchemy.ext.declarative import declarative_base
|
||||
from sqlalchemy.orm import sessionmaker, relationship
|
||||
from dotenv import load_dotenv
|
||||
@@ -7,22 +9,11 @@ from dotenv import load_dotenv
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
DB_USER = os.getenv("DB_USER")
|
||||
DB_PASSWORD = os.getenv("DB_PASSWORD")
|
||||
DB_HOST = os.getenv("DB_HOST")
|
||||
DB_PORT = os.getenv("DB_PORT")
|
||||
import urllib.parse
|
||||
|
||||
# ... (imports)
|
||||
|
||||
# Load environment variables
|
||||
load_dotenv()
|
||||
|
||||
DB_USER = os.getenv("DB_USER")
|
||||
DB_PASSWORD = os.getenv("DB_PASSWORD")
|
||||
DB_HOST = os.getenv("DB_HOST")
|
||||
DB_PORT = os.getenv("DB_PORT")
|
||||
DB_NAME = os.getenv("DB_NAME")
|
||||
DB_USER = os.getenv("DB_USER", "postgres")
|
||||
DB_PASSWORD = os.getenv("DB_PASSWORD", "password")
|
||||
DB_HOST = os.getenv("DB_HOST", "localhost")
|
||||
DB_PORT = os.getenv("DB_PORT", "5432")
|
||||
DB_NAME = os.getenv("DB_NAME", "ocr_db")
|
||||
|
||||
encoded_user = urllib.parse.quote_plus(DB_USER)
|
||||
encoded_password = urllib.parse.quote_plus(DB_PASSWORD)
|
||||
@@ -35,6 +26,26 @@ SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
||||
|
||||
Base = declarative_base()
|
||||
|
||||
class Vendor(Base):
|
||||
__tablename__ = "vendors"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String, unique=True, index=True)
|
||||
default_model = Column(String) # 'text' or 'vision'
|
||||
created_at = Column(DateTime)
|
||||
|
||||
class Document(Base):
|
||||
__tablename__ = "documents"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
vendor_id = Column(Integer, ForeignKey("vendors.id"), nullable=True)
|
||||
filename = Column(String)
|
||||
upload_date = Column(DateTime)
|
||||
status = Column(String) # 'pending', 'verified'
|
||||
processed_data = Column(JSONB) # Store the verified extraction results
|
||||
|
||||
vendor = relationship("Vendor")
|
||||
|
||||
class Email(Base):
|
||||
__tablename__ = "emails"
|
||||
|
||||
@@ -54,7 +65,7 @@ class Attachment(Base):
|
||||
email_id = Column(Integer, ForeignKey("emails.id"))
|
||||
filename = Column(String)
|
||||
content_type = Column(String)
|
||||
file_content = Column(LargeBinary) # Storing content directly in DB as requested
|
||||
file_content = Column(LargeBinary)
|
||||
|
||||
email = relationship("Email", back_populates="attachments")
|
||||
|
||||
|
||||
@@ -85,6 +85,12 @@ class LoginResponse(BaseModel):
|
||||
token: str
|
||||
message: str
|
||||
|
||||
@app.post("/api/login", response_model=LoginResponse)
|
||||
def login(request: LoginRequest):
|
||||
if request.username == "admin" and request.password == "admin":
|
||||
return LoginResponse(token="fake-super-secret-token", message="Success")
|
||||
raise HTTPException(status_code=401, detail="Invalid username or password")
|
||||
|
||||
class NERResponse(BaseModel):
|
||||
text: str
|
||||
|
||||
|
||||
Reference in New Issue
Block a user