EngReem85 commited on
Commit
0ab224a
·
verified ·
1 Parent(s): 3f28629

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -24,7 +24,7 @@ def predict_sketch(image):
24
  تستقبل الصورة من لوحة الرسم، تعالجها، وتعيد الاحتمالات.
25
  """
26
  try:
27
- # الصورة قادمة بصيغة (height, width, 3) RGB
28
  gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
29
  resized = cv2.resize(gray, (28, 28))
30
  # قلب الألوان (افتراض أن الخلفية سوداء والرسم أبيض)
@@ -43,13 +43,13 @@ def predict_sketch(image):
43
  def random_example():
44
  idx = np.random.randint(0, len(test_images))
45
  img = test_images[idx].reshape(28, 28)
46
- # تحويل إلى 3 قنوات (RGB) لأن مكون Image يتوقع صورة ملونة
47
  img_rgb = np.stack([img] * 3, axis=2)
48
  info_text = f"🖼️ مثال عشوائي رقم {idx} | الرقم الحقيقي: {test_labels[idx]}"
49
  return img_rgb, info_text
50
 
51
  # ============================================
52
- # 5. بناء واجهة Gradio باستخدام gr.Image (مع خاصية الرسم)
53
  # ============================================
54
  with gr.Blocks(title="MNIST Digit Recognizer") as demo:
55
  gr.Markdown("# 🧠 التعرف على الأرقام المكتوبة بخط اليد")
@@ -57,14 +57,8 @@ with gr.Blocks(title="MNIST Digit Recognizer") as demo:
57
 
58
  with gr.Row():
59
  with gr.Column(scale=1):
60
- # 🔥 استخدام gr.Image مع sources=['sketch'] لإنشاء لوحة رسم
61
- sketch = gr.Image(
62
- sources=['sketch'],
63
- label="✏️ ارسم هنا",
64
- height=280,
65
- width=280,
66
- type="numpy" # تعيد الصورة كمصفوفة NumPy
67
- )
68
  with gr.Row():
69
  submit_btn = gr.Button("🔮 توقع", variant="primary")
70
  random_btn = gr.Button("🎲 عرض مثال عشوائي", variant="secondary")
 
24
  تستقبل الصورة من لوحة الرسم، تعالجها، وتعيد الاحتمالات.
25
  """
26
  try:
27
+ # image تكون بصيغة (height, width, 3) من نوع numpy
28
  gray = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
29
  resized = cv2.resize(gray, (28, 28))
30
  # قلب الألوان (افتراض أن الخلفية سوداء والرسم أبيض)
 
43
  def random_example():
44
  idx = np.random.randint(0, len(test_images))
45
  img = test_images[idx].reshape(28, 28)
46
+ # تحويل إلى 3 قنوات (RGB) لأن Sketchpad يتوقع صورة ملونة
47
  img_rgb = np.stack([img] * 3, axis=2)
48
  info_text = f"🖼️ مثال عشوائي رقم {idx} | الرقم الحقيقي: {test_labels[idx]}"
49
  return img_rgb, info_text
50
 
51
  # ============================================
52
+ # 5. بناء واجهة Gradio (باستخدام gr.Sketchpad بدون وسائط إضافية)
53
  # ============================================
54
  with gr.Blocks(title="MNIST Digit Recognizer") as demo:
55
  gr.Markdown("# 🧠 التعرف على الأرقام المكتوبة بخط اليد")
 
57
 
58
  with gr.Row():
59
  with gr.Column(scale=1):
60
+ # استخدام Sketchpad بدون أي وسائط إضافية
61
+ sketch = gr.Sketchpad(label="✏️ ارسم هنا")
 
 
 
 
 
 
62
  with gr.Row():
63
  submit_btn = gr.Button("🔮 توقع", variant="primary")
64
  random_btn = gr.Button("🎲 عرض مثال عشوائي", variant="secondary")