File size: 2,994 Bytes
0d9a2a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from typing import Optional, List, Dict
import json

app = FastAPI(
    title="SobroJuriBert API",
    description="Legal text analysis service (Vercel deployment)",
    version="1.0.0"
)

# CORS middleware
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

class AnalysisRequest(BaseModel):
    text: str
    analysis_type: Optional[str] = "full"

class AnalysisResponse(BaseModel):
    text: str
    analysis_type: str
    results: Dict
    status: str = "success"

@app.get("/")
async def root():
    return {
        "name": "SobroJuriBert",
        "version": "1.0.0",
        "description": "Legal text analysis service",
        "status": "operational",
        "note": "Running in lightweight mode on Vercel",
        "endpoints": [
            "/analyze",
            "/extract_entities", 
            "/classify",
            "/health"
        ]
    }

@app.post("/analyze", response_model=AnalysisResponse)
async def analyze_text(request: AnalysisRequest):
    """Analyze legal text (demo mode)"""
    try:
        # In production, this would use JuriBERT model
        # For Vercel deployment, we return mock results
        results = {
            "entities": [
                {"text": "contrat", "type": "LEGAL_CONCEPT", "confidence": 0.95},
                {"text": "obligation", "type": "LEGAL_CONCEPT", "confidence": 0.92}
            ],
            "classification": {
                "category": "contract_law",
                "confidence": 0.88
            },
            "summary": "Legal document analysis completed",
            "keywords": ["contrat", "obligation", "juridique"],
            "language": "fr"
        }
        
        return AnalysisResponse(
            text=request.text[:100] + "...",
            analysis_type=request.analysis_type,
            results=results
        )
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

@app.post("/extract_entities")
async def extract_entities(request: AnalysisRequest):
    """Extract legal entities from text"""
    return {
        "entities": [
            {"text": "partie contractante", "type": "PARTY", "confidence": 0.9},
            {"text": "tribunal", "type": "INSTITUTION", "confidence": 0.95}
        ],
        "text_length": len(request.text)
    }

@app.post("/classify")
async def classify_document(request: AnalysisRequest):
    """Classify legal document type"""
    return {
        "classification": {
            "primary": "contract",
            "secondary": ["commercial", "services"],
            "confidence": 0.85
        }
    }

@app.get("/health")
async def health_check():
    return {
        "status": "healthy",
        "service": "SobroJuriBert",
        "mode": "vercel_lightweight"
    }

# For Vercel
handler = app