Dacho688 commited on
Commit
2a97c34
·
0 Parent(s):

Initial commit

Browse files
.gitattributes ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
.github/workflows/sync_to_hf.yaml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync to Hugging Face hub
2
+ on:
3
+ push:
4
+ branches: [main]
5
+
6
+ # to run this workflow manually from the Actions tab
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+ sync-to-hub:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ with:
15
+ fetch-depth: 0
16
+ lfs: true
17
+ - name: Push to hub
18
+ env:
19
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
20
+ HF_USERNAME: ${{ vars.HF_USERNAME }}
21
+ HF_SPACE_NAME: ${{ vars.HF_SPACE_NAME}}
22
+ run: git push https://$HF_USERNAME:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${HF_SPACE_NAME} main
.gitignore ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .env
2
+ .vscode/
3
+ .venv/
4
+ __pycache__/
Dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Dockerfile
2
+ # Use a lightweight official Python image as the base
3
+ FROM python:3.12-slim
4
+ # Set the working directory inside the container
5
+ WORKDIR /app
6
+ # Copy the requirements file and install dependencies
7
+ COPY requirements.txt .
8
+ RUN pip install --no-cache-dir -r requirements.txt
9
+ # Copy the rest of your application code
10
+ COPY ./app .
11
+ # Expose the port your FastAPI application will run on
12
+ EXPOSE 7860
13
+ # Command to run the FastAPI application with Uvicorn
14
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
README.md ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: ML API
3
+ emoji: 🤖
4
+ colorFrom: blue
5
+ colorTo: gray
6
+ sdk: docker
7
+ app_port: 7860
8
+ pinned: false
9
+ ---
10
+
11
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app/app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+
3
+ from fastapi import FastAPI
4
+ from fastapi.responses import RedirectResponse
5
+ from pydantic import BaseModel
6
+ import joblib
7
+ import pandas as pd
8
+
9
+ app = FastAPI()
10
+ model = joblib.load("./pipeline.joblib")
11
+
12
+ class Input(BaseModel):
13
+ CUST_NBR: str
14
+ MENU_TYP_DESC: str
15
+ PYR_SEG_CD: str
16
+ DIV_NBR: str
17
+ WKLY_ORDERS: float
18
+ PERC_EB: float
19
+ AVG_WKLY_SALES: float
20
+ AVG_WKLY_CASES: float
21
+
22
+ class Output(BaseModel):
23
+ prediction: list[int]
24
+
25
+ @app.post("/predict", response_model=Output)
26
+ def predict(data: list[Input]) -> Output:
27
+ print(data)
28
+ data = [item.model_dump() for item in data]
29
+ data = pd.DataFrame(data)
30
+ prediction = model.predict(data).tolist()
31
+ return {"prediction":prediction}
32
+
33
+ @app.get("/")
34
+ def home():
35
+ return RedirectResponse(url="/docs", status_code=302)
app/pipeline.joblib ADDED
Binary file (6.33 kB). View file
 
app/request_test.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Thu Nov 20 17:00:22 2025
4
+
5
+ @author: dkondic
6
+ """
7
+ import requests
8
+
9
+ data = [
10
+ {"CUST_NBR":"1111",
11
+ "MENU_TYP_DESC":"MEXICAN",
12
+ "PYR_SEG_CD":"Education",
13
+ "DIV_NBR":"20",
14
+ "WKLY_ORDERS": 1,
15
+ "PERC_EB":0.80,
16
+ "AVG_WKLY_SALES":2656.04,
17
+ "AVG_WKLY_CASES":67.00}]
18
+
19
+ response = requests.post("http://localhost:7860/predict", json=data)
20
+ print(response.json())
docker-compose.yaml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ services:
2
+ app:
3
+ build: .
4
+ container_name: app
5
+ restart: unless-stopped
6
+ ports:
7
+ - "7860:7860"
requirements.txt ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ annotated-doc==0.0.4
2
+ annotated-types==0.7.0
3
+ anyio==4.11.0
4
+ click==8.3.1
5
+ colorama==0.4.6
6
+ fastapi==0.121.3
7
+ h11==0.16.0
8
+ idna==3.11
9
+ joblib==1.5.2
10
+ mord==0.7
11
+ numpy==2.3.5
12
+ pandas==2.3.3
13
+ pydantic==2.12.4
14
+ pydantic_core==2.41.5
15
+ python-dateutil==2.9.0.post0
16
+ pytz==2025.2
17
+ scikit-learn==1.7.2
18
+ scipy==1.16.3
19
+ six==1.17.0
20
+ sniffio==1.3.1
21
+ starlette==0.50.0
22
+ threadpoolctl==3.6.0
23
+ typing-inspection==0.4.2
24
+ typing_extensions==4.15.0
25
+ tzdata==2025.2
26
+ uvicorn==0.38.0