Menasha123/gvisions
0
๐ฟ Plant Disease Detection API
A Flask-based API for predicting plant diseases from images or numerical features using a pre-trained deep learning model. It also supports storing geolocation data related to detected diseases in Firebase Firestore.
๐ Features
- Predict plant diseases from uploaded leaf images.
- Predict diseases based on numeric features.
- Store disease name and associated geolocations.
- Save results to Firebase Firestore.
- Supports basic error handling and logging.
๐ ๏ธ Setup
1. Clone the Repository
git clone https://github.com/your-username/plant-disease-api.git
cd plant-disease-api2. Install Dependencies
pip install -r requirements.txtKey Libraries:
- Flask
- TensorFlow
- NumPy
- Firebase Admin SDK
3. Prepare Your Files
- Place your trained model in the root directory as
model.h5. - Include your Firebase service account JSON as
./serviceAccountKey.json.
๐ฆ API Endpoints
/
Method: GET Description: Returns the home page (index.html).
/predict-image
Method: POST Content-Type: multipart/form-data Description: Predicts disease from an uploaded image.
Form Data:
file: image file (jpg/png)
Response:
{
"predicted_class": "Mosaic Virus Disease",
"confidence": 0.97,
"all_predictions": {
"Healthy Leaf": 0.01,
...
}
}Note: After prediction, the disease name is stored in memory to be associated with geolocation data.
/geolocation
Method: POST Content-Type: application/json Description: Stores geolocation data (latitude & longitude). If a disease is already predicted, it saves both to Firestore.
Request Body:
{
"latitude": 12.9716,
"longitude": 77.5946
}Response:
{
"message": "Geolocation data stored successfully"
}๐ง Internal Functions
predict_disease(img_data)
- Preprocesses the image.
- Predicts disease using the loaded model.
- Returns the class label, confidence, and full class probabilities.
save_disease_locations()
- Combines the disease and geolocation data.
- Saves the information to Firestore in the structure:
{
"Disease Name": {
"coordinates": {
"01": {"latitude": 12.34, "longitude": 56.78},
"02": ...
}
}
}๐ฅ Firebase Integration
- Initialized using
serviceAccountKey.json. - Stores data in
disease_coordinatescollection. - Automatically merges new geolocations with existing ones.
โ Error Handling
404 Not Found500 Server Error- Custom validation for input types
๐งช Running the App
python app.pyVisit: http://127.0.0.1:5000
๐งผ Utility Functions
clean_label(label): Removes "Augmented" prefix.preprocess_image(img_data): Resizes and preprocesses images using ResNet50 conventions.
