therealestcoder commited on
Commit
9482591
Β·
verified Β·
1 Parent(s): 1a4b0b4

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +11 -4
app.py CHANGED
@@ -10,13 +10,20 @@ import cv2
10
  import gradio as gr
11
  import numpy as np
12
  import torch
13
- from PIL import Image
14
 
15
  # ── paths ──────────────────────────────────────────────────────────────────
16
  ROOT = Path(__file__).resolve().parent
17
- sys.path.insert(0, str(ROOT))
 
 
 
 
 
 
 
 
 
18
 
19
- from src import config as C
20
  from src.infer import load_model, predict_image, render_visualization
21
 
22
  # ── model (lazy) ───────────────────────────────────────────────────────────
@@ -106,7 +113,7 @@ with gr.Blocks(title="Paint Defect Detector", theme=gr.themes.Soft()) as demo:
106
  img_input = gr.Image(label="Car Body Panel Photo", type="numpy")
107
  vin_input = gr.Textbox(label="VIN (optional)", placeholder="e.g. XTA210930Y2837465")
108
  threshold = gr.Slider(
109
- minimum=0.1, maximum=0.9, value=C.DEFECT_THRESHOLD, step=0.05,
110
  label="Defect Threshold",
111
  info="Patch probability above this value is marked as defective."
112
  )
 
10
  import gradio as gr
11
  import numpy as np
12
  import torch
 
13
 
14
  # ── paths ──────────────────────────────────────────────────────────────────
15
  ROOT = Path(__file__).resolve().parent
16
+ if str(ROOT) not in sys.path:
17
+ sys.path.insert(0, str(ROOT))
18
+
19
+ # inline constants so the app works even if src imports have issues
20
+ DEFECT_THRESHOLD = float(os.getenv("PDD_DEFECT_THRESHOLD", 0.55))
21
+ PANEL_DEFECT_RATIO = 0.005
22
+ IMG_SIZE = 384
23
+ PATCH_SIZE = 512
24
+ PATCH_STRIDE = 256
25
+ BACKBONE = os.getenv("PDD_BACKBONE", "tf_efficientnetv2_s.in21k_ft_in1k")
26
 
 
27
  from src.infer import load_model, predict_image, render_visualization
28
 
29
  # ── model (lazy) ───────────────────────────────────────────────────────────
 
113
  img_input = gr.Image(label="Car Body Panel Photo", type="numpy")
114
  vin_input = gr.Textbox(label="VIN (optional)", placeholder="e.g. XTA210930Y2837465")
115
  threshold = gr.Slider(
116
+ minimum=0.1, maximum=0.9, value=DEFECT_THRESHOLD, step=0.05,
117
  label="Defect Threshold",
118
  info="Patch probability above this value is marked as defective."
119
  )