Spaces:
Sleeping
Sleeping
Commit ·
670b0ed
1
Parent(s): ee82622
Update app.py requirement.txt Dockerfile
Browse files- Dockerfile +1 -1
- app.py +5 -20
- requirements.txt +2 -4
Dockerfile
CHANGED
|
@@ -7,4 +7,4 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
|
| 7 |
|
| 8 |
COPY . /app
|
| 9 |
|
| 10 |
-
CMD ["
|
|
|
|
| 7 |
|
| 8 |
COPY . /app
|
| 9 |
|
| 10 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -1,39 +1,24 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
-
from pydantic import BaseModel
|
| 3 |
import pandas as pd
|
| 4 |
import joblib
|
| 5 |
from huggingface_hub import hf_hub_download
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
model_path = hf_hub_download(repo_id="danialsiddiqui/task6-model", filename="model.joblib")
|
| 9 |
model_data = joblib.load(model_path)
|
| 10 |
model = model_data["model"]
|
| 11 |
columns = model_data["columns"]
|
| 12 |
|
| 13 |
-
# --- FastAPI app ---
|
| 14 |
-
app = FastAPI(title="Nexus Task6 API")
|
| 15 |
-
|
| 16 |
-
# Define the input schema
|
| 17 |
-
class PredictInput(BaseModel):
|
| 18 |
-
gender: str
|
| 19 |
-
customer_type: str
|
| 20 |
-
product_line: str
|
| 21 |
-
unit_price: float
|
| 22 |
-
quantity: int
|
| 23 |
-
tax_5: float
|
| 24 |
-
|
| 25 |
@app.get("/")
|
| 26 |
def home():
|
| 27 |
return {"status": "API is running"}
|
| 28 |
|
| 29 |
@app.post("/predict")
|
| 30 |
-
def predict(data:
|
| 31 |
-
|
| 32 |
-
df = pd.DataFrame([data.dict()])
|
| 33 |
-
# One-hot encode categorical variables
|
| 34 |
df = pd.get_dummies(df)
|
| 35 |
-
# Reindex to match training columns
|
| 36 |
df = df.reindex(columns=columns, fill_value=0)
|
| 37 |
-
# Predict
|
| 38 |
prediction = model.predict(df)[0]
|
| 39 |
return {"prediction": float(prediction)}
|
|
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import joblib
|
| 4 |
from huggingface_hub import hf_hub_download
|
| 5 |
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# Load model from HF repo
|
| 9 |
model_path = hf_hub_download(repo_id="danialsiddiqui/task6-model", filename="model.joblib")
|
| 10 |
model_data = joblib.load(model_path)
|
| 11 |
model = model_data["model"]
|
| 12 |
columns = model_data["columns"]
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
@app.get("/")
|
| 15 |
def home():
|
| 16 |
return {"status": "API is running"}
|
| 17 |
|
| 18 |
@app.post("/predict")
|
| 19 |
+
def predict(data: dict):
|
| 20 |
+
df = pd.DataFrame([data])
|
|
|
|
|
|
|
| 21 |
df = pd.get_dummies(df)
|
|
|
|
| 22 |
df = df.reindex(columns=columns, fill_value=0)
|
|
|
|
| 23 |
prediction = model.predict(df)[0]
|
| 24 |
return {"prediction": float(prediction)}
|
requirements.txt
CHANGED
|
@@ -1,8 +1,6 @@
|
|
| 1 |
fastapi
|
| 2 |
uvicorn[standard]
|
| 3 |
-
huggingface-hub
|
| 4 |
-
joblib
|
| 5 |
pandas
|
| 6 |
-
numpy
|
| 7 |
scikit-learn
|
| 8 |
-
|
|
|
|
|
|
| 1 |
fastapi
|
| 2 |
uvicorn[standard]
|
|
|
|
|
|
|
| 3 |
pandas
|
|
|
|
| 4 |
scikit-learn
|
| 5 |
+
joblib
|
| 6 |
+
huggingface-hub
|