Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,19 +1,27 @@
|
|
| 1 |
-
import
|
| 2 |
from huggingface_hub import from_pretrained_fastai
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
| 5 |
learn = from_pretrained_fastai("hugginglearners/brain-tumor-detection-mri")
|
| 6 |
|
| 7 |
-
|
| 8 |
-
def predict(
|
| 9 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
pred_class, _, probs = learn.predict(img)
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
from huggingface_hub import from_pretrained_fastai
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import io
|
| 5 |
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
+
|
| 8 |
+
# Load the model
|
| 9 |
learn = from_pretrained_fastai("hugginglearners/brain-tumor-detection-mri")
|
| 10 |
|
| 11 |
+
@app.route('/predict', methods=['POST'])
|
| 12 |
+
def predict():
|
| 13 |
+
# Get image from the request
|
| 14 |
+
file = request.files['file']
|
| 15 |
+
img = Image.open(io.BytesIO(file.read()))
|
| 16 |
+
|
| 17 |
+
# Make a prediction
|
| 18 |
pred_class, _, probs = learn.predict(img)
|
| 19 |
+
|
| 20 |
+
# Return the result as JSON
|
| 21 |
+
return jsonify({
|
| 22 |
+
'prediction': str(pred_class),
|
| 23 |
+
'confidence': float(probs.max())
|
| 24 |
+
})
|
| 25 |
|
| 26 |
+
if __name__ == '__main__':
|
| 27 |
+
app.run(debug=True)
|