Spaces:
Runtime error
Runtime error
File size: 683 Bytes
8081a16 6a87acd 8081a16 6a87acd 8081a16 6a87acd 8081a16 6a87acd 8081a16 6a87acd 8081a16 |
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 |
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")
@app.route('/predict', methods=['POST'])
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)
|