CoolFace
Apppublic

Menasha123/gvisions

sourceHugging Facecc-by-4.0updated 1y agoView on Hugging Face
0likes
App README

๐ŸŒฟ 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

bash
git clone https://github.com/your-username/plant-disease-api.git
cd plant-disease-api

2. Install Dependencies

bash
pip install -r requirements.txt

Key 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:

json
{
  "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:

json
{
  "latitude": 12.9716,
  "longitude": 77.5946
}

Response:

json
{
  "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:
json
{
  "Disease Name": {
    "coordinates": {
      "01": {"latitude": 12.34, "longitude": 56.78},
      "02": ...
    }
  }
}

๐Ÿ”ฅ Firebase Integration

  • โ€”Initialized using serviceAccountKey.json.
  • โ€”Stores data in disease_coordinates collection.
  • โ€”Automatically merges new geolocations with existing ones.

โ— Error Handling

  • โ€”404 Not Found
  • โ€”500 Server Error
  • โ€”Custom validation for input types

๐Ÿงช Running the App

bash
python app.py

Visit: 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.