Spaces:
Runtime error
Runtime error
Download app.py from Deepthii/PlantDiseaseDetection: direct link, hf CLI and curl.
- Browser
- Download file 837 Bytes
-
https://huggingface.co/spaces/Deepthii/PlantDiseaseDetection/resolve/main/app.py
- Command line
-
hf download hf://spaces/Deepthii/PlantDiseaseDetection/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Deepthii/PlantDiseaseDetection/resolve/main/app.py
837 Bytes
| from fastai.vision.all import * | |
| import gradio as gr | |
| import re | |
| # Custom function to remove underscores from label names | |
| def custom_parent_label(o): | |
| return re.sub(r'_', ' ', parent_label(o)) | |
| learn = load_learner('plant.pkl') | |
| def classify_image(img): | |
| pred,index,probs=learn.predict(img) | |
| words_in_pred = pred.split() | |
| # if len(words_in_pred) > 1: | |
| # words_in_pred.pop(0) | |
| # result_string = ' '.join(words_in_pred) | |
| probs_list = probs.tolist() # Convert TensorBase to Python list | |
| index_integer = index.item() if index.numel() > 0 else 0 | |
| pred_prob = probs_list[index_integer] if probs_list else None | |
| return {pred: pred_prob} | |
| image=gr.inputs.Image(shape=(192, 192)) | |
| label=gr.outputs.Label() | |
| interface=gr.Interface(fn=classify_image, inputs=image, outputs=label) | |
| interface.launch(inline=False) | |