mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
moved files
This commit is contained in:
parent
0618fc05fd
commit
f4fc50680b
7 changed files with 1190 additions and 0 deletions
4
backend/app/requirements/dev.txt
Normal file
4
backend/app/requirements/dev.txt
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
pytest
|
||||
mock
|
||||
pytest-cov
|
||||
pytest-mock
|
||||
33
backend/app/requirements/requirements.txt
Normal file
33
backend/app/requirements/requirements.txt
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# Pandas and numpy
|
||||
numpy==2.1.2
|
||||
pandas==2.2.3
|
||||
pytz==2024.2
|
||||
six==1.16.0
|
||||
# tqdm
|
||||
tqdm==4.66.5
|
||||
# fastapi
|
||||
fastapi==0.115.2
|
||||
sqlalchemy==2.0.36
|
||||
pydantic-settings==2.6.0
|
||||
psycopg2-binary==2.9.10
|
||||
python-jose==3.3.0
|
||||
cryptography==43.0.3
|
||||
mangum==0.19.0
|
||||
# AWS
|
||||
boto3==1.35.44
|
||||
# ML, Data Science
|
||||
usaddress==0.5.11
|
||||
epc-api-python==1.0.2
|
||||
fuzzywuzzy==0.18.0
|
||||
python-Levenshtein==0.26.0
|
||||
textblob==0.18.0.post0
|
||||
msgpack==1.1.0
|
||||
scikit-learn==1.5.2
|
||||
cffi==1.15.1
|
||||
mip==1.15.0
|
||||
# Data
|
||||
pyarrow==17.0.0
|
||||
fastparquet==2024.5.0
|
||||
aiohttp==3.10.10
|
||||
# find my epc
|
||||
beautifulsoup4
|
||||
50
backend/docker/engine.Dockerfile
Normal file
50
backend/docker/engine.Dockerfile
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# Pull base image
|
||||
FROM python:3.11.10-slim-bullseye as build-image
|
||||
|
||||
# Set environment variables
|
||||
ENV PYTHONDONTWRITEBYTECODE 1
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
# Set work directory to the root of your project
|
||||
WORKDIR var/task/Model
|
||||
|
||||
# Install python dependencies
|
||||
COPY ./backend/requirements/requirements.txt ./requirements.txt
|
||||
# Install and clean up temp caches
|
||||
RUN pip install --upgrade pip \
|
||||
&& pip install -r backend/engine/requirements.txt && rm -rf /root/.cache
|
||||
|
||||
# Since we are not using a base AWS image, there is some additional setup required. We need to set up the runtime
|
||||
# interface client
|
||||
# https://docs.aws.amazon.com/lambda/latest/dg/python-image.html#python-image-clients
|
||||
# Additionally install the AWS Lambda RIC
|
||||
RUN pip install awslambdaric
|
||||
|
||||
# Second stage: "runtime-image"
|
||||
FROM python:3.11.10-slim-bullseye
|
||||
|
||||
# Create the extensions directory to avoid warnings with RIE
|
||||
RUN mkdir -p /opt/extensions
|
||||
|
||||
# Set work directory to the root of your project
|
||||
WORKDIR /var/task/Model
|
||||
|
||||
# Copy the python dependencies from the build-image
|
||||
COPY --from=build-image /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/
|
||||
|
||||
# Copy project files
|
||||
COPY ./backend/ ./backend
|
||||
COPY ./recommendations/ ./recommendations
|
||||
COPY ./utils/ ./utils/
|
||||
COPY ./etl/epc/ ./etl/epc/
|
||||
COPY ./etl/epc_clean/ ./etl/epc_clean/
|
||||
COPY ./etl/bill_savings/ ./etl/bill_savings/
|
||||
COPY ./etl/spatial/ ./etl/spatial/
|
||||
COPY ./BaseUtility.py ./BaseUtility.py
|
||||
COPY ./datatypes/ ./datatypes/
|
||||
COPY ./etl/find_my_epc/ ./etl/find_my_epc/
|
||||
|
||||
# Set the ENTRYPOINT to the AWS Lambda RIC and CMD to your function handler
|
||||
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
|
||||
# Define the handler location
|
||||
CMD ["backend.engine.handler.handler"]
|
||||
8
backend/engine/README.md
Normal file
8
backend/engine/README.md
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# Model Engine Lambda
|
||||
|
||||
This repository contains the code for the Model Engine Lambda, which is responsible for serving machine learning models
|
||||
in a serverless environment. The Lambda function is designed to handle requests for model inference and return the
|
||||
results to the client.
|
||||
|
||||
This service consumes an SQS queue and is triggered by messages sent to the queue. The Lambda function processes the
|
||||
messages, performs model inference, and sends the results back to the client.
|
||||
1050
backend/engine/engine.py
Normal file
1050
backend/engine/engine.py
Normal file
File diff suppressed because it is too large
Load diff
20
backend/engine/handler.py
Normal file
20
backend/engine/handler.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
import json
|
||||
import asyncio
|
||||
from backend.engine.engine import model_engine
|
||||
from backend.app.plan.schemas import PlanTriggerRequest
|
||||
from utils.logger import setup_logger
|
||||
|
||||
logger = setup_logger()
|
||||
|
||||
|
||||
def handler(event, context):
|
||||
"""
|
||||
Lambda handler that triggers the model engine for each SQS message.
|
||||
"""
|
||||
for record in event.get("Records", []):
|
||||
try:
|
||||
body_dict = json.loads(record["body"])
|
||||
payload = PlanTriggerRequest.model_validate(body_dict)
|
||||
asyncio.run(model_engine(payload))
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to process record: {e}")
|
||||
25
backend/engine/requirements.txt
Normal file
25
backend/engine/requirements.txt
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# Pandas and numpy
|
||||
numpy==2.1.2
|
||||
pandas==2.2.3
|
||||
pytz==2024.2
|
||||
six==1.16.0
|
||||
# tqdm
|
||||
tqdm==4.66.5
|
||||
# AWS
|
||||
boto3==1.35.44
|
||||
# ML, Data Science
|
||||
usaddress==0.5.11
|
||||
epc-api-python==1.0.2
|
||||
fuzzywuzzy==0.18.0
|
||||
python-Levenshtein==0.26.0
|
||||
textblob==0.18.0.post0
|
||||
msgpack==1.1.0
|
||||
scikit-learn==1.5.2
|
||||
cffi==1.15.1
|
||||
mip==1.15.0
|
||||
# Data
|
||||
pyarrow==17.0.0
|
||||
fastparquet==2024.5.0
|
||||
aiohttp==3.10.10
|
||||
# find my epc
|
||||
beautifulsoup4
|
||||
Loading…
Add table
Reference in a new issue