izhan001 commited on
Commit
94b8a01
·
verified ·
1 Parent(s): 3299aac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import onnxruntime as ort
3
+ import numpy as np
4
+ from PIL import Image
5
+
6
+ # Load ONNX model
7
+ onnx_model_path = "your_model.onnx" # Replace with your ONNX model file name
8
+ ort_session = ort.InferenceSession(onnx_model_path)
9
+
10
+ def preprocess_image(image):
11
+ image = image.resize((224, 224)) # Adjust size according to your model
12
+ image = np.array(image).astype(np.float32) / 255.0 # Normalize
13
+ image = np.expand_dims(image, axis=0).transpose(0, 3, 1, 2) # Adjust shape
14
+ return image
15
+
16
+ def predict(image):
17
+ input_tensor = preprocess_image(image)
18
+ ort_inputs = {ort_session.get_inputs()[0].name: input_tensor}
19
+ ort_outs = ort_session.run(None, ort_inputs)
20
+ prediction = np.argmax(ort_outs[0])
21
+ return "Infected" if prediction == 1 else "Uninfected"
22
+
23
+ # Create Gradio Interface
24
+ iface = gr.Interface(
25
+ fn=predict,
26
+ inputs=gr.Image(type="pil"),
27
+ outputs="text",
28
+ title="Malaria Detection",
29
+ description="Upload a blood cell image to check if it is infected or not."
30
+ )
31
+
32
+ # Launch app
33
+ iface.launch()