Emmanuel Frimpong Asante
commited on
Commit
·
54d88d7
1
Parent(s):
7286714
update space
Browse files- .env +2 -1
- Dockerfile +1 -1
- app.py +4 -1
- requirements.txt +1 -1
- services/disease_detection_service.py +33 -18
.env
CHANGED
@@ -10,5 +10,6 @@ SMTP_PASSWORD="your_email_password"
|
|
10 |
FROM_EMAIL="your_from_email_address"
|
11 |
|
12 |
|
13 |
-
# TensorFlow
|
14 |
TF_ENABLE_ONEDNN_OPTS=0
|
|
|
|
10 |
FROM_EMAIL="your_from_email_address"
|
11 |
|
12 |
|
13 |
+
# TensorFlow Settings
|
14 |
TF_ENABLE_ONEDNN_OPTS=0
|
15 |
+
TF_FORCE_GPU_ALLOW_GROWTH=true
|
Dockerfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
# Use the official Python 3.
|
2 |
FROM python:3.9
|
3 |
|
4 |
# Create and set up a user
|
|
|
1 |
+
# Use the official Python 3.9 image
|
2 |
FROM python:3.9
|
3 |
|
4 |
# Create and set up a user
|
app.py
CHANGED
@@ -11,6 +11,7 @@ import tensorflow as tf
|
|
11 |
from routes.authentication import auth_router
|
12 |
from routes.disease_detection import disease_router
|
13 |
from routes.health_dashboard import dashboard_router
|
|
|
14 |
from services.health_monitoring_service import evaluate_health_data, get_health_alerts, send_alerts
|
15 |
from huggingface_hub import login
|
16 |
|
@@ -44,7 +45,9 @@ if os.path.isdir(static_dir):
|
|
44 |
else:
|
45 |
logger.error("Static directory not found.")
|
46 |
raise HTTPException(status_code=500, detail="Static directory not found.")
|
47 |
-
|
|
|
|
|
48 |
# Include routers for authentication, disease detection, and health dashboard
|
49 |
app.include_router(auth_router, prefix="/auth", tags=["Authentication"])
|
50 |
app.include_router(disease_router, prefix="/disease", tags=["Disease Detection"])
|
|
|
11 |
from routes.authentication import auth_router
|
12 |
from routes.disease_detection import disease_router
|
13 |
from routes.health_dashboard import dashboard_router
|
14 |
+
from services.disease_detection_service import load_disease_model, load_llama_model
|
15 |
from services.health_monitoring_service import evaluate_health_data, get_health_alerts, send_alerts
|
16 |
from huggingface_hub import login
|
17 |
|
|
|
45 |
else:
|
46 |
logger.error("Static directory not found.")
|
47 |
raise HTTPException(status_code=500, detail="Static directory not found.")
|
48 |
+
# Load models at startup
|
49 |
+
disease_model = load_disease_model()
|
50 |
+
llama_model, llama_tokenizer = load_llama_model()
|
51 |
# Include routers for authentication, disease detection, and health dashboard
|
52 |
app.include_router(auth_router, prefix="/auth", tags=["Authentication"])
|
53 |
app.include_router(disease_router, prefix="/disease", tags=["Disease Detection"])
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
opencv-python
|
2 |
fastapi
|
3 |
passlib[bcrypt]
|
4 |
pydantic[email]
|
|
|
1 |
+
opencv-python-headless
|
2 |
fastapi
|
3 |
passlib[bcrypt]
|
4 |
pydantic[email]
|
services/disease_detection_service.py
CHANGED
@@ -38,24 +38,39 @@ if gpus:
|
|
38 |
else:
|
39 |
logger.info("Using CPU without mixed precision.")
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
|
60 |
# Disease mapping and treatment guidelines
|
61 |
name_disease = {0: 'Coccidiosis', 1: 'Healthy', 2: 'New Castle Disease', 3: 'Salmonella'}
|
|
|
38 |
else:
|
39 |
logger.info("Using CPU without mixed precision.")
|
40 |
|
41 |
+
|
42 |
+
# Model loading functions
|
43 |
+
def load_disease_model():
|
44 |
+
"""Load the disease detection model."""
|
45 |
+
try:
|
46 |
+
model_path = "models/Final_Chicken_disease_model.h5"
|
47 |
+
device = '/GPU:0' if gpu_devices else '/CPU:0'
|
48 |
+
with tf.device(device):
|
49 |
+
model = load_model(model_path, compile=True)
|
50 |
+
logger.info(f"Disease detection model loaded successfully on {device}.")
|
51 |
+
return model
|
52 |
+
except Exception as e:
|
53 |
+
logger.error(f"Error loading disease model: {e}")
|
54 |
+
raise RuntimeError("Failed to load disease detection model")
|
55 |
+
|
56 |
+
|
57 |
+
def load_llama_model():
|
58 |
+
"""Load the Llama 3.2 model for text generation."""
|
59 |
+
try:
|
60 |
+
model_name = "meta-llama/Llama-3.2-1B"
|
61 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
62 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
63 |
+
|
64 |
+
if tokenizer.pad_token is None:
|
65 |
+
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
|
66 |
+
model.resize_token_embeddings(len(tokenizer))
|
67 |
+
|
68 |
+
logger.info("Llama 3.2 model loaded successfully.")
|
69 |
+
return model, tokenizer
|
70 |
+
except Exception as e:
|
71 |
+
logger.error(f"Error loading Llama model: {e}")
|
72 |
+
raise RuntimeError("Failed to load Llama model")
|
73 |
+
|
74 |
|
75 |
# Disease mapping and treatment guidelines
|
76 |
name_disease = {0: 'Coccidiosis', 1: 'Healthy', 2: 'New Castle Disease', 3: 'Salmonella'}
|