import numpy as np from huggingface_hub import hf_hub_download from tensorflow.keras.models import load_model from PIL import Image import gradio as gr # ---------------------------- # تحميل الوزن من HuggingFace # ---------------------------- REPO_ID = "MooseML/EfficientNet-Cancer-Detection" MODEL_FILE = "efficientnet_cancer_model.h5" # موجود فعليًا في Files model_path = hf_hub_download( repo_id=REPO_ID, filename=MODEL_FILE ) model = load_model(model_path) # ---------------------------- # تحضير الصورة # ---------------------------- def preprocess(img: Image.Image): img = img.resize((96, 96)) img = np.array(img).astype("float32") / 255.0 img = np.expand_dims(img, axis=0) return img labels = ["No Tumor", "Tumor"] # ---------------------------- # دالة التنبؤ # ---------------------------- def predict(img): x = preprocess(img) probs = model.predict(x)[0] return { labels[0]: float(probs[0]), labels[1]: float(probs[1]), } # ---------------------------- # واجهة Gradio # ---------------------------- demo = gr.Interface( fn=predict, inputs=gr.Image(type="pil", label="Upload histopathology patch"), outputs=gr.Label(), title="EfficientNet Tumor Detection Demo", description="Model: MooseML/EfficientNet-Cancer-Detection", ) demo.launch()