Spaces:
Sleeping
Sleeping
Commit ·
50755bb
1
Parent(s): c57f130
feat: cleaned
Browse files- api/server.py +1 -3
- app/__init__.py +0 -0
- app/core/__init__.py +0 -0
- app/core/config/__init__.py +0 -0
- app/core/config/settings.py +0 -28
- banner.py +9 -7
- main.py +2 -0
- start.sh +5 -0
api/server.py
CHANGED
|
@@ -37,9 +37,8 @@ import uvicorn
|
|
| 37 |
from fastapi import FastAPI, File, Form, HTTPException, UploadFile
|
| 38 |
from fastapi.middleware.cors import CORSMiddleware
|
| 39 |
from fastapi.middleware.gzip import GZipMiddleware
|
| 40 |
-
from pydantic import BaseModel, Field
|
| 41 |
|
| 42 |
-
from banner import print_banner
|
| 43 |
from core import ConversionError, ConversionResult, DocumentConverter, SUPPORTED_EXTENSIONS
|
| 44 |
from extraction.generic_json_extractor import extract
|
| 45 |
from extraction.label_mapper import validate_mappings
|
|
@@ -100,7 +99,6 @@ def _start_ping_scheduler() -> None:
|
|
| 100 |
@asynccontextmanager
|
| 101 |
async def lifespan(app: FastAPI):
|
| 102 |
"""Application lifespan handler — runs startup and shutdown logic."""
|
| 103 |
-
print_banner()
|
| 104 |
logger.info(
|
| 105 |
"MarkItDown API starting | version=2.1.0 | host=0.0.0.0:7860 | started_at=%s",
|
| 106 |
datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC"),
|
|
|
|
| 37 |
from fastapi import FastAPI, File, Form, HTTPException, UploadFile
|
| 38 |
from fastapi.middleware.cors import CORSMiddleware
|
| 39 |
from fastapi.middleware.gzip import GZipMiddleware
|
| 40 |
+
from pydantic import BaseModel, Field, field_validator
|
| 41 |
|
|
|
|
| 42 |
from core import ConversionError, ConversionResult, DocumentConverter, SUPPORTED_EXTENSIONS
|
| 43 |
from extraction.generic_json_extractor import extract
|
| 44 |
from extraction.label_mapper import validate_mappings
|
|
|
|
| 99 |
@asynccontextmanager
|
| 100 |
async def lifespan(app: FastAPI):
|
| 101 |
"""Application lifespan handler — runs startup and shutdown logic."""
|
|
|
|
| 102 |
logger.info(
|
| 103 |
"MarkItDown API starting | version=2.1.0 | host=0.0.0.0:7860 | started_at=%s",
|
| 104 |
datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC"),
|
app/__init__.py
DELETED
|
File without changes
|
app/core/__init__.py
DELETED
|
File without changes
|
app/core/config/__init__.py
DELETED
|
File without changes
|
app/core/config/settings.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
"""Application settings via Pydantic Settings.
|
| 2 |
-
|
| 3 |
-
Configuration is driven by environment variables with sensible defaults
|
| 4 |
-
for local development. In production, set these via the container's
|
| 5 |
-
environment (Docker Compose, K8s ConfigMap/Secret, etc.).
|
| 6 |
-
"""
|
| 7 |
-
|
| 8 |
-
from __future__ import annotations
|
| 9 |
-
|
| 10 |
-
import os
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
class Settings:
|
| 14 |
-
"""Simple settings container — no external dependencies required."""
|
| 15 |
-
|
| 16 |
-
SERVICE_NAME: str = "reconciliation-file-processing-service"
|
| 17 |
-
API_VERSION: str = "2.1.0"
|
| 18 |
-
ENVIRONMENT: str = os.getenv("ENVIRONMENT", "development")
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
_settings: Settings | None = None
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
def get_settings() -> Settings:
|
| 25 |
-
global _settings
|
| 26 |
-
if _settings is None:
|
| 27 |
-
_settings = Settings()
|
| 28 |
-
return _settings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
banner.py
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
|
|
|
|
|
| 1 |
import pyfiglet
|
| 2 |
from rich.console import Console
|
| 3 |
from rich.rule import Rule
|
| 4 |
from rich.text import Text
|
| 5 |
|
| 6 |
-
from app.core.config.settings import get_settings
|
| 7 |
-
|
| 8 |
_console = Console()
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
def print_banner() -> None:
|
| 12 |
-
settings = get_settings()
|
| 13 |
|
|
|
|
| 14 |
art = pyfiglet.figlet_format("ValidOps", font="slant")
|
| 15 |
|
| 16 |
_console.print(Text(art, style="bold cyan"))
|
| 17 |
-
_console.print(f" [bold white]{'Service:':<14}[/bold white] [cyan]{
|
| 18 |
-
_console.print(f" [bold white]{'Version:':<14}[/bold white] [cyan]v{
|
| 19 |
-
_console.print(f" [bold white]{'Environment:':<14}[/bold white] [cyan]{
|
| 20 |
_console.print(Rule(style="dim cyan"))
|
| 21 |
_console.print()
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
import pyfiglet
|
| 4 |
from rich.console import Console
|
| 5 |
from rich.rule import Rule
|
| 6 |
from rich.text import Text
|
| 7 |
|
|
|
|
|
|
|
| 8 |
_console = Console()
|
| 9 |
|
| 10 |
+
SERVICE_NAME = os.getenv("SERVICE_NAME", "reconciliation-file-processing-service")
|
| 11 |
+
API_VERSION = os.getenv("API_VERSION", "2.1.0")
|
| 12 |
+
ENVIRONMENT = os.getenv("ENVIRONMENT", "development")
|
| 13 |
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
def print_banner() -> None:
|
| 16 |
art = pyfiglet.figlet_format("ValidOps", font="slant")
|
| 17 |
|
| 18 |
_console.print(Text(art, style="bold cyan"))
|
| 19 |
+
_console.print(f" [bold white]{'Service:':<14}[/bold white] [cyan]{SERVICE_NAME}[/cyan]")
|
| 20 |
+
_console.print(f" [bold white]{'Version:':<14}[/bold white] [cyan]v{API_VERSION}[/cyan]")
|
| 21 |
+
_console.print(f" [bold white]{'Environment:':<14}[/bold white] [cyan]{ENVIRONMENT}[/cyan]")
|
| 22 |
_console.print(Rule(style="dim cyan"))
|
| 23 |
_console.print()
|
main.py
CHANGED
|
@@ -14,11 +14,13 @@ import os
|
|
| 14 |
|
| 15 |
import uvicorn
|
| 16 |
|
|
|
|
| 17 |
from logger import get_logger
|
| 18 |
|
| 19 |
logger = get_logger(__name__)
|
| 20 |
|
| 21 |
if __name__ == "__main__":
|
|
|
|
| 22 |
workers = int(os.getenv("WORKERS", os.cpu_count() or 1))
|
| 23 |
port = int(os.getenv("PORT", "7860"))
|
| 24 |
|
|
|
|
| 14 |
|
| 15 |
import uvicorn
|
| 16 |
|
| 17 |
+
from banner import print_banner
|
| 18 |
from logger import get_logger
|
| 19 |
|
| 20 |
logger = get_logger(__name__)
|
| 21 |
|
| 22 |
if __name__ == "__main__":
|
| 23 |
+
print_banner()
|
| 24 |
workers = int(os.getenv("WORKERS", os.cpu_count() or 1))
|
| 25 |
port = int(os.getenv("PORT", "7860"))
|
| 26 |
|
start.sh
CHANGED
|
@@ -66,6 +66,11 @@ else
|
|
| 66 |
log_warn "Import smoke test failed. Check $LOG_FILE for details. Continuing startup."
|
| 67 |
fi
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
# ---------------------------------------------------------------------------
|
| 70 |
# Start uvicorn
|
| 71 |
# ---------------------------------------------------------------------------
|
|
|
|
| 66 |
log_warn "Import smoke test failed. Check $LOG_FILE for details. Continuing startup."
|
| 67 |
fi
|
| 68 |
|
| 69 |
+
# ---------------------------------------------------------------------------
|
| 70 |
+
# Print startup banner
|
| 71 |
+
# ---------------------------------------------------------------------------
|
| 72 |
+
python -c "from banner import print_banner; print_banner()" 2>/dev/null || true
|
| 73 |
+
|
| 74 |
# ---------------------------------------------------------------------------
|
| 75 |
# Start uvicorn
|
| 76 |
# ---------------------------------------------------------------------------
|