from PIL import Image import numpy as np import tensorflow as tf import gradio as gr import json # تحميل أسماء الفئات with open("class_names.json", "r", encoding="utf-8") as f: index_to_arabic = json.load(f) index_to_arabic = {int(k): v for k, v in index_to_arabic.items()} arabic_names = [index_to_arabic[i] for i in sorted(index_to_arabic.keys())] # تحميل النموذج model = tf.keras.models.load_model("model.h5") def predict_flower(img): if img is None: return {"⚠️ يرجى رفع صورة": 1.0} if img.mode != 'RGB': img = img.convert('RGB') img = img.resize((150, 150)) img_array = np.array(img) / 255.0 img_array = np.expand_dims(img_array, axis=0) preds = model.predict(img_array, verbose=0)[0] if np.max(preds) < 0.6: return {"❌ لا يمكن التعرف على الصورة": 1.0} return {arabic_names[i]: float(preds[i]) for i in range(len(arabic_names))} iface = gr.Interface( fn=predict_flower, inputs=gr.Image(type="pil", label="ارفع صورة زهرة 🌸"), outputs=gr.Label(), title="🌼 مُصنّف الزهور (عربي)", description="يدعم: أقحوان، هندباء، توليب، عباد الشمس" ) if __name__ == "__main__": iface.launch()