Spaces:
Sleeping
Sleeping
| import fastapi | |
| import io | |
| from fastapi import UploadFile, File | |
| from PIL import Image | |
| from .predict import predict_image | |
| app = fastapi.FastAPI() | |
| def root(): | |
| return {"message": "API is working!"} | |
| async def upload_image(file: UploadFile = File(...)): | |
| if not file.content_type.startswith("image/"): | |
| return {"error": "Please upload an image to proceed"} | |
| contents = await file.read() | |
| try: | |
| image = Image.open(io.BytesIO(contents)) | |
| except Exception as e: | |
| return {"error": f"Failed to open image: {str(e)}"} | |
| pred = predict_image(image) | |
| return {"prediction": pred} | |