Upload folder using huggingface_hub
Browse files- Dockerfile +17 -0
- app.py +43 -0
- requirements.txt +7 -0
Dockerfile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use a standard Python 3.9 image
|
| 2 |
+
FROM python:3.9
|
| 3 |
+
|
| 4 |
+
# Set the working directory inside the container
|
| 5 |
+
WORKDIR /app
|
| 6 |
+
|
| 7 |
+
# Copy the requirements file first to leverage Docker caching
|
| 8 |
+
COPY requirements.txt .
|
| 9 |
+
|
| 10 |
+
# Install Python dependencies
|
| 11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Copy the rest of the application files
|
| 14 |
+
COPY . .
|
| 15 |
+
|
| 16 |
+
# Command to run the FastAPI application with Uvicorn
|
| 17 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
import joblib
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
# Define the FastAPI application
|
| 8 |
+
app = FastAPI()
|
| 9 |
+
|
| 10 |
+
# Download and load the model
|
| 11 |
+
# Replace "josequinonez/PIMA-Diabetes-Prediction-FastAPI" with your actual Hugging Face repo ID if different
|
| 12 |
+
model_path = hf_hub_download(repo_id="josequinonez/PIMA-Diabetes-Prediction-FastAPI",
|
| 13 |
+
filename="best_pima_diabetes_model_v1.joblib", repo_type="model")
|
| 14 |
+
model = joblib.load(model_path)
|
| 15 |
+
|
| 16 |
+
# Define the input data structure using Pydantic
|
| 17 |
+
class DiabetesFeatures(BaseModel):
|
| 18 |
+
preg: int
|
| 19 |
+
plas: int
|
| 20 |
+
pres: int
|
| 21 |
+
skin: int
|
| 22 |
+
test: int
|
| 23 |
+
mass: float
|
| 24 |
+
pedi: float
|
| 25 |
+
age: int
|
| 26 |
+
|
| 27 |
+
# Define the prediction endpoint
|
| 28 |
+
@app.post("/predict/")
|
| 29 |
+
async def predict_diabetes(features: DiabetesFeatures):
|
| 30 |
+
# Convert input features to a pandas DataFrame
|
| 31 |
+
input_data = pd.DataFrame([features.model_dump()])
|
| 32 |
+
|
| 33 |
+
# Make prediction
|
| 34 |
+
prediction = model.predict(input_data)[0]
|
| 35 |
+
|
| 36 |
+
# Return the prediction result
|
| 37 |
+
result = "Diabetic" if prediction == 1 else "Non-Diabetic"
|
| 38 |
+
return {"prediction": result}
|
| 39 |
+
|
| 40 |
+
# Optional: Add a root endpoint for testing
|
| 41 |
+
@app.get("/")
|
| 42 |
+
async def read_root():
|
| 43 |
+
return {"message": "PIMA Diabetes Prediction API is running!"}
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas==2.2.2
|
| 2 |
+
huggingface_hub==0.32.6
|
| 3 |
+
joblib==1.5.1
|
| 4 |
+
scikit-learn==1.6.0
|
| 5 |
+
fastapi==0.111.0
|
| 6 |
+
uvicorn[standard]==0.30.3
|
| 7 |
+
pydantic==2.7.4
|