File size: 1,768 Bytes
63bcd5a
 
41bd215
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41bd215
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63bcd5a
 
 
 
 
 
 
 
 
 
 
 
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
# api/main.py

from fastapi import FastAPI, HTTPException

from fastapi.middleware.cors import CORSMiddleware

from api.schemas import AnalyzeRequest, ChatRequest, ChatResponse
from api.services import analyze_project, chat_with_llm

# =====================================================
# Create App
# =====================================================
app = FastAPI(
    title="Graduation Project Similarity API",
    version="1.0.0",
    description="AI system for project similarity and originality detection"
)

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

# =====================================================
# Routes
# =====================================================

@app.get("/")
def home():
    return {
        "message": "API is running successfully"
    }


@app.get("/health")
def health():
    return {
        "status": "healthy"
    }


@app.post("/analyze")
def analyze(data: AnalyzeRequest):
    try:
        result = analyze_project(
            title=data.title,
            description=data.description,
            abstract=data.abstract,
            features=data.features,
            top_k=data.top_k
        )
        return result
    except HTTPException:
        raise
    except Exception as exc:
        raise HTTPException(
            status_code=500,
            detail=f"Analysis failed: {exc}"
        )


@app.post("/chat", response_model=ChatResponse)
def chat(data: ChatRequest):

    result = chat_with_llm(
        user_id=data.user_id,
        message=data.message
    )

    return result