medbenhasan commited on
Commit
8081a16
·
verified ·
1 Parent(s): 6a87acd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -13
app.py CHANGED
@@ -1,19 +1,27 @@
1
- import gradio as gr
2
  from huggingface_hub import from_pretrained_fastai
 
 
3
 
4
- # Load the model from Hugging Face Hub
 
 
5
  learn = from_pretrained_fastai("hugginglearners/brain-tumor-detection-mri")
6
 
7
- # Define the prediction function
8
- def predict(img):
9
- # Assuming input is an image, convert it into the format required by the model
 
 
 
 
10
  pred_class, _, probs = learn.predict(img)
11
- return {str(pred_class): float(probs.max())}
12
-
13
- # Create the Gradio interface
14
- iface = gr.Interface(fn=predict, inputs="image", outputs="label",
15
- title="Brain Tumor Detection",
16
- description="Upload an MRI scan to detect brain tumors")
17
 
18
- # Launch the interface
19
- iface.launch()
 
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)