Spaces:
Sleeping
Sleeping
Deploying kidney tumor detection app from Colab
Browse files- .gitattributes +1 -0
- app.py +53 -0
- best_resnet_model.keras +3 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.keras filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
import tensorflow as tf
|
| 5 |
+
from tensorflow import keras
|
| 6 |
+
from tensorflow.keras.applications.resnet_v2 import preprocess_input as resnet_v2_preprocess
|
| 7 |
+
|
| 8 |
+
# --- 1. إعدادات النموذج ---
|
| 9 |
+
IMG_WIDTH, IMG_HEIGHT = 224, 224
|
| 10 |
+
IMAGE_SIZE = (IMG_HEIGHT, IMG_WIDTH)
|
| 11 |
+
MODEL_PATH = 'best_resnet_model.keras'
|
| 12 |
+
|
| 13 |
+
# --- 2. تحميل النموذج ---
|
| 14 |
+
try:
|
| 15 |
+
model = keras.models.load_model(MODEL_PATH)
|
| 16 |
+
print("Model loaded successfully!")
|
| 17 |
+
except Exception as e:
|
| 18 |
+
print(f"Error loading model: {e}")
|
| 19 |
+
model = None
|
| 20 |
+
|
| 21 |
+
# --- 3. تعريف دالة التنبؤ ---
|
| 22 |
+
class_labels = {0: "Normal", 1: "Tumor"}
|
| 23 |
+
|
| 24 |
+
def predict(image):
|
| 25 |
+
if model is None:
|
| 26 |
+
return {"Error": "Model could not be loaded."}
|
| 27 |
+
|
| 28 |
+
image_resized = tf.image.resize(image, IMAGE_SIZE)
|
| 29 |
+
img_array = np.array(image_resized)
|
| 30 |
+
img_array_expanded = np.expand_dims(img_array, axis=0)
|
| 31 |
+
processed_img_array = resnet_v2_preprocess(img_array_expanded)
|
| 32 |
+
|
| 33 |
+
preds = model.predict(processed_img_array)
|
| 34 |
+
confidence = preds[0][0]
|
| 35 |
+
|
| 36 |
+
confidences = {
|
| 37 |
+
class_labels[0]: 1 - confidence,
|
| 38 |
+
class_labels[1]: confidence
|
| 39 |
+
}
|
| 40 |
+
return confidences
|
| 41 |
+
|
| 42 |
+
# --- 4. إنشاء الواجهة ---
|
| 43 |
+
demo = gr.Interface(
|
| 44 |
+
fn=predict,
|
| 45 |
+
inputs=gr.Image(label="Upload Kidney CT Image", type="pil"),
|
| 46 |
+
outputs=gr.Label(num_top_classes=2, label="Prediction Results"),
|
| 47 |
+
title="🩺 Kidney Tumor Detection",
|
| 48 |
+
description="AI model to detect tumors in kidney CT scans. (Proof of concept for a university project)"
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
# --- 5. تشغيل التطبيق ---
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
demo.launch()
|
best_resnet_model.keras
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:876e3df87bf92ecf1a3b0396cdb46ba1182c2817faa710b4150deb0b958b5012
|
| 3 |
+
size 213663641
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
tensorflow
|
| 3 |
+
numpy
|