Emmanuel Frimpong Asante
commited on
Commit
·
c84994a
1
Parent(s):
2aeb5c4
update space
Browse files- .env +5 -0
- .gitignore +1 -0
- .idea/Generative_AI_with_poultry_disease_detection_system_v2.iml +7 -2
- .idea/git_toolbox_prj.xml +15 -0
- .idea/misc.xml +1 -1
- README.md +109 -1
- app.py +42 -1
- requirements.txt +7 -6
- services/utils.py +38 -0
- static/index.html +10 -0
- static/script.js +0 -0
- static/style.css +0 -0
.env
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# .env file
|
| 2 |
+
|
| 3 |
+
MONGO_URI="your_mongo_db_uri"
|
| 4 |
+
EMAIL_USER="your_email_username"
|
| 5 |
+
EMAIL_PASS="your_email_password"
|
.gitignore
CHANGED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.venv
|
.idea/Generative_AI_with_poultry_disease_detection_system_v2.iml
CHANGED
|
@@ -1,8 +1,13 @@
|
|
| 1 |
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
<module type="PYTHON_MODULE" version="4">
|
| 3 |
<component name="NewModuleRootManager">
|
| 4 |
-
<content url="file://$MODULE_DIR$"
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
<orderEntry type="sourceFolder" forTests="false" />
|
| 7 |
</component>
|
|
|
|
|
|
|
|
|
|
| 8 |
</module>
|
|
|
|
| 1 |
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
<module type="PYTHON_MODULE" version="4">
|
| 3 |
<component name="NewModuleRootManager">
|
| 4 |
+
<content url="file://$MODULE_DIR$">
|
| 5 |
+
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
| 6 |
+
</content>
|
| 7 |
+
<orderEntry type="jdk" jdkName="Python 3.12 (Generative_AI_with_poultry_disease_detection_system_v2)" jdkType="Python SDK" />
|
| 8 |
<orderEntry type="sourceFolder" forTests="false" />
|
| 9 |
</component>
|
| 10 |
+
<component name="PackageRequirementsSettings">
|
| 11 |
+
<option name="removeUnused" value="true" />
|
| 12 |
+
</component>
|
| 13 |
</module>
|
.idea/git_toolbox_prj.xml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="GitToolBoxProjectSettings">
|
| 4 |
+
<option name="commitMessageIssueKeyValidationOverride">
|
| 5 |
+
<BoolValueOverride>
|
| 6 |
+
<option name="enabled" value="true" />
|
| 7 |
+
</BoolValueOverride>
|
| 8 |
+
</option>
|
| 9 |
+
<option name="commitMessageValidationEnabledOverride">
|
| 10 |
+
<BoolValueOverride>
|
| 11 |
+
<option name="enabled" value="true" />
|
| 12 |
+
</BoolValueOverride>
|
| 13 |
+
</option>
|
| 14 |
+
</component>
|
| 15 |
+
</project>
|
.idea/misc.xml
CHANGED
|
@@ -3,5 +3,5 @@
|
|
| 3 |
<component name="Black">
|
| 4 |
<option name="sdkName" value="Python 3.12 (Generative_AI_with_poultry)" />
|
| 5 |
</component>
|
| 6 |
-
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (
|
| 7 |
</project>
|
|
|
|
| 3 |
<component name="Black">
|
| 4 |
<option name="sdkName" value="Python 3.12 (Generative_AI_with_poultry)" />
|
| 5 |
</component>
|
| 6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.12 (Generative_AI_with_poultry_disease_detection_system_v2)" project-jdk-type="Python SDK" />
|
| 7 |
</project>
|
README.md
CHANGED
|
@@ -8,4 +8,112 @@ pinned: false
|
|
| 8 |
license: mit
|
| 9 |
---
|
| 10 |
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
license: mit
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# 🐔 Poultry Farming Assistance and Management System
|
| 12 |
+
|
| 13 |
+
This project integrates both a **Poultry Farming Assistance System** and a **Poultry Management System**. The system supports farm management tasks like health management, to-do lists, inventory, and notifications, while also providing intelligent assistance for disease detection and recommendations using AI.
|
| 14 |
+
|
| 15 |
+
## Project Features
|
| 16 |
+
1. **User Registration/Login System**
|
| 17 |
+
2. **Data Logging and Reporting (dashboards and exporting PDF and XLS)**
|
| 18 |
+
3. **Health Management and Disease Detection**
|
| 19 |
+
4. **Inventory Management**
|
| 20 |
+
5. **Poultry Farming Assistance (AI-based disease detection and recommendations)**
|
| 21 |
+
6. **Notification System via Email**
|
| 22 |
+
|
| 23 |
+
## System Components
|
| 24 |
+
|
| 25 |
+
### Poultry Farming Assistance System
|
| 26 |
+
- AI-based disease detection using machine learning models (e.g., `Final_Chicken_disease_model.h5`).
|
| 27 |
+
- Health monitoring and suggestions for poultry care.
|
| 28 |
+
- Fecal image analysis to detect common poultry diseases.
|
| 29 |
+
- Generate actionable insights based on poultry health data.
|
| 30 |
+
|
| 31 |
+
### Poultry Management System
|
| 32 |
+
- **To-Do List Management**: Manage daily farm tasks and activities.
|
| 33 |
+
- **Inventory Management**: Track and manage feed, medicines, and other supplies.
|
| 34 |
+
- **Health Records**: Log poultry health issues, treatments, and disease outbreaks.
|
| 35 |
+
- **Group Management**: Farmers can join groups, and admins can create and share to-do lists across groups.
|
| 36 |
+
- **Reporting**: Generate reports on farm performance, health metrics, and more.
|
| 37 |
+
|
| 38 |
+
## Use Cases
|
| 39 |
+
- **Poultry Farmer**: Can sign up, log in, access disease detection tools, complete to-do lists, view health reports, and receive notifications.
|
| 40 |
+
- **Poultry Farm Admin**: Can create and assign tasks, manage inventory, track group activities, and monitor health conditions across the farm.
|
| 41 |
+
|
| 42 |
+
## 📋 Development To-Do Checklist
|
| 43 |
+
|
| 44 |
+
### 1. Setup and Configuration
|
| 45 |
+
- [x] Set up a virtual environment (e.g., `venv`, `conda`) for the project.
|
| 46 |
+
- [x] Install necessary Python packages: `FastAPI`, `AdminLTE`, `MongoDB`, `TensorFlow`, `Keras`, `pymongo`, `transformers`, etc.
|
| 47 |
+
- [x] Configure MongoDB connection and test basic CRUD operations with MongoDB.
|
| 48 |
+
- [x] Set up environment variables for MongoDB URI, email credentials, and other sensitive data.
|
| 49 |
+
|
| 50 |
+
### 2. Authentication System
|
| 51 |
+
- [ ] Build the user registration system (Poultry Farmer, Poultry Admin).
|
| 52 |
+
- [ ] Implement login and logout functionality using JWT.
|
| 53 |
+
- [ ] Set up password encryption (e.g., `bcrypt`) for secure storage.
|
| 54 |
+
- [ ] Implement session management and token validation.
|
| 55 |
+
|
| 56 |
+
### 3. Poultry Farming Assistance System
|
| 57 |
+
- [ ] Integrate poultry disease detection model (`Final_Chicken_disease_model.h5`).
|
| 58 |
+
- [ ] Create an image preprocessing pipeline for disease detection.
|
| 59 |
+
- [ ] Build routes to upload and analyze poultry fecal images.
|
| 60 |
+
- [ ] Develop health-related notifications and treatment suggestions.
|
| 61 |
+
- [ ] Implement real-time health monitoring and alert system for farmers.
|
| 62 |
+
|
| 63 |
+
### 4. To-Do List Management
|
| 64 |
+
- [ ] Create MongoDB schema for to-do lists (`todo_list.py`).
|
| 65 |
+
- [ ] Implement routes and controllers for farmers to view and complete to-do lists.
|
| 66 |
+
- [ ] Implement routes and controllers for admins to create and share to-do lists.
|
| 67 |
+
- [ ] Design **AdminLTE 4**-based UI for displaying and managing to-do lists.
|
| 68 |
+
|
| 69 |
+
### 5. Data Logging and Reporting
|
| 70 |
+
- [ ] Develop a data logging system for tracking activities.
|
| 71 |
+
- [ ] Set up reporting dashboards using **AdminLTE** (instead of Shiny).
|
| 72 |
+
- [ ] Implement export functionality for data as PDF and XLS.
|
| 73 |
+
- [ ] Integrate data visualization tools for real-time reporting and insights.
|
| 74 |
+
|
| 75 |
+
### 6. Health Management
|
| 76 |
+
- [ ] Create MongoDB schema for storing poultry health records (`health_record.py`).
|
| 77 |
+
- [ ] Integrate the poultry disease detection model with health management.
|
| 78 |
+
- [ ] Develop an **AdminLTE** dashboard for tracking health issues and disease management.
|
| 79 |
+
- [ ] Implement health-related notifications and treatment suggestions for farmers.
|
| 80 |
+
|
| 81 |
+
### 7. Inventory Management
|
| 82 |
+
- [ ] Build MongoDB schema for inventory management (`inventory.py`).
|
| 83 |
+
- [ ] Develop routes for adding, updating, and deleting inventory items.
|
| 84 |
+
- [ ] Create an **AdminLTE** dashboard for tracking inventory levels and status.
|
| 85 |
+
- [ ] Set up alerts for low stock levels via email notifications.
|
| 86 |
+
|
| 87 |
+
### 8. Notification System
|
| 88 |
+
- [ ] Set up an email service for sending notifications to users (e.g., `smtplib` or `nodemailer`).
|
| 89 |
+
- [ ] Implement notification triggers for the following:
|
| 90 |
+
- [ ] To-do list completion.
|
| 91 |
+
- [ ] Health alerts and treatment recommendations.
|
| 92 |
+
- [ ] Inventory updates and low stock alerts.
|
| 93 |
+
- [ ] Test email notification system for various scenarios.
|
| 94 |
+
|
| 95 |
+
### 9. Group Management
|
| 96 |
+
- [ ] Create MongoDB schema for group management (`group.py`).
|
| 97 |
+
- [ ] Allow farm admins to create and delete groups.
|
| 98 |
+
- [ ] Allow poultry farmers to join groups.
|
| 99 |
+
- [ ] Implement group sharing functionalities (e.g., sharing to-do lists across groups).
|
| 100 |
+
|
| 101 |
+
### 10. Testing and Debugging
|
| 102 |
+
- [ ] Write unit tests for each module (authentication, to-do lists, health management, inventory, notifications).
|
| 103 |
+
- [ ] Conduct integration testing to ensure all components work together.
|
| 104 |
+
- [ ] Debug issues related to MongoDB transactions, AdminLTE dashboards, and TensorFlow model predictions.
|
| 105 |
+
|
| 106 |
+
### 11. Deployment
|
| 107 |
+
- [ ] Deploy the system on Hugging Face Spaces.
|
| 108 |
+
- [ ] Configure the production environment (e.g., environment variables, security settings).
|
| 109 |
+
- [ ] Set up a continuous integration/continuous deployment (CI/CD) pipeline for automatic testing and deployment.
|
| 110 |
+
|
| 111 |
+
---
|
| 112 |
+
|
| 113 |
+
## Future Enhancements (Backlog)
|
| 114 |
+
- [ ] Add mobile app support for poultry farmers using `Flutter`.
|
| 115 |
+
- [ ] Implement AI-based inventory prediction for restocking supplies.
|
| 116 |
+
- [ ] Enable multi-language support for different regions.
|
| 117 |
+
- [ ] Introduce additional disease models for enhanced health management.
|
| 118 |
+
|
| 119 |
+
---
|
app.py
CHANGED
|
@@ -1,7 +1,48 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
app = FastAPI()
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
@app.get("/")
|
| 6 |
def greet_json():
|
| 7 |
return {"Hello": "World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Depends, HTTPException
|
| 2 |
+
from pymongo import MongoClient
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import os
|
| 5 |
+
import uvicorn
|
| 6 |
|
| 7 |
+
# Load environment variables
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
# Initialize FastAPI app
|
| 11 |
app = FastAPI()
|
| 12 |
|
| 13 |
+
# MongoDB Configuration
|
| 14 |
+
MONGO_URI = os.getenv("MONGO_URI")
|
| 15 |
+
client = MongoClient(MONGO_URI)
|
| 16 |
+
db = client.get_database("poultry_management")
|
| 17 |
+
|
| 18 |
+
# Dependency to get the MongoDB database
|
| 19 |
+
def get_db():
|
| 20 |
+
return db
|
| 21 |
+
|
| 22 |
+
# Root route
|
| 23 |
@app.get("/")
|
| 24 |
def greet_json():
|
| 25 |
return {"Hello": "World!"}
|
| 26 |
+
|
| 27 |
+
# Example route for testing MongoDB connection
|
| 28 |
+
@app.get("/test_db")
|
| 29 |
+
def test_db_connection(db=Depends(get_db)):
|
| 30 |
+
try:
|
| 31 |
+
db.test.insert_one({"test": "connection"})
|
| 32 |
+
return {"status": "Connection Successful", "message": "Document inserted!"}
|
| 33 |
+
except Exception as e:
|
| 34 |
+
raise HTTPException(status_code=500, detail=f"Database connection error: {e}")
|
| 35 |
+
|
| 36 |
+
# Placeholder for authentication routes
|
| 37 |
+
# from routes.authentication import auth_router # Uncomment when routes are ready
|
| 38 |
+
# app.include_router(auth_router, prefix="/auth")
|
| 39 |
+
|
| 40 |
+
# Placeholder for other routes
|
| 41 |
+
# from routes.todo import todo_router # Uncomment when routes are ready
|
| 42 |
+
# from routes.health import health_router # Uncomment when routes are ready
|
| 43 |
+
# app.include_router(todo_router, prefix="/todos")
|
| 44 |
+
# app.include_router(health_router, prefix="/health")
|
| 45 |
+
|
| 46 |
+
# Main entry point for running the application
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
|
requirements.txt
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
-
fastapi
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
|
|
|
|
|
| 1 |
+
fastapi~=0.115.4
|
| 2 |
+
passlib~=1.7.4
|
| 3 |
+
pydantic~=2.9.2
|
| 4 |
+
pymongo~=4.9.2
|
| 5 |
+
pyjwt~=2.9.0
|
| 6 |
+
python-dotenv~=1.0.1
|
| 7 |
+
uvicorn~=0.32.0
|
services/utils.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# services/utils.py
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
+
from pymongo import MongoClient
|
| 6 |
+
from pymongo.errors import ConnectionFailure, OperationFailure
|
| 7 |
+
|
| 8 |
+
# Load environment variables from .env
|
| 9 |
+
load_dotenv()
|
| 10 |
+
|
| 11 |
+
# MongoDB Connection URI
|
| 12 |
+
MONGO_URI = os.getenv("MONGO_URI")
|
| 13 |
+
|
| 14 |
+
# Initialize MongoDB client and database connection
|
| 15 |
+
class MongoDB:
|
| 16 |
+
def __init__(self, uri: str, db_name: str):
|
| 17 |
+
self.client = MongoClient(uri)
|
| 18 |
+
self.db = self.client[db_name]
|
| 19 |
+
|
| 20 |
+
def test_connection(self) -> str:
|
| 21 |
+
"""Tests MongoDB connection by performing a basic operation."""
|
| 22 |
+
try:
|
| 23 |
+
self.db.test_collection.insert_one({"status": "connection_test"})
|
| 24 |
+
return "Connection successful: Test document inserted!"
|
| 25 |
+
except (ConnectionFailure, OperationFailure) as e:
|
| 26 |
+
return f"Database connection error: {e}"
|
| 27 |
+
|
| 28 |
+
def get_collection(self, collection_name: str):
|
| 29 |
+
"""Fetches a MongoDB collection."""
|
| 30 |
+
return self.db[collection_name]
|
| 31 |
+
|
| 32 |
+
# Instantiate MongoDB with URI and database name
|
| 33 |
+
mongo_instance = MongoDB(uri=MONGO_URI, db_name="poultry_management")
|
| 34 |
+
|
| 35 |
+
def test_db_connection():
|
| 36 |
+
"""Tests the database connection and prints result."""
|
| 37 |
+
result = mongo_instance.test_connection()
|
| 38 |
+
print(result)
|
static/index.html
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>Title</title>
|
| 6 |
+
</head>
|
| 7 |
+
<body>
|
| 8 |
+
|
| 9 |
+
</body>
|
| 10 |
+
</html>
|
static/script.js
ADDED
|
File without changes
|
static/style.css
ADDED
|
File without changes
|