Update main.py
Browse files
main.py
CHANGED
@@ -1,13 +1,10 @@
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
-
from pydantic import BaseModel
|
3 |
-
from typing import List, Dict, Any, Optional
|
4 |
-
import os
|
5 |
-
import uvicorn
|
6 |
-
import time
|
7 |
-
import hashlib
|
8 |
from document_processor import DocumentProcessor
|
9 |
from models import *
|
10 |
-
|
|
|
|
|
11 |
# Initialize document processor
|
12 |
processor = DocumentProcessor()
|
13 |
|
@@ -20,19 +17,14 @@ async def lifespan(app: FastAPI):
|
|
20 |
yield
|
21 |
# Shutdown events (if you need any cleanup)
|
22 |
print("π Shutting down application...")
|
23 |
-
|
|
|
24 |
app = FastAPI(
|
25 |
title="Legal Document Analysis API",
|
26 |
version="1.0.0",
|
27 |
lifespan=lifespan # Pass the lifespan handler here
|
28 |
)
|
29 |
|
30 |
-
|
31 |
-
@app.on_event("startup")
|
32 |
-
async def startup_event():
|
33 |
-
"""Initialize models on startup"""
|
34 |
-
await processor.initialize()
|
35 |
-
|
36 |
@app.post("/analyze_document")
|
37 |
async def analyze_document(data: AnalyzeDocumentInput):
|
38 |
"""Unified endpoint for complete document analysis"""
|
@@ -69,3 +61,4 @@ def summarize_batch(data: SummarizeBatchInput):
|
|
69 |
if __name__ == "__main__":
|
70 |
import uvicorn
|
71 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
1 |
+
from contextlib import asynccontextmanager
|
2 |
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
from document_processor import DocumentProcessor
|
4 |
from models import *
|
5 |
+
import time
|
6 |
+
import hashlib
|
7 |
+
|
8 |
# Initialize document processor
|
9 |
processor = DocumentProcessor()
|
10 |
|
|
|
17 |
yield
|
18 |
# Shutdown events (if you need any cleanup)
|
19 |
print("π Shutting down application...")
|
20 |
+
|
21 |
+
# Create FastAPI app with lifespan handler
|
22 |
app = FastAPI(
|
23 |
title="Legal Document Analysis API",
|
24 |
version="1.0.0",
|
25 |
lifespan=lifespan # Pass the lifespan handler here
|
26 |
)
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
@app.post("/analyze_document")
|
29 |
async def analyze_document(data: AnalyzeDocumentInput):
|
30 |
"""Unified endpoint for complete document analysis"""
|
|
|
61 |
if __name__ == "__main__":
|
62 |
import uvicorn
|
63 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
64 |
+
|