thurya commited on
Commit
2256d58
·
verified ·
1 Parent(s): 8978f77

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +17 -0
  2. app.py +39 -0
  3. class_names.json +6 -0
  4. model.h5 +3 -0
README.md ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+ tags:
4
+ - image-classification
5
+ - flower-classifier
6
+ - tensorflow
7
+ - arabic
8
+ library_name: tensorflow
9
+ ---
10
+
11
+ # 🌼 مُصنّف الزهور باللغة العربية
12
+
13
+ هذا النموذج يصنّف الصور إلى 4 أنواع من الزهور:
14
+ - أقحوان
15
+ - هندباء
16
+ - توليب
17
+ - عباد الشمس
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from PIL import Image
3
+ import numpy as np
4
+ import tensorflow as tf
5
+ import gradio as gr
6
+ import json
7
+
8
+ # تحميل أسماء الفئات
9
+ with open("class_names.json", "r", encoding="utf-8") as f:
10
+ index_to_arabic = json.load(f)
11
+ index_to_arabic = {int(k): v for k, v in index_to_arabic.items()}
12
+ arabic_names = [index_to_arabic[i] for i in sorted(index_to_arabic.keys())]
13
+
14
+ # تحميل النموذج
15
+ model = tf.keras.models.load_model("model.h5")
16
+
17
+ def predict_flower(img):
18
+ if img is None:
19
+ return {"⚠️ يرجى رفع صورة": 1.0}
20
+ if img.mode != 'RGB':
21
+ img = img.convert('RGB')
22
+ img = img.resize((150, 150))
23
+ img_array = np.array(img) / 255.0
24
+ img_array = np.expand_dims(img_array, axis=0)
25
+ preds = model.predict(img_array, verbose=0)[0]
26
+ if np.max(preds) < 0.6:
27
+ return {"❌ لا يمكن التعرف على الصورة": 1.0}
28
+ return {arabic_names[i]: float(preds[i]) for i in range(len(arabic_names))}
29
+
30
+ iface = gr.Interface(
31
+ fn=predict_flower,
32
+ inputs=gr.Image(type="pil", label="ارفع صورة زهرة 🌸"),
33
+ outputs=gr.Label(),
34
+ title="🌼 مُصنّف الزهور (عربي)",
35
+ description="يدعم: أقحوان، هندباء، توليب، عباد الشمس"
36
+ )
37
+
38
+ if __name__ == "__main__":
39
+ iface.launch()
class_names.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "0": "الاقحوان",
3
+ "1": "الهدباء",
4
+ "2": "توليب",
5
+ "3": "عباد الشمس"
6
+ }
model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e2ff848383ab699a214faf55ca416db0f5aefa4104017cf4c4a74e82bb215a4a
3
+ size 41514392