Tantawi65 commited on
Commit
2f34ba3
·
1 Parent(s): 900e15e

Flatten structure: Move all files from app/ to root directory

Browse files
Dockerfile CHANGED
@@ -23,5 +23,6 @@ EXPOSE 7860
23
  ENV PYTHONPATH=/code
24
  ENV TMPDIR=/tmp
25
 
 
26
  # Command to run the application
27
- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
23
  ENV PYTHONPATH=/code
24
  ENV TMPDIR=/tmp
25
 
26
+ # Command to run the application with explicit path
27
  # Command to run the application
28
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
app/main.py → main.py RENAMED
@@ -1,4 +1,4 @@
1
- # app/main.py
2
 
3
  import shutil
4
  import os
@@ -6,11 +6,11 @@ import uuid
6
  from fastapi import FastAPI, File, UploadFile, HTTPException
7
  from fastapi.responses import JSONResponse
8
  from fastapi.middleware.cors import CORSMiddleware
9
- from app.predict import predict_image
10
 
11
  app = FastAPI(
12
- title="GP-Tea Skin Analysis API",
13
- description="AI-powered skin condition analysis service",
14
  version="1.0.0"
15
  )
16
 
@@ -23,8 +23,10 @@ app.add_middleware(
23
  allow_headers=["*"],
24
  )
25
 
26
- # Create uploads directory
27
- os.makedirs("app/uploads", exist_ok=True)
 
 
28
 
29
  @app.get("/health")
30
  async def health_check():
@@ -38,7 +40,7 @@ async def analyze_image(file: UploadFile = File(...)):
38
  raise HTTPException(status_code=400, detail="File must be an image")
39
 
40
  unique_filename = f"{uuid.uuid4().hex}_{file.filename}"
41
- file_path = f"app/uploads/{unique_filename}"
42
 
43
  with open(file_path, "wb") as buffer:
44
  shutil.copyfileobj(file.file, buffer)
 
1
+ # main.py
2
 
3
  import shutil
4
  import os
 
6
  from fastapi import FastAPI, File, UploadFile, HTTPException
7
  from fastapi.responses import JSONResponse
8
  from fastapi.middleware.cors import CORSMiddleware
9
+ from predict import predict_image
10
 
11
  app = FastAPI(
12
+ title="Medical Image Classification API",
13
+ description="AI-powered medical image classification service",
14
  version="1.0.0"
15
  )
16
 
 
23
  allow_headers=["*"],
24
  )
25
 
26
+ # Create uploads directory in tmp (writable in containers)
27
+ import tempfile
28
+ UPLOAD_DIR = tempfile.mkdtemp()
29
+ os.makedirs(UPLOAD_DIR, exist_ok=True)
30
 
31
  @app.get("/health")
32
  async def health_check():
 
40
  raise HTTPException(status_code=400, detail="File must be an image")
41
 
42
  unique_filename = f"{uuid.uuid4().hex}_{file.filename}"
43
+ file_path = os.path.join(UPLOAD_DIR, unique_filename)
44
 
45
  with open(file_path, "wb") as buffer:
46
  shutil.copyfileobj(file.file, buffer)
app/model_loader.py → model_loader.py RENAMED
@@ -1,9 +1,9 @@
1
- # app/model_loader.py
2
  import os
3
  import tensorflow as tf
4
  from huggingface_hub import hf_hub_download
5
 
6
- MODEL_PATH = "app/model/efficientnetv2s.h5"
7
  REPO_ID = "Miguel764/efficientnetv2s-skin-cancer-classifier"
8
  FILENAME = "efficientnetv2s.h5"
9
 
@@ -14,7 +14,7 @@ def load_model():
14
  hf_hub_download(
15
  repo_id=REPO_ID,
16
  filename=FILENAME,
17
- local_dir="app/model"
18
  )
19
  else:
20
  print("Model already exists locally.")
 
1
+ # model_loader.py
2
  import os
3
  import tensorflow as tf
4
  from huggingface_hub import hf_hub_download
5
 
6
+ MODEL_PATH = "model/efficientnetv2s.h5"
7
  REPO_ID = "Miguel764/efficientnetv2s-skin-cancer-classifier"
8
  FILENAME = "efficientnetv2s.h5"
9
 
 
14
  hf_hub_download(
15
  repo_id=REPO_ID,
16
  filename=FILENAME,
17
+ local_dir="model"
18
  )
19
  else:
20
  print("Model already exists locally.")
app/predict.py → predict.py RENAMED
@@ -1,8 +1,8 @@
1
- # app/predict.py
2
  from tensorflow.keras.preprocessing import image
3
  import numpy as np
4
  import tensorflow as tf
5
- from app.model_loader import load_model
6
 
7
  model = load_model()
8
 
 
1
+ # predict.py
2
  from tensorflow.keras.preprocessing import image
3
  import numpy as np
4
  import tensorflow as tf
5
+ from model_loader import load_model
6
 
7
  model = load_model()
8