Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- Dockerfile +12 -0
- app.py +30 -0
- requirements.txt +0 -0
Dockerfile
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
EXPOSE 7860
|
| 11 |
+
|
| 12 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, File, UploadFile
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import numpy as np
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import io
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
+
# Load model
|
| 10 |
+
model = tf.keras.models.load_model("model/saved_model")
|
| 11 |
+
|
| 12 |
+
def preprocess(image):
|
| 13 |
+
image = image.resize((224, 224))
|
| 14 |
+
image = np.array(image) / 255.0
|
| 15 |
+
return np.expand_dims(image, axis=0)
|
| 16 |
+
|
| 17 |
+
@app.get("/")
|
| 18 |
+
def root():
|
| 19 |
+
return {"message": "Model is running!"}
|
| 20 |
+
|
| 21 |
+
@app.post("/predict")
|
| 22 |
+
async def predict(file: UploadFile = File(...)):
|
| 23 |
+
image = Image.open(io.BytesIO(await file.read())).convert("RGB")
|
| 24 |
+
input_data = preprocess(image)
|
| 25 |
+
|
| 26 |
+
prediction = model.predict(input_data)
|
| 27 |
+
|
| 28 |
+
return {
|
| 29 |
+
"prediction": prediction.tolist()
|
| 30 |
+
}
|
requirements.txt
ADDED
|
File without changes
|