Spaces:
Runtime error
Runtime error
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() | |