shuraimi commited on
Commit
c6fa3f7
·
verified ·
1 Parent(s): 21f2458

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -103
app.py CHANGED
@@ -89,44 +89,6 @@ st.markdown("""
89
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
90
  }
91
 
92
- /* Navigation buttons styling */
93
- div[data-testid="column"] .stButton > button {
94
- padding: 0.5rem 1rem;
95
- font-size: 0.9rem;
96
- min-width: 50px;
97
- }
98
-
99
- /* Page number buttons */
100
- .stButton > button[kind="primary"] {
101
- background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
102
- font-weight: 700;
103
- }
104
-
105
- .stButton > button[kind="secondary"] {
106
- background: white;
107
- color: #667eea;
108
- border: 2px solid #667eea;
109
- font-weight: 500;
110
- }
111
-
112
- /* Example image containers */
113
- .example-image-container {
114
- aspect-ratio: 1 / 1;
115
- overflow: hidden;
116
- border-radius: 10px;
117
- margin-bottom: 0.5rem;
118
- background: #f0f2f6;
119
- display: flex;
120
- align-items: center;
121
- justify-content: center;
122
- }
123
-
124
- .example-image-container img {
125
- width: 100%;
126
- height: 100%;
127
- object-fit: cover;
128
- }
129
-
130
  /* Image container */
131
  .uploaded-image {
132
  border-radius: 15px;
@@ -177,7 +139,7 @@ def load_model():
177
  learner = load_learner(MODEL_PATH)
178
  return learner
179
  except Exception as e:
180
- st.error(f"⚠️ Error loading model:\n\n{e}")
181
  return None
182
 
183
  def predict(learner, img_bytes: bytes):
@@ -210,72 +172,15 @@ def main():
210
  example_images = list(examples_path.glob("*.jpg")) + list(examples_path.glob("*.png")) + list(examples_path.glob("*.jpeg"))
211
 
212
  if example_images:
213
- # Initialize page number in session state
214
- if 'example_page' not in st.session_state:
215
- st.session_state.example_page = 0
216
 
217
- # Number of images per page
218
- images_per_page = 5
219
- total_pages = (len(example_images) + images_per_page - 1) // images_per_page
220
-
221
- # Get current page images
222
- start_idx = st.session_state.example_page * images_per_page
223
- end_idx = min(start_idx + images_per_page, len(example_images))
224
- current_page_images = example_images[start_idx:end_idx]
225
-
226
- # Display examples in a grid (always 5 columns for consistency)
227
- cols = st.columns(5)
228
-
229
- for idx in range(5):
230
  with cols[idx]:
231
- if idx < len(current_page_images):
232
- img_path = current_page_images[idx]
233
- # Use HTML container for consistent sizing
234
- st.markdown(
235
- f'<div class="example-image-container">',
236
- unsafe_allow_html=True
237
- )
238
- st.image(str(img_path), use_container_width=True)
239
- st.markdown('</div>', unsafe_allow_html=True)
240
- st.caption(img_path.stem)
241
- if st.button(f"Use", key=f"example_{start_idx + idx}"):
242
- # Store the selected example in session state
243
- st.session_state.example_image = img_path
244
- st.rerun()
245
- else:
246
- # Empty placeholder to maintain grid consistency
247
- st.markdown('<div style="height: 200px;"></div>', unsafe_allow_html=True)
248
-
249
- # Pagination controls
250
- if total_pages > 1:
251
- st.markdown("<br>", unsafe_allow_html=True)
252
- page_cols = st.columns([1, 6, 1])
253
-
254
- with page_cols[0]:
255
- if st.button("⬅️", disabled=(st.session_state.example_page == 0), help="Previous page"):
256
- st.session_state.example_page -= 1
257
- st.rerun()
258
-
259
- with page_cols[1]:
260
- # Page number buttons centered
261
- center_cols = st.columns([1, 2, 1])
262
- with center_cols[1]:
263
- page_buttons = st.columns(total_pages)
264
- for page_num in range(total_pages):
265
- with page_buttons[page_num]:
266
- if st.button(
267
- f"{page_num + 1}",
268
- key=f"page_{page_num}",
269
- type="primary" if page_num == st.session_state.example_page else "secondary",
270
- use_container_width=True
271
- ):
272
- st.session_state.example_page = page_num
273
- st.rerun()
274
-
275
- with page_cols[2]:
276
- if st.button("➡️", disabled=(st.session_state.example_page == total_pages - 1), help="Next page"):
277
- st.session_state.example_page += 1
278
- st.rerun()
279
  else:
280
  st.info("No example images found in the 'examples' folder.")
281
  else:
 
89
  box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
90
  }
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  /* Image container */
93
  .uploaded-image {
94
  border-radius: 15px;
 
139
  learner = load_learner(MODEL_PATH)
140
  return learner
141
  except Exception as e:
142
+ st.error(f⚠️ Error loading model:\n\n{e}")
143
  return None
144
 
145
  def predict(learner, img_bytes: bytes):
 
172
  example_images = list(examples_path.glob("*.jpg")) + list(examples_path.glob("*.png")) + list(examples_path.glob("*.jpeg"))
173
 
174
  if example_images:
175
+ # Display examples in a grid
176
+ cols = st.columns(min(5, len(example_images)))
 
177
 
178
+ for idx, img_path in enumerate(example_images[:5]): # Show max 5 examples
 
 
 
 
 
 
 
 
 
 
 
 
179
  with cols[idx]:
180
+ st.image(str(img_path), use_container_width=True, caption=img_path.stem)
181
+ if st.button(f"Use", key=f"example_{idx}"):
182
+ # Store the selected example in session state
183
+ st.session_state.example_image = img_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  else:
185
  st.info("No example images found in the 'examples' folder.")
186
  else: