numanabubakar commited on
Commit
82b164a
·
1 Parent(s): 8af372d

Fix: Accept image_b64 alias and handle data URI prefix for mobile requests

Browse files
Files changed (1) hide show
  1. backend/app.py +6 -5
backend/app.py CHANGED
@@ -6,7 +6,7 @@ import base64
6
  import io
7
  from fastapi import FastAPI, UploadFile, File, HTTPException
8
  from fastapi.middleware.cors import CORSMiddleware
9
- from pydantic import BaseModel
10
  from typing import List, Dict, Any
11
 
12
  from model_loader import get_model_loader
@@ -44,16 +44,17 @@ class PredictionResponse(BaseModel):
44
  image_info: Dict[str, Any]
45
 
46
  class MobileRequest(BaseModel):
47
- image: str
48
 
49
  # Allow aliases in case the mobile app uses different names
50
- class Config:
51
- populate_by_name = True
52
- json_schema_extra = {
53
  "example": {
54
  "image": "base64_string_here"
55
  }
56
  }
 
57
 
58
  from fastapi.exceptions import RequestValidationError
59
  from fastapi.responses import JSONResponse
 
6
  import io
7
  from fastapi import FastAPI, UploadFile, File, HTTPException
8
  from fastapi.middleware.cors import CORSMiddleware
9
+ from pydantic import BaseModel, Field, ConfigDict
10
  from typing import List, Dict, Any
11
 
12
  from model_loader import get_model_loader
 
44
  image_info: Dict[str, Any]
45
 
46
  class MobileRequest(BaseModel):
47
+ image: str = Field(..., alias="image_b64")
48
 
49
  # Allow aliases in case the mobile app uses different names
50
+ model_config = ConfigDict(
51
+ populate_by_name=True,
52
+ json_schema_extra={
53
  "example": {
54
  "image": "base64_string_here"
55
  }
56
  }
57
+ )
58
 
59
  from fastapi.exceptions import RequestValidationError
60
  from fastapi.responses import JSONResponse