Spaces:
Sleeping
Sleeping
File size: 1,000 Bytes
0c87d10 |
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 |
import gradio as gr
import tensorflow as tf
from tensorflow.keras.preprocessing import image
import numpy as np
from PIL import Image
# تحميل الموديل
model = tf.keras.models.load_model("model.h5")
# دالة التنبؤ
def predict(img):
img = img.resize((228, 228)) # تأكد من نفس المقاس المستخدم في التدريب
img_array = image.img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
img_array = img_array / 255.0
prediction = model.predict(img_array)[0][0]
label = "Stroke" if prediction > 0.5 else "No Stroke"
confidence = round(float(prediction) * 100, 2) if prediction > 0.5 else round((1 - float(prediction)) * 100, 2)
return f"{label} ({confidence}%)"
# إنشاء واجهة Gradio
interface = gr.Interface(
fn=predict,
inputs=gr.Image(type="pil"),
outputs="text",
title="Brain Stroke Detection",
description="Upload a CT scan image to detect stroke probability."
)
interface.launch() |