|
|
|
|
|
|
|
|
import os |
|
|
import time |
|
|
import logging |
|
|
from fastapi import FastAPI, Request, HTTPException, BackgroundTasks |
|
|
from fastapi.templating import Jinja2Templates |
|
|
from fastapi.responses import HTMLResponse |
|
|
from fastapi.staticfiles import StaticFiles |
|
|
import tensorflow as tf |
|
|
from routes.authentication import auth_router |
|
|
|
|
|
|
|
|
|
|
|
from huggingface_hub import login |
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO) |
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
gpu_devices = tf.config.list_physical_devices('GPU') |
|
|
if gpu_devices: |
|
|
logger.info(f"GPUs available: {len(gpu_devices)}") |
|
|
else: |
|
|
logger.info("No GPUs available. Using CPU.") |
|
|
|
|
|
|
|
|
app = FastAPI() |
|
|
templates = Jinja2Templates(directory="templates") |
|
|
|
|
|
|
|
|
static_dir = "static" |
|
|
if os.path.isdir(static_dir): |
|
|
app.mount("/static", StaticFiles(directory=static_dir), name="static") |
|
|
logger.info("Mounted static directory at /static") |
|
|
else: |
|
|
logger.error("Static directory not found.") |
|
|
raise HTTPException(status_code=500, detail="Static directory not found.") |
|
|
|
|
|
|
|
|
HF_TOKEN = os.environ.get('HF_Token') |
|
|
if HF_TOKEN: |
|
|
login(token=HF_TOKEN, add_to_git_credential=True) |
|
|
else: |
|
|
logger.warning("Hugging Face token not found in environment variables.") |
|
|
|
|
|
|
|
|
|
|
|
app.include_router(auth_router, prefix="/auth", tags=["Authentication"]) |
|
|
|
|
|
|
|
|
|
|
|
@app.get("/", response_class=HTMLResponse) |
|
|
async def landing_page(request: Request): |
|
|
"""Render the landing page template.""" |
|
|
logger.info("Landing page accessed") |
|
|
return templates.TemplateResponse("landing.html", {"request": request}) |
|
|
|
|
|
|
|
|
health_metrics = { |
|
|
"weight_loss_percentage": 6, |
|
|
"mortality_rate": 1, |
|
|
"reduced_feed_intake_percentage": 12 |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|