morefaat69 commited on
Commit
a14e2d6
Β·
verified Β·
1 Parent(s): 3779515

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -6,11 +6,11 @@ import cv2
6
  import base64
7
  from ultralytics import YOLO
8
 
9
- # ─── Load Models
10
  person_model = YOLO("yolov8n.pt")
11
  statue_model = YOLO("best.pt")
12
 
13
- # ─── App Setup
14
  app = FastAPI()
15
 
16
  UPLOAD_FOLDER = "/tmp/uploads"
@@ -18,26 +18,26 @@ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
18
 
19
  app.mount("/uploads", StaticFiles(directory=UPLOAD_FOLDER), name="uploads")
20
 
21
- CONF_THRESHOLD = 0.30
22
 
23
  router = APIRouter()
24
 
25
 
26
  def draw_label(image, label, x1, y1, x2, y2, box_color, text_color):
27
-
28
  font = cv2.FONT_HERSHEY_SIMPLEX
29
  font_scale = 0.6
30
  thickness = 2
31
 
32
  (tw, th), _ = cv2.getTextSize(label, font, font_scale, thickness)
33
 
34
-
35
  if y1 - th - 8 >= 0:
36
  label_y1 = y1 - th - 8
37
  label_y2 = y1
38
  text_y = y1 - 5
39
  else:
40
-
41
  label_y1 = y1
42
  label_y2 = y1 + th + 8
43
  text_y = y1 + th + 3
@@ -71,7 +71,7 @@ async def predict_image(
71
  person_count = 0
72
  statue_count = 0
73
 
74
- # ── Person Detection
75
  person_results = person_model(file_path)
76
 
77
  for box in person_results[0].boxes:
@@ -97,7 +97,7 @@ async def predict_image(
97
  })
98
  person_count += 1
99
 
100
- # ── Statue Detection
101
  statue_results = statue_model(file_path)
102
 
103
  for box in statue_results[0].boxes:
@@ -122,7 +122,7 @@ async def predict_image(
122
  })
123
  statue_count += 1
124
 
125
- # ── Save Output Image
126
  output_filename = f"output_{safe_filename}"
127
  output_path = os.path.join(UPLOAD_FOLDER, output_filename)
128
  cv2.imwrite(output_path, image)
 
6
  import base64
7
  from ultralytics import YOLO
8
 
9
+ # ─── Load Models ──────────────────────────────────────────────────────────────
10
  person_model = YOLO("yolov8n.pt")
11
  statue_model = YOLO("best.pt")
12
 
13
+ # ─── App Setup ────────────────────────────────────────────────────────────────
14
  app = FastAPI()
15
 
16
  UPLOAD_FOLDER = "/tmp/uploads"
 
18
 
19
  app.mount("/uploads", StaticFiles(directory=UPLOAD_FOLDER), name="uploads")
20
 
21
+ CONF_THRESHOLD = 0.25
22
 
23
  router = APIRouter()
24
 
25
 
26
  def draw_label(image, label, x1, y1, x2, y2, box_color, text_color):
27
+ """Ψ§Ψ±Ψ³Ω… Ψ§Ω„Ω€ label ΩΩˆΩ‚ Ψ§Ω„Ω€ box، ΩˆΩ„Ωˆ Ω…ΩΩŠΨ΄ Ω…ΩƒΨ§Ω† ΩΩˆΩ‚ Ψ­Ψ·Ω‡ ΨͺΨ­Ψͺ"""
28
  font = cv2.FONT_HERSHEY_SIMPLEX
29
  font_scale = 0.6
30
  thickness = 2
31
 
32
  (tw, th), _ = cv2.getTextSize(label, font, font_scale, thickness)
33
 
34
+ # Ω„Ωˆ ΩΩŠΩ‡ Ω…ΩƒΨ§Ω† ΩΩˆΩ‚ Ψ§Ω„Ω€ box
35
  if y1 - th - 8 >= 0:
36
  label_y1 = y1 - th - 8
37
  label_y2 = y1
38
  text_y = y1 - 5
39
  else:
40
+ # Ψ­Ψ· Ψ§Ω„Ω€ label Ψ¬ΩˆΩ‡ Ψ§Ω„Ω€ box Ω…Ω† ΩΩˆΩ‚
41
  label_y1 = y1
42
  label_y2 = y1 + th + 8
43
  text_y = y1 + th + 3
 
71
  person_count = 0
72
  statue_count = 0
73
 
74
+ # ── Person Detection ──────────────────────────────────────────────────────
75
  person_results = person_model(file_path)
76
 
77
  for box in person_results[0].boxes:
 
97
  })
98
  person_count += 1
99
 
100
+ # ── Statue Detection ──────────────────────────────────────────────────────
101
  statue_results = statue_model(file_path)
102
 
103
  for box in statue_results[0].boxes:
 
122
  })
123
  statue_count += 1
124
 
125
+ # ── Save Output Image ─────────────────────────────────────────────────────
126
  output_filename = f"output_{safe_filename}"
127
  output_path = os.path.join(UPLOAD_FOLDER, output_filename)
128
  cv2.imwrite(output_path, image)