Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- .gitattributes +34 -1
- .gitignore +0 -1
- README.md +6 -47
- app.py +58 -53
- potato_disease_model.h5 +3 -0
- requirements.txt +0 -0
.gitattributes
CHANGED
|
@@ -1,2 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
.gitignore
CHANGED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
myenv
|
|
|
|
|
|
README.md
CHANGED
|
@@ -1,53 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title: Potato
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
This model detects diseases in potato leaves, classifying them into three categories:
|
| 15 |
-
- Early Blight
|
| 16 |
-
- Late Blight
|
| 17 |
-
- Healthy
|
| 18 |
-
|
| 19 |
-
## Usage
|
| 20 |
-
|
| 21 |
-
### Web Interface
|
| 22 |
-
The model is available through a Gradio web interface. Simply run:
|
| 23 |
-
```bash
|
| 24 |
-
python app.py
|
| 25 |
-
```
|
| 26 |
-
Then open your browser to `http://localhost:7860`
|
| 27 |
-
|
| 28 |
-
### API Usage
|
| 29 |
-
You can also use the model through an API endpoint:
|
| 30 |
-
|
| 31 |
-
```python
|
| 32 |
-
import requests
|
| 33 |
-
|
| 34 |
-
# Replace with your Hugging Face Space URL
|
| 35 |
-
API_URL = "https://your-space-url.hf.space/predict"
|
| 36 |
-
|
| 37 |
-
# Load your image
|
| 38 |
-
with open("path_to_image.jpg", "rb") as f:
|
| 39 |
-
image_data = f.read()
|
| 40 |
-
|
| 41 |
-
# Make prediction
|
| 42 |
-
response = requests.post(API_URL, files={"file": image_data})
|
| 43 |
-
prediction = response.json()["prediction"]
|
| 44 |
-
print(f"Prediction: {prediction}")
|
| 45 |
-
```
|
| 46 |
-
|
| 47 |
-
## Model Details
|
| 48 |
-
- Input: 256x256 RGB image of a potato leaf
|
| 49 |
-
- Output: Classification into one of three categories
|
| 50 |
-
- Model: TensorFlow/Keras model
|
| 51 |
-
|
| 52 |
-
## Requirements
|
| 53 |
-
See `requirements.txt` for all dependencies.
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Potato
|
| 3 |
+
emoji: 🚀
|
| 4 |
+
colorFrom: indigo
|
| 5 |
+
colorTo: indigo
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.29.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,61 +1,66 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from fastapi import FastAPI, File, UploadFile
|
| 3 |
-
from tensorflow.keras.models import load_model
|
| 4 |
-
from tensorflow.keras.preprocessing import image
|
| 5 |
import numpy as np
|
|
|
|
|
|
|
| 6 |
from PIL import Image
|
| 7 |
-
import
|
| 8 |
-
import
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Gradio Interface
|
| 49 |
interface = gr.Interface(
|
| 50 |
-
fn=
|
| 51 |
-
inputs=gr.Image(type="pil"),
|
| 52 |
-
outputs=gr.Label(),
|
| 53 |
-
title="
|
| 54 |
-
description="Upload a potato leaf
|
| 55 |
)
|
| 56 |
|
| 57 |
-
|
| 58 |
-
app = gr.mount_gradio_app(app, interface, path="/")
|
| 59 |
-
|
| 60 |
-
if __name__ == "__main__":
|
| 61 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
+
from tensorflow.keras.models import load_model
|
| 4 |
+
from tensorflow.keras.preprocessing.image import img_to_array
|
| 5 |
from PIL import Image
|
| 6 |
+
import requests
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
# Constants
|
| 10 |
+
MODEL_URL = "https://storage.googleapis.com/potato-model-detection/potato_disease_model.h5"
|
| 11 |
+
MODEL_PATH = "potato_disease_model.h5"
|
| 12 |
+
CLASS_NAMES = ["Early Blight", "Late Blight", "Healthy"]
|
| 13 |
+
|
| 14 |
+
def download_model():
|
| 15 |
+
"""Download the model if not already available locally."""
|
| 16 |
+
if not os.path.exists(MODEL_PATH):
|
| 17 |
+
print("Downloading model...")
|
| 18 |
+
response = requests.get(MODEL_URL)
|
| 19 |
+
if response.status_code == 200:
|
| 20 |
+
with open(MODEL_PATH, 'wb') as f:
|
| 21 |
+
f.write(response.content)
|
| 22 |
+
print("Model downloaded successfully.")
|
| 23 |
+
else:
|
| 24 |
+
raise Exception(f"Failed to download model: HTTP {response.status_code}")
|
| 25 |
+
|
| 26 |
+
def load_disease_model(path):
|
| 27 |
+
"""Load the trained Keras model."""
|
| 28 |
+
try:
|
| 29 |
+
return load_model(path)
|
| 30 |
+
except Exception as e:
|
| 31 |
+
raise RuntimeError(f"Error loading model: {e}")
|
| 32 |
+
|
| 33 |
+
def preprocess_image(image):
|
| 34 |
+
"""Convert and resize image for model input."""
|
| 35 |
+
image = image.convert("RGB").resize((256, 256))
|
| 36 |
+
img_array = img_to_array(image) / 255.0
|
| 37 |
+
return np.expand_dims(img_array, axis=0)
|
| 38 |
+
|
| 39 |
+
def predict(image):
|
| 40 |
+
"""Make a prediction and return class probabilities."""
|
| 41 |
+
try:
|
| 42 |
+
img_array = preprocess_image(image)
|
| 43 |
+
prediction = model.predict(img_array)[0]
|
| 44 |
+
|
| 45 |
+
# Normalize if not already
|
| 46 |
+
if not np.isclose(np.sum(prediction), 1.0, atol=1e-2):
|
| 47 |
+
prediction = prediction / np.sum(prediction)
|
| 48 |
+
|
| 49 |
+
return {CLASS_NAMES[i]: round(float(pred), 4) for i, pred in enumerate(prediction)}
|
| 50 |
+
except Exception as e:
|
| 51 |
+
return {"error": str(e)}
|
| 52 |
+
|
| 53 |
+
# Ensure model is ready
|
| 54 |
+
download_model()
|
| 55 |
+
model = load_disease_model(MODEL_PATH)
|
| 56 |
|
| 57 |
# Gradio Interface
|
| 58 |
interface = gr.Interface(
|
| 59 |
+
fn=predict,
|
| 60 |
+
inputs=gr.Image(type="pil", label="Upload Leaf Image"),
|
| 61 |
+
outputs=gr.Label(num_top_classes=3, label="Prediction"),
|
| 62 |
+
title="otato Leaf Disease Detection",
|
| 63 |
+
description="Upload an image of a potato leaf to detect Early Blight, Late Blight, or Healthy condition.",
|
| 64 |
)
|
| 65 |
|
| 66 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
potato_disease_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a0ea2599967005ff4ddec606ab9693d2823ccb4cd7cfe33bc293887d1c060ba6
|
| 3 |
+
size 712308576
|
requirements.txt
CHANGED
|
Binary files a/requirements.txt and b/requirements.txt differ
|
|
|