Upload 5 files
Browse files- Dockerfile +16 -0
- README.md +4 -4
- app.py +31 -0
- model.pkl +3 -0
- requirements.txt +6 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.9
|
| 5 |
+
|
| 6 |
+
RUN useradd -m -u 1000 user
|
| 7 |
+
USER user
|
| 8 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 9 |
+
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 14 |
+
|
| 15 |
+
COPY --chown=user . /app
|
| 16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
---
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Accident Prediction
|
| 3 |
+
emoji: 👁
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
---
|
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request, Form, Depends
|
| 2 |
+
from fastapi.templating import Jinja2Templates
|
| 3 |
+
from fastapi.staticfiles import StaticFiles
|
| 4 |
+
import pickle
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# Load the trained model
|
| 8 |
+
with open("model.pkl", "rb") as model_file:
|
| 9 |
+
model = pickle.load(model_file)
|
| 10 |
+
|
| 11 |
+
app = FastAPI()
|
| 12 |
+
|
| 13 |
+
# Setup templates and static files
|
| 14 |
+
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 15 |
+
templates = Jinja2Templates(directory="templates")
|
| 16 |
+
|
| 17 |
+
@app.get("/")
|
| 18 |
+
def home(request: Request):
|
| 19 |
+
return templates.TemplateResponse("index.html", {"request": request})
|
| 20 |
+
|
| 21 |
+
@app.post("/predict")
|
| 22 |
+
def predict(
|
| 23 |
+
request: Request,
|
| 24 |
+
x1: float = Form(...),
|
| 25 |
+
x2: float = Form(...),
|
| 26 |
+
x3: float = Form(...),
|
| 27 |
+
x4: float = Form(...),
|
| 28 |
+
):
|
| 29 |
+
input_features = np.array([[x1, x2, x3, x4]])
|
| 30 |
+
prediction = model.predict(input_features)[0] # Get the predicted category
|
| 31 |
+
return templates.TemplateResponse("index.html", {"request": request, "result": prediction})
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0dee138c904ac2e2623a1a04609df67e001596738582c398a7716f82a215649a
|
| 3 |
+
size 366219
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
numpy
|
| 4 |
+
jinja2
|
| 5 |
+
scikit-learn
|
| 6 |
+
python-multipart
|