berkeruveyik commited on
Commit
4d5ff6e
·
verified ·
1 Parent(s): 09c3b67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -3
app.py CHANGED
@@ -2,6 +2,8 @@ import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
4
  from PIL import Image
 
 
5
 
6
  # Load the model
7
  print("Loading model...")
@@ -73,13 +75,30 @@ def predict(image):
73
  print(f"Error: {e}")
74
  return {"Error": str(e)}
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  # --- Gradio Interface ---
77
  with gr.Blocks(title="Food 270 Classifier") as demo:
78
  # Title and description
79
  gr.Markdown("""
80
  # 🍽️ Food 270 Classifier
81
- **An AI model that can recognize 270 different types of food**
82
- 📸 Upload a photo of food and let it guess what it is!
83
  """)
84
 
85
  # Main row
@@ -105,6 +124,23 @@ with gr.Blocks(title="Food 270 Classifier") as demo:
105
  - The **Top 5** most likely predictions are shown
106
  """)
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  # Bottom section - Tips and info
109
  with gr.Row():
110
  gr.Markdown("""
@@ -122,7 +158,8 @@ with gr.Blocks(title="Food 270 Classifier") as demo:
122
  - **Dataset**: Food 270
123
  - **Number of Classes**: 270 different foods
124
  - **Training Size**: 224x224
125
- *Developer: Berker Üveyik*
 
126
  """)
127
 
128
  # Event handlers
 
2
  import tensorflow as tf
3
  import numpy as np
4
  from PIL import Image
5
+ import os
6
+ import glob
7
 
8
  # Load the model
9
  print("Loading model...")
 
75
  print(f"Error: {e}")
76
  return {"Error": str(e)}
77
 
78
+ # --- Örnek resimleri yükle ---
79
+ def load_sample_images():
80
+ """sample_images klasöründeki tüm resimleri yükle"""
81
+ sample_folder = "sample_images"
82
+ if os.path.exists(sample_folder):
83
+ # Desteklenen resim formatları
84
+ image_extensions = ['*.jpg', '*.jpeg', '*.png', '*.JPG', '*.JPEG', '*.PNG']
85
+ sample_images = []
86
+ for ext in image_extensions:
87
+ sample_images.extend(glob.glob(os.path.join(sample_folder, ext)))
88
+ return sorted(sample_images)
89
+ return []
90
+
91
+ # Örnek resimleri al
92
+ sample_images = load_sample_images()
93
+ print(f"{len(sample_images)} örnek resim yüklendi")
94
+
95
  # --- Gradio Interface ---
96
  with gr.Blocks(title="Food 270 Classifier") as demo:
97
  # Title and description
98
  gr.Markdown("""
99
  # 🍽️ Food 270 Classifier
100
+ **An AI model that can recognize 270 different types of food**
101
+ 📸 Upload a photo of food and let it guess what it is!
102
  """)
103
 
104
  # Main row
 
124
  - The **Top 5** most likely predictions are shown
125
  """)
126
 
127
+ # Örnek resimler bölümü
128
+ if sample_images:
129
+ gr.Markdown("""
130
+ ---
131
+ ### 🖼️ Example Images
132
+ Click on an example image below to try the model!
133
+ """)
134
+
135
+ gr.Examples(
136
+ examples=sample_images,
137
+ inputs=input_image,
138
+ outputs=output,
139
+ fn=predict,
140
+ cache_examples=False, # Her tıklamada yeniden tahmin yap
141
+ label="Sample Food Images"
142
+ )
143
+
144
  # Bottom section - Tips and info
145
  with gr.Row():
146
  gr.Markdown("""
 
158
  - **Dataset**: Food 270
159
  - **Number of Classes**: 270 different foods
160
  - **Training Size**: 224x224
161
+
162
+ *Developer: Berker Üveyik*
163
  """)
164
 
165
  # Event handlers