Spaces:
Runtime error
Runtime error
File size: 1,055 Bytes
acf2d38 8b7cda3 4499fe6 8b7cda3 a1955da 8b7cda3 4499fe6 8b7cda3 29c50fd 8b7cda3 29c50fd 8b7cda3 29c50fd 8b7cda3 29c50fd 8b7cda3 29c50fd 8b7cda3 29c50fd 9396581 8b7cda3 29c50fd 8b7cda3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import fastapi
from fastapi import FastAPI, UploadFile, File
from transformers import AutoModelForImageClassification
app = FastAPI()
# Load the model from the local file
model = AutoModelForImageClassification.from_pretrained(
"andupets/real-estate-image-classification-30classes"
)
# Define a function to preprocess the image
def preprocess_image(image: UploadFile):
# Resize the image to a fixed size
image = image.resize((224, 224))
# Convert the image to a NumPy array
image = np.array(image)
# Normalize the image
image = image / 255.0
# Return the image
return image
# Define an endpoint to predict the output
@app.post("/predict")
async def predict_endpoint(
image: UploadFile = File(...)
): # Preprocess the image
image = preprocess_image(image)
# Make a prediction
prediction = model(image)
# Return the prediction
return {"prediction": prediction}
# Start the FastAPI app
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
|