Spaces:
Running
Running
Create inference/inference.py
Browse files- inference/inference.py +18 -0
inference/inference.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
|
3 |
+
def load_disease_pipeline(model_id):
|
4 |
+
return pipeline(
|
5 |
+
task="image-classification",
|
6 |
+
model=model_id,
|
7 |
+
top_k=3
|
8 |
+
)
|
9 |
+
|
10 |
+
def diagnose(image, pipe):
|
11 |
+
results = pipe(image)
|
12 |
+
preds = [f"{r['label']} ({r['score']*100:.1f}%)" for r in results]
|
13 |
+
advice = (
|
14 |
+
"No disease detected—maintain standard crop care."
|
15 |
+
if "healthy" in results[0]['label'].lower()
|
16 |
+
else f"Disease detected: {results[0]['label']}. Apply targeted treatment."
|
17 |
+
)
|
18 |
+
return preds, advice
|