yasyn14 commited on
Commit
0c4301a
·
1 Parent(s): 1b055ee

brought back grad

Browse files
Files changed (3) hide show
  1. main.py +34 -4
  2. requirements.txt +0 -0
  3. utils/predictor.py +1 -1
main.py CHANGED
@@ -4,10 +4,12 @@ from fastapi import FastAPI
4
  from fastapi.middleware.cors import CORSMiddleware
5
  from contextlib import asynccontextmanager
6
  from huggingface_hub import hf_hub_download
 
7
  from PIL import Image
8
 
9
  from api.v1 import router as v1_router
10
  from models.model_loader import load_skin_condition_model
 
11
 
12
  os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
13
  logger = logging.getLogger("uvicorn.error")
@@ -58,10 +60,6 @@ app.add_middleware(
58
  allow_headers=["*"],
59
  )
60
 
61
- # --- basic hello route at “/” ---
62
- @app.get("/", tags=["Root"])
63
- async def hello():
64
- return {"message": "Hello from the Skin Analyzer API 👋"}
65
 
66
  @app.get("/healthz", tags=["Health"])
67
  async def health_check():
@@ -69,3 +67,35 @@ async def health_check():
69
 
70
  # include your versioned REST API
71
  app.include_router(v1_router)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  from fastapi.middleware.cors import CORSMiddleware
5
  from contextlib import asynccontextmanager
6
  from huggingface_hub import hf_hub_download
7
+ import gradio as gr
8
  from PIL import Image
9
 
10
  from api.v1 import router as v1_router
11
  from models.model_loader import load_skin_condition_model
12
+ from utils.predictor import predict_skin_condition
13
 
14
  os.environ["TF_ENABLE_ONEDNN_OPTS"] = "0"
15
  logger = logging.getLogger("uvicorn.error")
 
60
  allow_headers=["*"],
61
  )
62
 
 
 
 
 
63
 
64
  @app.get("/healthz", tags=["Health"])
65
  async def health_check():
 
67
 
68
  # include your versioned REST API
69
  app.include_router(v1_router)
70
+
71
+
72
+ # === Gradio UI Setup ===
73
+ def predict_skin_condition_grad(image: Image.Image):
74
+ if image is None:
75
+ return "No image provided"
76
+
77
+ model = app.state.model
78
+
79
+ # Preprocess image
80
+ img = image.resize((224, 224)).convert("RGB")
81
+ img_array = np.array(img)
82
+
83
+ # Predict
84
+ prediction = predict_skin_condition(img_array, model)
85
+
86
+
87
+ confidence = prediction.get("confidence")
88
+ label = prediction.get("condition")
89
+
90
+ return f"{label} ({confidence:.2%} confidence)"
91
+
92
+ gradio_interface = gr.Interface(
93
+ fn=predict_skin_condition_grad,
94
+ inputs=gr.Image(type="pil", label="Upload a skin image"),
95
+ outputs=gr.Text(label="Prediction"),
96
+ title="Skin Analyzer",
97
+ description="Upload a photo of skin to detect conditions like acne, eczema, dryness, etc."
98
+ )
99
+
100
+ # Mount Gradio on root
101
+ app = gr.mount_gradio_app(app, gradio_interface, path="")
requirements.txt CHANGED
Binary files a/requirements.txt and b/requirements.txt differ
 
utils/predictor.py CHANGED
@@ -11,5 +11,5 @@ def predict_skin_condition(img_array, model):
11
 
12
  return {
13
  "condition": CLASS_NAMES[top_index],
14
- "confidence": float(pred_probs[top_index]) * 100
15
  }
 
11
 
12
  return {
13
  "condition": CLASS_NAMES[top_index],
14
+ "confidence": float(pred_probs[top_index])
15
  }