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