Omarelrayes commited on
Commit
ec10275
·
verified ·
1 Parent(s): d24b228

Update app/main.py

Browse files
Files changed (1) hide show
  1. app/main.py +13 -5
app/main.py CHANGED
@@ -8,7 +8,11 @@ from . import configs as config
8
  from .models import UploadResponse, ClassifyRequest, ClassifyResponse, SegmentRequest, SegmentResponse
9
  from .services.predictor import classify_image
10
  from .services.segmenter import segment_image
11
- from .services.routing import router as model_router
 
 
 
 
12
  from .storage import (
13
  save_image,
14
  get_image_path,
@@ -27,6 +31,9 @@ app = FastAPI(
27
 
28
  app.add_middleware(MetricsMiddleware)
29
 
 
 
 
30
  ALLOWED_CONTENT_TYPES = {"image/jpeg", "image/png", "image/jpg"}
31
  MAX_FILE_SIZE = 10 * 1024 * 1024
32
 
@@ -44,7 +51,7 @@ async def models_status():
44
  return {
45
  "classification_loaded": classification_model is not None,
46
  "segmentation_loaded": segmentation_model is not None,
47
- "ab_testing": model_router.get_ab_status(),
48
  "loaded_versions": config.get_loaded_versions(),
49
  "storage_paths": {
50
  "images": str(config.IMAGES_DIR),
@@ -55,7 +62,7 @@ async def models_status():
55
 
56
  @app.get("/api/ab-status")
57
  async def ab_testing_status():
58
- return model_router.get_ab_status()
59
 
60
 
61
  @app.post("/api/upload", status_code=201, response_model=UploadResponse)
@@ -115,7 +122,8 @@ async def classify(body: ClassifyRequest):
115
  status=existing.get("status", "completed"),
116
  )
117
 
118
- resolved_uri = model_router.resolve_classifier_version(body.model_version)
 
119
 
120
  try:
121
  prediction, confidence, actual_version = classify_image(
@@ -230,4 +238,4 @@ async def health():
230
  return {
231
  "status": "healthy",
232
  "predict_ready": config.get_classification_model() is not None,
233
- }
 
8
  from .models import UploadResponse, ClassifyRequest, ClassifyResponse, SegmentRequest, SegmentResponse
9
  from .services.predictor import classify_image
10
  from .services.segmenter import segment_image
11
+ from .services.routing import (
12
+ router as model_router,
13
+ resolve_classifier_version,
14
+ get_ab_status,
15
+ )
16
  from .storage import (
17
  save_image,
18
  get_image_path,
 
31
 
32
  app.add_middleware(MetricsMiddleware)
33
 
34
+ # ✅ Include the router for model management endpoints
35
+ app.include_router(model_router)
36
+
37
  ALLOWED_CONTENT_TYPES = {"image/jpeg", "image/png", "image/jpg"}
38
  MAX_FILE_SIZE = 10 * 1024 * 1024
39
 
 
51
  return {
52
  "classification_loaded": classification_model is not None,
53
  "segmentation_loaded": segmentation_model is not None,
54
+ "ab_testing": get_ab_status(), # ✅ استخدام الدالة المستقلة
55
  "loaded_versions": config.get_loaded_versions(),
56
  "storage_paths": {
57
  "images": str(config.IMAGES_DIR),
 
62
 
63
  @app.get("/api/ab-status")
64
  async def ab_testing_status():
65
+ return get_ab_status() # ✅ استخدام الدالة المستقلة
66
 
67
 
68
  @app.post("/api/upload", status_code=201, response_model=UploadResponse)
 
122
  status=existing.get("status", "completed"),
123
  )
124
 
125
+ # استخدام الدالة المستقلة
126
+ resolved_uri = resolve_classifier_version(body.model_version)
127
 
128
  try:
129
  prediction, confidence, actual_version = classify_image(
 
238
  return {
239
  "status": "healthy",
240
  "predict_ready": config.get_classification_model() is not None,
241
+ }