Spaces:
Sleeping
Sleeping
implement prediction endpoint and update Dockerfile and requirements
Browse files- Dockerfile +7 -0
- README.md +0 -1
- app.py +34 -0
- requirements.txt +5 -0
Dockerfile
CHANGED
|
@@ -1,5 +1,12 @@
|
|
| 1 |
FROM python:3.9
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
RUN useradd -m -u 1000 user
|
| 4 |
USER user
|
| 5 |
ENV PATH="/home/user/.local/bin:$PATH"
|
|
|
|
| 1 |
FROM python:3.9
|
| 2 |
|
| 3 |
+
ENV MLFLOW_EXPERIMENT_NAME=$MLFLOW_EXPERIMENT_NAME
|
| 4 |
+
ENV MLFLOW_TRACKING_URI=$MLFLOW_TRACKING_URI
|
| 5 |
+
ENV AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
|
| 6 |
+
ENV AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
|
| 7 |
+
ENV BACKEND_STORE_URI=$BACKEND_STORE_URI
|
| 8 |
+
ENV ARTIFACT_ROOT=$ARTIFACT_ROOT
|
| 9 |
+
|
| 10 |
RUN useradd -m -u 1000 user
|
| 11 |
USER user
|
| 12 |
ENV PATH="/home/user/.local/bin:$PATH"
|
README.md
CHANGED
|
@@ -9,4 +9,3 @@ license: mit
|
|
| 9 |
short_description: Web service for Getaround app to deliver car rental pricing
|
| 10 |
---
|
| 11 |
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 9 |
short_description: Web service for Getaround app to deliver car rental pricing
|
| 10 |
---
|
| 11 |
|
|
|
app.py
CHANGED
|
@@ -1,7 +1,41 @@
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
|
|
|
| 5 |
@app.get("/")
|
| 6 |
def greet_json():
|
| 7 |
return {"Hello": "World!"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
import mlflow.pyfunc
|
| 4 |
+
import pandas as pd
|
| 5 |
|
| 6 |
app = FastAPI()
|
| 7 |
|
| 8 |
+
|
| 9 |
@app.get("/")
|
| 10 |
def greet_json():
|
| 11 |
return {"Hello": "World!"}
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class PredictionFeatures(BaseModel):
|
| 15 |
+
YearsExperience: float
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
#### SOME CODE ####
|
| 19 |
+
###################
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
@app.post("/predict", tags=["Machine Learning"])
|
| 23 |
+
async def predict(predictionFeatures: PredictionFeatures):
|
| 24 |
+
"""
|
| 25 |
+
Prediction of salary for a given year of experience!
|
| 26 |
+
"""
|
| 27 |
+
# Read data
|
| 28 |
+
years_experience = pd.DataFrame(
|
| 29 |
+
{"YearsExperience": [predictionFeatures.YearsExperience]}
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Log model from mlflow
|
| 33 |
+
logged_model = "runs:/c09d09ef14e546b08f2f339d2c966da6/salary_estimator" # REPLACE WITH YOUR OWN RUN ID
|
| 34 |
+
|
| 35 |
+
# Load model as a PyFuncModel.
|
| 36 |
+
loaded_model = mlflow.pyfunc.load_model(logged_model)
|
| 37 |
+
prediction = loaded_model.predict(years_experience)
|
| 38 |
+
|
| 39 |
+
# Format response
|
| 40 |
+
response = {"prediction": prediction.tolist()[0]}
|
| 41 |
+
return response
|
requirements.txt
CHANGED
|
@@ -1,2 +1,7 @@
|
|
| 1 |
fastapi
|
| 2 |
uvicorn[standard]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
fastapi
|
| 2 |
uvicorn[standard]
|
| 3 |
+
pydantic
|
| 4 |
+
mlflow
|
| 5 |
+
pandas
|
| 6 |
+
|
| 7 |
+
|