Download app/main.py from AIOmarRehan/Animal_Image_Classification_Using_InceptionV3: direct link, hf CLI and curl.
- Browser
- Download file 816 Bytes
-
https://huggingface.co/spaces/AIOmarRehan/Animal_Image_Classification_Using_InceptionV3/resolve/main/app/main.py
- Command line
-
hf download hf://spaces/AIOmarRehan/Animal_Image_Classification_Using_InceptionV3/app/main.py
-
curl -L -o main.py https://huggingface.co/spaces/AIOmarRehan/Animal_Image_Classification_Using_InceptionV3/resolve/main/app/main.py
816 Bytes
| from fastapi import FastAPI, UploadFile, File | |
| from fastapi.responses import JSONResponse | |
| from app.model import predict | |
| from PIL import Image | |
| import io | |
| app = FastAPI(title="Animal Image Classifier") | |
| async def predict_image(file: UploadFile = File(...)): | |
| try: | |
| # Read image from uploaded file | |
| contents = await file.read() | |
| img = Image.open(io.BytesIO(contents)) | |
| # Run prediction | |
| label, confidence, probs = predict(img) | |
| return JSONResponse(content={ | |
| "predicted_label": label, | |
| "confidence": round(confidence, 3), | |
| "probabilities": {k: round(v, 3) for k, v in probs.items()} | |
| }) | |
| except Exception as e: | |
| return JSONResponse(content={"error": str(e)}, status_code=500) |