File size: 544 Bytes
6f80c37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from transformers import pipeline

def load_disease_pipeline(model_id):
    return pipeline(
        task="image-classification",
        model=model_id,
        top_k=3
    )

def diagnose(image, pipe):
    results = pipe(image)
    preds = [f"{r['label']} ({r['score']*100:.1f}%)" for r in results]
    advice = (
        "No disease detected—maintain standard crop care." 
        if "healthy" in results[0]['label'].lower() 
        else f"Disease detected: {results[0]['label']}. Apply targeted treatment."
    )
    return preds, advice