Spaces:
Running
Running
solve pydantic deprecation warning
Browse files- src/main.py +13 -5
src/main.py
CHANGED
|
@@ -2,7 +2,7 @@ import os
|
|
| 2 |
import logging
|
| 3 |
import secrets
|
| 4 |
import requests
|
| 5 |
-
from typing import Annotated, Generator
|
| 6 |
from fastapi import (
|
| 7 |
FastAPI,
|
| 8 |
Request,
|
|
@@ -13,7 +13,7 @@ from fastapi import (
|
|
| 13 |
from fastapi.background import BackgroundTasks
|
| 14 |
from fastapi.responses import RedirectResponse, JSONResponse
|
| 15 |
from fastapi.security.api_key import APIKeyHeader
|
| 16 |
-
from pydantic import BaseModel, Field
|
| 17 |
from psycopg.errors import UniqueViolation
|
| 18 |
from sqlalchemy.exc import IntegrityError
|
| 19 |
from starlette.status import (
|
|
@@ -23,10 +23,10 @@ from starlette.status import (
|
|
| 23 |
HTTP_500_INTERNAL_SERVER_ERROR,
|
| 24 |
HTTP_503_SERVICE_UNAVAILABLE)
|
| 25 |
from dotenv import load_dotenv
|
| 26 |
-
from src.entity.api.transaction_api import TransactionApi
|
| 27 |
from sqlalchemy import text
|
| 28 |
from sqlalchemy.orm import Session
|
| 29 |
|
|
|
|
| 30 |
from src.service.fraud_service import check_for_fraud_api
|
| 31 |
from src.service.notification_service import send_notification
|
| 32 |
from src.repository.common import get_session
|
|
@@ -84,8 +84,16 @@ class TransactionProcessingOutput(BaseModel):
|
|
| 84 |
It contains the fraud detection result and the fraud score.
|
| 85 |
This class is used as the response model for the /transaction/process endpoint.
|
| 86 |
"""
|
| 87 |
-
is_fraud: int = Field(description="The prediction result. 1 if the transaction is detected as fraudulent, 0 otherwise."
|
| 88 |
-
fraud_score: float = Field(description="Probability of transaction being fraudulent."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
@app.post("/transaction/process",
|
| 91 |
tags=["transaction"],
|
|
|
|
| 2 |
import logging
|
| 3 |
import secrets
|
| 4 |
import requests
|
| 5 |
+
from typing import Annotated, Generator, ClassVar
|
| 6 |
from fastapi import (
|
| 7 |
FastAPI,
|
| 8 |
Request,
|
|
|
|
| 13 |
from fastapi.background import BackgroundTasks
|
| 14 |
from fastapi.responses import RedirectResponse, JSONResponse
|
| 15 |
from fastapi.security.api_key import APIKeyHeader
|
| 16 |
+
from pydantic import BaseModel, Field, ConfigDict
|
| 17 |
from psycopg.errors import UniqueViolation
|
| 18 |
from sqlalchemy.exc import IntegrityError
|
| 19 |
from starlette.status import (
|
|
|
|
| 23 |
HTTP_500_INTERNAL_SERVER_ERROR,
|
| 24 |
HTTP_503_SERVICE_UNAVAILABLE)
|
| 25 |
from dotenv import load_dotenv
|
|
|
|
| 26 |
from sqlalchemy import text
|
| 27 |
from sqlalchemy.orm import Session
|
| 28 |
|
| 29 |
+
from src.entity.api.transaction_api import TransactionApi
|
| 30 |
from src.service.fraud_service import check_for_fraud_api
|
| 31 |
from src.service.notification_service import send_notification
|
| 32 |
from src.repository.common import get_session
|
|
|
|
| 84 |
It contains the fraud detection result and the fraud score.
|
| 85 |
This class is used as the response model for the /transaction/process endpoint.
|
| 86 |
"""
|
| 87 |
+
is_fraud: int = Field(description="The prediction result. 1 if the transaction is detected as fraudulent, 0 otherwise.")
|
| 88 |
+
fraud_score: float = Field(description="Probability of transaction being fraudulent.")
|
| 89 |
+
|
| 90 |
+
model_config: ClassVar[ConfigDict] = ConfigDict(
|
| 91 |
+
json_schema_extra = {
|
| 92 |
+
"example": {
|
| 93 |
+
"is_fraud": 1,
|
| 94 |
+
"fraud_score": 0.85
|
| 95 |
+
}
|
| 96 |
+
})
|
| 97 |
|
| 98 |
@app.post("/transaction/process",
|
| 99 |
tags=["transaction"],
|