Omarelrayes commited on
Commit
8be32ac
·
verified ·
1 Parent(s): 18616b7

Update app/configs.py

Browse files
Files changed (1) hide show
  1. app/configs.py +33 -17
app/configs.py CHANGED
@@ -1,13 +1,15 @@
1
  # app/configs.py
2
  import os
3
- os.environ["PYTHONPATH"] = "/app:" + os.environ.get("PYTHONPATH", "")
4
-
5
- import tensorflow as tf
6
  from pathlib import Path
7
  from typing import Dict, Any, List
 
8
  from huggingface_hub import hf_hub_download
9
  import zipfile
10
  import shutil
 
 
 
11
 
12
  try:
13
  from hf_artifact_repo import HuggingFaceArtifactRepository
@@ -34,6 +36,34 @@ print("="*60)
34
  _classification_model = None
35
  _segmentation_model = None
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  def download_and_extract_savedmodel(zip_path_in_repo, extract_dir):
38
  print(f"📥 Downloading {zip_path_in_repo}...")
39
 
@@ -117,18 +147,4 @@ def get_segmentation_model():
117
 
118
  return _segmentation_model
119
 
120
- model_classes = {
121
- 0: "benign",
122
- 1: "malignant"
123
- }
124
-
125
- request_history: List[Dict[str, Any]] = []
126
-
127
- STORAGE_DIR = Path("storage")
128
- IMAGES_DIR = STORAGE_DIR / "images"
129
- SEGMENTS_DIR = STORAGE_DIR / "segments"
130
-
131
- for d in [STORAGE_DIR, IMAGES_DIR, SEGMENTS_DIR]:
132
- d.mkdir(parents=True, exist_ok=True)
133
-
134
  print("✅ Models module initialized successfully!")
 
1
  # app/configs.py
2
  import os
3
+ import uuid
 
 
4
  from pathlib import Path
5
  from typing import Dict, Any, List
6
+ from datetime import datetime
7
  from huggingface_hub import hf_hub_download
8
  import zipfile
9
  import shutil
10
+ import tensorflow as tf
11
+
12
+ os.environ["PYTHONPATH"] = "/app:" + os.environ.get("PYTHONPATH", "")
13
 
14
  try:
15
  from hf_artifact_repo import HuggingFaceArtifactRepository
 
36
  _classification_model = None
37
  _segmentation_model = None
38
 
39
+ # Storage directories
40
+ STORAGE_DIR = Path("storage")
41
+ IMAGES_DIR = STORAGE_DIR / "images"
42
+ SEGMENTS_DIR = STORAGE_DIR / "segments"
43
+
44
+ for d in [STORAGE_DIR, IMAGES_DIR, SEGMENTS_DIR]:
45
+ d.mkdir(parents=True, exist_ok=True)
46
+
47
+ model_classes = {
48
+ 0: "benign",
49
+ 1: "malignant"
50
+ }
51
+
52
+ request_history: List[Dict[str, Any]] = []
53
+
54
+ def save_image(image_bytes: bytes, filename: str) -> str:
55
+ """Save uploaded image to storage"""
56
+ image_path = IMAGES_DIR / filename
57
+ with open(image_path, 'wb') as f:
58
+ f.write(image_bytes)
59
+ return str(image_path)
60
+
61
+ def save_segmentation(mask_image, request_id: str) -> str:
62
+ """Save segmentation mask"""
63
+ segmentation_path = SEGMENTS_DIR / f"{request_id}_mask.png"
64
+ mask_image.save(segmentation_path, format='PNG')
65
+ return str(segmentation_path)
66
+
67
  def download_and_extract_savedmodel(zip_path_in_repo, extract_dir):
68
  print(f"📥 Downloading {zip_path_in_repo}...")
69
 
 
147
 
148
  return _segmentation_model
149
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  print("✅ Models module initialized successfully!")