Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +31 -0
- model.h5 +3 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from tensorflow.keras.preprocessing import image
|
| 4 |
+
import numpy as np
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
# تحميل الموديل
|
| 8 |
+
model = tf.keras.models.load_model("model.h5")
|
| 9 |
+
|
| 10 |
+
# دالة التنبؤ
|
| 11 |
+
def predict(img):
|
| 12 |
+
img = img.resize((228, 228)) # تأكد من نفس المقاس المستخدم في التدريب
|
| 13 |
+
img_array = image.img_to_array(img)
|
| 14 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 15 |
+
img_array = img_array / 255.0
|
| 16 |
+
|
| 17 |
+
prediction = model.predict(img_array)[0][0]
|
| 18 |
+
label = "Stroke" if prediction > 0.5 else "No Stroke"
|
| 19 |
+
confidence = round(float(prediction) * 100, 2) if prediction > 0.5 else round((1 - float(prediction)) * 100, 2)
|
| 20 |
+
return f"{label} ({confidence}%)"
|
| 21 |
+
|
| 22 |
+
# إنشاء واجهة Gradio
|
| 23 |
+
interface = gr.Interface(
|
| 24 |
+
fn=predict,
|
| 25 |
+
inputs=gr.Image(type="pil"),
|
| 26 |
+
outputs="text",
|
| 27 |
+
title="Brain Stroke Detection",
|
| 28 |
+
description="Upload a CT scan image to detect stroke probability."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
interface.launch()
|
model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5e4c7de57bd900c1f9789b197efc682ff480ce25b761cf249bfa5506f04644f1
|
| 3 |
+
size 86072208
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
tensorflow
|
| 3 |
+
Pillow
|