Adding PlantDataApi
This commit is contained in:
parent
9d9f974416
commit
5222880624
5 changed files with 225 additions and 0 deletions
BIN
.DS_Store
vendored
Normal file
BIN
.DS_Store
vendored
Normal file
Binary file not shown.
170
READMEPlantAPI.md
Normal file
170
READMEPlantAPI.md
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
|
||||||
|
🌱 Plant Health & Identification API
|
||||||
|
|
||||||
|
An intelligent backend service built for our hackathon project. This API uses a dual-model AI system to analyze an image of a plant, first identifying its species and then assessing its health.
|
||||||
|
|
||||||
|
🚀 The Problem
|
||||||
|
|
||||||
|
Have you ever wondered what kind of plant you have or why its leaves are suddenly turning yellow? Our project aims to provide a simple, accessible answer. This repository contains the backend API that powers our application, capable of providing a comprehensive plant analysis from a single image.
|
||||||
|
|
||||||
|
🧠 The AI Pipeline
|
||||||
|
|
||||||
|
This API uses a two-stage process to analyze an image:
|
||||||
|
|
||||||
|
Species Identification: We use a custom-trained TensorFlow/Keras model, built on a MobileNetV2 architecture. This model was fine-tuned on a dataset of six specific plant types to achieve high accuracy in identifying which plant is in the image.
|
||||||
|
|
||||||
|
Health Assessment: Once the plant's species is known (e.g., "tomato"), we use OpenAI's powerful, open-source CLIP model. We dynamically generate text prompts like "a photo of a healthy tomato plant" or "a photo of a sick tomato plant with yellow spots" and ask CLIP which description best matches the image. This zero-shot approach allows for a flexible and nuanced understanding of the plant's health.
|
||||||
|
|
||||||
|
✨ Features
|
||||||
|
|
||||||
|
Identify 6 Plant Species: Accurately distinguishes between tomato, basil, mint, lettuce, rosemary, and strawberry.
|
||||||
|
|
||||||
|
Assess 4 Health States: Classifies plants as Healthy, Diseased, Dehydrated, or Dead.
|
||||||
|
|
||||||
|
Confidence Scores: Provides confidence levels for both the species identification and the health assessment.
|
||||||
|
|
||||||
|
Simple JSON API: Easy to integrate with any frontend or mobile application.
|
||||||
|
|
||||||
|
🛠️ Tech Stack
|
||||||
|
|
||||||
|
Backend Framework: Flask
|
||||||
|
|
||||||
|
AI / Machine Learning: TensorFlow (Keras), PyTorch, OpenAI CLIP
|
||||||
|
|
||||||
|
Image Processing: Pillow, OpenCV
|
||||||
|
|
||||||
|
Core Language: Python 3.10
|
||||||
|
|
||||||
|
🔌 API Documentation
|
||||||
|
|
||||||
|
This is the documentation for the main analysis endpoint.
|
||||||
|
|
||||||
|
Analyze a Plant Image
|
||||||
|
|
||||||
|
Endpoint: /analyze
|
||||||
|
|
||||||
|
Method: POST
|
||||||
|
|
||||||
|
Body: multipart/form-data
|
||||||
|
|
||||||
|
The request must contain a file field named image.
|
||||||
|
|
||||||
|
Successful Response (Status 200 OK)
|
||||||
|
|
||||||
|
The API will return a JSON object with the analysis.
|
||||||
|
|
||||||
|
Example Response:
|
||||||
|
|
||||||
|
Generated json
|
||||||
|
{
|
||||||
|
"plant_species": "tomato",
|
||||||
|
"identification_confidence": "97.45%",
|
||||||
|
"health_status": "Healthy",
|
||||||
|
"health_confidence": "89.12%",
|
||||||
|
"health_breakdown": {
|
||||||
|
"Healthy": 0.8912,
|
||||||
|
"Diseased": 0.0562,
|
||||||
|
"Dehydrated": 0.0421,
|
||||||
|
"Dead": 0.0105
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Field Descriptions:
|
||||||
|
|
||||||
|
Key Type Description
|
||||||
|
plant_species String The identified species of the plant.
|
||||||
|
identification_confidence String The model's confidence in the species identification.
|
||||||
|
health_status String The most likely health status of the plant.
|
||||||
|
health_confidence String The model's confidence in the health assessment.
|
||||||
|
health_breakdown Object A dictionary of raw probability scores for each health state.
|
||||||
|
Error Responses
|
||||||
|
|
||||||
|
If the request is missing an image, the API will return:
|
||||||
|
|
||||||
|
Status: 400 Bad Request
|
||||||
|
|
||||||
|
Body: {"error": "No image file provided"}
|
||||||
|
|
||||||
|
For any other server-side issues, the API will return:
|
||||||
|
|
||||||
|
Status: 500 Internal Server Error
|
||||||
|
|
||||||
|
Body: {"error": "An internal server error occurred."}
|
||||||
|
|
||||||
|
🖥️ How to Run Locally
|
||||||
|
|
||||||
|
To run this backend server on your own machine, follow these steps.
|
||||||
|
|
||||||
|
Clone the Repository:
|
||||||
|
|
||||||
|
Generated bash
|
||||||
|
git clone <repository-url>
|
||||||
|
cd <repository-name>/backend
|
||||||
|
IGNORE_WHEN_COPYING_START
|
||||||
|
content_copy
|
||||||
|
download
|
||||||
|
Use code with caution.
|
||||||
|
Bash
|
||||||
|
IGNORE_WHEN_COPYING_END
|
||||||
|
|
||||||
|
Create a Virtual Environment:
|
||||||
|
|
||||||
|
Generated bash
|
||||||
|
python3 -m venv venv
|
||||||
|
source venv/bin/activate
|
||||||
|
IGNORE_WHEN_COPYING_START
|
||||||
|
content_copy
|
||||||
|
download
|
||||||
|
Use code with caution.
|
||||||
|
Bash
|
||||||
|
IGNORE_WHEN_COPYING_END
|
||||||
|
|
||||||
|
Install Dependencies:
|
||||||
|
This can take a while as it will download TensorFlow and PyTorch.
|
||||||
|
|
||||||
|
Generated bash
|
||||||
|
pip install -r requirements.txt
|
||||||
|
IGNORE_WHEN_COPYING_START
|
||||||
|
content_copy
|
||||||
|
download
|
||||||
|
Use code with caution.
|
||||||
|
Bash
|
||||||
|
IGNORE_WHEN_COPYING_END
|
||||||
|
|
||||||
|
Place the Model:
|
||||||
|
Make sure you have the trained Keras model (BestModel.keras) inside the models/ directory.
|
||||||
|
|
||||||
|
Run the Server:
|
||||||
|
|
||||||
|
Generated bash
|
||||||
|
python app.py
|
||||||
|
IGNORE_WHEN_COPYING_START
|
||||||
|
content_copy
|
||||||
|
download
|
||||||
|
Use code with caution.
|
||||||
|
Bash
|
||||||
|
IGNORE_WHEN_COPYING_END
|
||||||
|
|
||||||
|
The API will now be running on your local machine at http://127.0.0.1:5000.
|
||||||
|
|
||||||
|
📁 Project Structure
|
||||||
|
Generated code
|
||||||
|
/backend
|
||||||
|
|-- app.py # The main Flask server and API logic.
|
||||||
|
|-- models/ # Folder for the trained Keras model.
|
||||||
|
| |-- BestModel.keras
|
||||||
|
|-- requirements.txt # Python dependencies.
|
||||||
|
|-- .gitignore # Files to be ignored by Git (like the venv).
|
||||||
|
IGNORE_WHEN_COPYING_START
|
||||||
|
content_copy
|
||||||
|
download
|
||||||
|
Use code with caution.
|
||||||
|
IGNORE_WHEN_COPYING_END
|
||||||
|
👥 Authors
|
||||||
|
|
||||||
|
[Your Name]
|
||||||
|
|
||||||
|
[Teammate's Name]
|
||||||
|
|
||||||
|
[Teammate's Name]
|
BIN
app.py
Normal file
BIN
app.py
Normal file
Binary file not shown.
BIN
models/BestModel.keras
Normal file
BIN
models/BestModel.keras
Normal file
Binary file not shown.
55
requirements.txt
Normal file
55
requirements.txt
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
absl-py==2.3.1
|
||||||
|
astunparse==1.6.3
|
||||||
|
blinker==1.9.0
|
||||||
|
certifi==2025.7.14
|
||||||
|
charset-normalizer==3.4.2
|
||||||
|
click==8.2.1
|
||||||
|
-e git+https://github.com/openai/CLIP.git@dcba3cb2e2827b402d2701e7e1c7d9fed8a20ef1#egg=clip
|
||||||
|
filelock==3.18.0
|
||||||
|
Flask==3.1.1
|
||||||
|
flatbuffers==25.2.10
|
||||||
|
fsspec==2025.7.0
|
||||||
|
ftfy==6.3.1
|
||||||
|
gast==0.6.0
|
||||||
|
google-pasta==0.2.0
|
||||||
|
grpcio==1.74.0
|
||||||
|
gunicorn==21.2.0
|
||||||
|
h5py==3.14.0
|
||||||
|
idna==3.10
|
||||||
|
itsdangerous==2.2.0
|
||||||
|
Jinja2==3.1.6
|
||||||
|
keras==3.11.1
|
||||||
|
libclang==18.1.1
|
||||||
|
Markdown==3.8.2
|
||||||
|
markdown-it-py==3.0.0
|
||||||
|
MarkupSafe==3.0.2
|
||||||
|
mdurl==0.1.2
|
||||||
|
ml_dtypes==0.5.3
|
||||||
|
mpmath==1.3.0
|
||||||
|
namex==0.1.0
|
||||||
|
networkx==3.4.2
|
||||||
|
numpy==2.1.3
|
||||||
|
opt_einsum==3.4.0
|
||||||
|
optree==0.17.0
|
||||||
|
packaging==25.0
|
||||||
|
pillow==11.3.0
|
||||||
|
protobuf==5.29.5
|
||||||
|
Pygments==2.19.2
|
||||||
|
regex==2025.7.34
|
||||||
|
requests==2.32.4
|
||||||
|
rich==14.1.0
|
||||||
|
six==1.17.0
|
||||||
|
sympy==1.14.0
|
||||||
|
tensorboard==2.19.0
|
||||||
|
tensorboard-data-server==0.7.2
|
||||||
|
tensorflow==2.19.0
|
||||||
|
tensorflow-io-gcs-filesystem==0.37.1
|
||||||
|
termcolor==3.1.0
|
||||||
|
torch==2.7.1
|
||||||
|
torchvision==0.22.1
|
||||||
|
tqdm==4.67.1
|
||||||
|
typing_extensions==4.14.1
|
||||||
|
urllib3==2.5.0
|
||||||
|
wcwidth==0.2.13
|
||||||
|
Werkzeug==3.1.3
|
||||||
|
wrapt==1.17.2
|
Loading…
Add table
Add a link
Reference in a new issue