|
import gradio as gr |
|
import numpy as np |
|
import tensorflow as tf |
|
|
|
|
|
model = tf.keras.models.load_model("model.h5") |
|
|
|
def predict(image): |
|
|
|
image = tf.image.resize(image, [224, 224]) |
|
image = np.expand_dims(image, axis=0) |
|
predictions = model.predict(image) |
|
|
|
|
|
|
|
|
|
no_tumor_confidence = predictions[0][0] |
|
tumor_confidence = predictions[0][1] |
|
|
|
|
|
if tumor_confidence > no_tumor_confidence: |
|
result = { |
|
"prediction": "Tumor Detected", |
|
"confidence": float(tumor_confidence) |
|
} |
|
else: |
|
result = { |
|
"prediction": "No Tumor Detected", |
|
"confidence": float(no_tumor_confidence) |
|
} |
|
|
|
return result |
|
|
|
|
|
iface = gr.Interface(fn=predict, inputs="image", outputs="json") |
|
|
|
|
|
iface.launch() |
|
|