Spaces:
Runtime error
Runtime error
File size: 1,956 Bytes
4e511bb 5d00b96 4e511bb d845688 4e511bb af8cb91 109acc7 c0a39e5 109acc7 9da9010 109acc7 4e511bb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import gradio as gr
import numpy as np
import tensorflow as tf
from tensorflow import keras
model = keras.models.load_model("brainTumor_classification.h5")
class_names = ['glioma', 'meningioma', 'notumor', 'pituitary']
img_height = 180
img_width = 180
def classify_image(image):
image = tf.image.resize(image, (img_height, img_width))
image = np.expand_dims(image, axis=0)
predictions = model.predict(image)
scores = tf.nn.softmax(predictions[0])
predicted_class = class_names[np.argmax(scores)]
confidence = 100 * np.max(scores)
return f"This image most likely belongs to {predicted_class} with a {confidence:.2f} percent confidence."
input_image = gr.inputs.Image(shape=(img_height, img_width))
output_text = gr.outputs.Textbox()
gr.Interface(
fn=classify_image,
inputs=input_image,
outputs=output_text,
examples=[["bt1.jpg"], ["bt2.jpg"], ["bt3.jpg"], ["br1.jpg"], ["br2.jpg"], ["br3.jpg"]],
live=True,
title = '<h1 style="text-align: center;">Brain Tumor Image Classification! 🧠 </h1>',
description=(
"<h2><b> 👉 Try Brain Tumor Image Classification Now!</b></h2>"
"<p>Don't miss out on this incredible opportunity to "
"shape the future of medical diagnostics. Embrace innovation, <br>"
"empower medical professionals, and make a real difference in <br>"
"the lives of countless individuals. 🌍🩺🤝(ผลงานชิ้นนี้เป็นของ นาวสาวสุวีรยา เนินทราย ผู้เดียวเท่านั้น หากมีผู้อื่นนำไปคัดลอกผลงานต่อ หรือนำผลงานนี้ลงแฟ้มผลงาน(Portfolio) นอกเหนือจากนี้ ถือเป็นความผิด)</p>"
),
theme="emoji",
theme_css=(".g-button { background-color: #FF5733; }")
).launch()
|