namanraj commited on
Commit
02ef8b7
·
verified ·
1 Parent(s): c30f62f

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +14 -0
  2. app/best_model.h5 +3 -0
  3. app/main.py +21 -0
  4. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /code
4
+
5
+ # Install dependencies
6
+ COPY requirements.txt .
7
+ RUN pip install --no-cache-dir -r requirements.txt
8
+
9
+ # Copy app code + model
10
+ COPY ./app ./app
11
+
12
+ EXPOSE 7860
13
+
14
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
app/best_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9f5065c23c6767d9f145cff5f21c574a77156a8b93baa70cc2c18864840cb1c9
3
+ size 6847976
app/main.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ import numpy as np
4
+ from tensorflow import keras
5
+
6
+ app = FastAPI()
7
+
8
+ # Load model
9
+ model = keras.models.load_model("best_model.h5")
10
+
11
+ # Input schema
12
+ class InputData(BaseModel):
13
+ pixels: list # flattened 28x28 = 784 values
14
+
15
+ @app.post("/predict")
16
+ def predict(data: InputData):
17
+ # Convert list → NumPy
18
+ X = np.array(data.pixels).reshape(1, 28, 28, 1) / 255.0 # normalize if trained that way
19
+ y_pred = model.predict(X)
20
+ predicted_class = int(np.argmax(y_pred, axis=1)[0])
21
+ return {"prediction": predicted_class}
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ numpy
4
+ tensorflow