Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +64 -0
- best-seg.pt +3 -0
- requirements.txt +6 -0
app.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
model = YOLO('best-seg.pt')
|
| 6 |
+
|
| 7 |
+
CLASS_NAMES = {0: 'Capped Cell', 1: 'Failed Cell', 2: 'Matured Cell', 3: 'Open Cell', 4: 'Semi-Matured Cell'}
|
| 8 |
+
MATURITY_MAP = {
|
| 9 |
+
'Open Cell': {'days': 10, 'percentage': 10},
|
| 10 |
+
'Capped Cell': {'days': 7, 'percentage': 40},
|
| 11 |
+
'Semi-Matured Cell': {'days': 5, 'percentage': 70},
|
| 12 |
+
'Matured Cell': {'days': 2, 'percentage': 95},
|
| 13 |
+
'Failed Cell': {'days': 0, 'percentage': 0}
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
def analyze(image):
|
| 17 |
+
results = model(image)
|
| 18 |
+
detections = []
|
| 19 |
+
distribution = {'open': 0, 'capped': 0, 'mature': 0, 'semiMature': 0, 'failed': 0}
|
| 20 |
+
|
| 21 |
+
for r in results:
|
| 22 |
+
if r.boxes is not None:
|
| 23 |
+
for i, box in enumerate(r.boxes):
|
| 24 |
+
cls = int(box.cls[0])
|
| 25 |
+
conf = float(box.conf[0])
|
| 26 |
+
x1, y1, x2, y2 = box.xyxy[0].tolist()
|
| 27 |
+
|
| 28 |
+
class_name = CLASS_NAMES.get(cls, 'Unknown')
|
| 29 |
+
maturity_info = MATURITY_MAP.get(class_name, {'days': 0, 'percentage': 0})
|
| 30 |
+
|
| 31 |
+
detections.append({
|
| 32 |
+
'id': i + 1,
|
| 33 |
+
'type': class_name,
|
| 34 |
+
'confidence': round(conf * 100),
|
| 35 |
+
'bbox': [int(x1), int(y1), int(x2-x1), int(y2-y1)],
|
| 36 |
+
'percentage': maturity_info['percentage'],
|
| 37 |
+
'estimatedHatchingDays': maturity_info['days']
|
| 38 |
+
})
|
| 39 |
+
|
| 40 |
+
if 'Semi-Matured' in class_name:
|
| 41 |
+
distribution['semiMature'] += 1
|
| 42 |
+
elif 'Matured' in class_name:
|
| 43 |
+
distribution['mature'] += 1
|
| 44 |
+
elif 'Capped' in class_name:
|
| 45 |
+
distribution['capped'] += 1
|
| 46 |
+
elif 'Open' in class_name:
|
| 47 |
+
distribution['open'] += 1
|
| 48 |
+
elif 'Failed' in class_name:
|
| 49 |
+
distribution['failed'] += 1
|
| 50 |
+
|
| 51 |
+
return json.dumps({
|
| 52 |
+
'totalQueenCells': len(detections),
|
| 53 |
+
'cells': detections,
|
| 54 |
+
'maturityDistribution': distribution
|
| 55 |
+
}, indent=2)
|
| 56 |
+
|
| 57 |
+
demo = gr.Interface(
|
| 58 |
+
fn=analyze,
|
| 59 |
+
inputs=gr.Image(type="numpy"),
|
| 60 |
+
outputs=gr.JSON(),
|
| 61 |
+
title="iBrood Queen Cell Analyzer"
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
demo.launch()
|
best-seg.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dd29def2ee1f0db481962a8080186f9ed8ad77acbfba15281a38f0532683ff99
|
| 3 |
+
size 45162038
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
ultralytics
|
| 3 |
+
opencv-python-headless
|
| 4 |
+
pillow
|
| 5 |
+
torch
|
| 6 |
+
torchvision
|