Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
|
4 |
+
def classify_image(Image):
|
5 |
+
model = tf.keras.models.load_model('tumor_model.h5')
|
6 |
+
labels = [
|
7 |
+
'Tumor - Glioma',
|
8 |
+
'No Tumor',
|
9 |
+
'Tumor - Meningioma',
|
10 |
+
'Tumor - Pituitary'
|
11 |
+
]
|
12 |
+
|
13 |
+
inp = Image.reshape((-1, 128, 128, 3))
|
14 |
+
inp = tf.keras.applications.resnet50.preprocess_input(inp)
|
15 |
+
prediction = model.predict(inp).flatten()
|
16 |
+
confidences = {labels[i]: float(prediction[i]) for i in range(4)}
|
17 |
+
|
18 |
+
return confidences
|
19 |
+
|
20 |
+
image_input = gr.inputs.Image(shape = (128, 128))
|
21 |
+
label_output = gr.outputs.Label(num_top_classes = 4)
|
22 |
+
|
23 |
+
title = "Tumor Classification"
|
24 |
+
description = "Upload an image and get predictions for tumor classification."
|
25 |
+
examples = [
|
26 |
+
['Example 1.jpg'],
|
27 |
+
['Example 2.jpg']
|
28 |
+
]
|
29 |
+
|
30 |
+
interface = gr.Interface(
|
31 |
+
fn = classify_image,
|
32 |
+
inputs = image_input,
|
33 |
+
outputs = label_output,
|
34 |
+
title = title,
|
35 |
+
description = description,
|
36 |
+
examples = examples,
|
37 |
+
button_style ='danger',
|
38 |
+
theme = 'huggingface'
|
39 |
+
)
|
40 |
+
|
41 |
+
interface.launch()
|