Spaces:
Runtime error
Runtime error
from flask import Flask, request, jsonify | |
from huggingface_hub import from_pretrained_fastai | |
from PIL import Image | |
import io | |
app = Flask(__name__) | |
# Load the model | |
learn = from_pretrained_fastai("hugginglearners/brain-tumor-detection-mri") | |
def predict(): | |
# Get image from the request | |
file = request.files['file'] | |
img = Image.open(io.BytesIO(file.read())) | |
# Make a prediction | |
pred_class, _, probs = learn.predict(img) | |
# Return the result as JSON | |
return jsonify({ | |
'prediction': str(pred_class), | |
'confidence': float(probs.max()) | |
}) | |
if __name__ == '__main__': | |
app.run(debug=True) | |