HyraXuna commited on
Commit
3ef95de
·
0 Parent(s):

first commit

Browse files
Files changed (4) hide show
  1. Dockerfile +34 -0
  2. README.md +10 -0
  3. app.py +56 -0
  4. requirements.txt +15 -0
Dockerfile ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM continuumio/miniconda3
2
+
3
+ RUN apt-get update -y
4
+ RUN apt-get install nano unzip curl -y
5
+
6
+ # THIS IS SPECIFIC TO HUGGINFACE
7
+ # We create a new user named "user" with ID of 1000
8
+ RUN useradd -m -u 1000 user
9
+ # We switch from "root" (default user when creating an image) to "user"
10
+ USER user
11
+ # We set two environmnet variables
12
+ # so that we can give ownership to all files in there afterwards
13
+ # we also add /home/user/.local/bin in the $PATH environment variable
14
+ # PATH environment variable sets paths to look for installed binaries
15
+ # We update it so that Linux knows where to look for binaries if we were to install them with "user".
16
+ ENV HOME=/home/user \
17
+ PATH=/home/user/.local/bin:$PATH
18
+
19
+ # We set working directory to $HOME/app (<=> /home/user/app)
20
+ WORKDIR $HOME/app
21
+
22
+ # Install basic dependencies
23
+ RUN pip install boto3 pandas gunicorn streamlit scikit-learn matplotlib seaborn plotly
24
+
25
+ # Copy all local files to /home/user/app with "user" as owner of these files
26
+ # Always use --chown=user when using HUGGINGFACE to avoid permission errors
27
+ COPY --chown=user . $HOME/app
28
+
29
+ COPY requirements.txt /dependencies/requirements.txt
30
+ RUN pip install -r /dependencies/requirements.txt
31
+
32
+ COPY . $HOME/app
33
+
34
+ CMD fastapi run app.py --port $PORT
README.md ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Test Api 2
3
+ emoji: 📈
4
+ colorFrom: gray
5
+ colorTo: green
6
+ sdk: docker
7
+ pinned: false
8
+ ---
9
+
10
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import mlflow
2
+ import uvicorn
3
+ import pandas as pd
4
+ from pydantic import BaseModel
5
+ from typing import Literal, List, Union
6
+ from fastapi import FastAPI, File, UploadFile
7
+ import joblib
8
+
9
+ # Log model from mlflow
10
+ logged_model = 'runs:/e7b51184619c45f9b2fbb017dfe0a49f/model'
11
+
12
+ # Load model as a PyFuncModel.
13
+ loaded_model = mlflow.pyfunc.load_model(logged_model)
14
+
15
+ tags_metadata = [
16
+ {
17
+ "name": "Machine Learning",
18
+ "description": "Prediction Endpoint."
19
+ }
20
+ ]
21
+
22
+ app = FastAPI(
23
+ title="Demo Iris API",
24
+ openapi_tags=tags_metadata
25
+ )
26
+
27
+ class PredictionFeatures(BaseModel):
28
+ sepal_length: float
29
+ sepal_width: float
30
+ petal_length: float
31
+ petal_width: float
32
+
33
+ @app.get("/", tags=["Introduction Endpoints"])
34
+ async def index():
35
+ """
36
+ Simply returns a welcome message!
37
+ """
38
+ message = "Hello world! This `/` is the most simple and default endpoint. If you want to learn more, check out documentation of the api at `/docs`"
39
+ return message
40
+
41
+
42
+ @app.post("/predict", tags=["Machine Learning"])
43
+ async def predict(predictionFeatures: PredictionFeatures):
44
+ # Read data
45
+ input_data = pd.DataFrame({
46
+ "sepal length (cm)": [predictionFeatures.sepal_length],
47
+ "sepal width (cm)": [predictionFeatures.sepal_width],
48
+ "petal length (cm)": [predictionFeatures.petal_length],
49
+ "petal width (cm)": [predictionFeatures.petal_width]
50
+ })
51
+
52
+ prediction = loaded_model.predict(input_data)
53
+
54
+ # Format response
55
+ response = {"prediction": prediction.tolist()[0]}
56
+ return response
requirements.txt ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi[standard]
2
+ pydantic
3
+ typing
4
+ pandas
5
+ openpyxl
6
+ mlflow
7
+ boto3
8
+ scikit-learn
9
+ python-multipart
10
+ fsspec
11
+ s3fs
12
+ streamlit
13
+ matplotlib
14
+ seaborn
15
+ plotly