SebastianAndreu commited on
Commit
b5441d4
·
verified ·
1 Parent(s): 1791631

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -32
app.py CHANGED
@@ -196,33 +196,30 @@ input, textarea, select {
196
  }
197
 
198
  /* Upload/Webcam tab buttons - make them visible and styled */
199
- [data-testid="image"] [role="tablist"] {
200
- background: #f8f9fa !important;
201
- padding: 12px !important;
202
- border-radius: 12px !important;
203
- gap: 12px !important;
204
- margin-bottom: 20px !important;
205
- display: flex !important;
206
- justify-content: center !important;
207
  }
208
 
209
- [data-testid="image"] [role="tab"] {
 
 
210
  background: white !important;
211
  border: 2px solid #cbd5e0 !important;
212
  border-radius: 10px !important;
213
- padding: 16px 32px !important;
214
- font-size: 1.1em !important;
215
  font-weight: 600 !important;
216
  color: #2d3748 !important;
217
  transition: all 0.3s ease !important;
218
- min-width: 150px !important;
219
- display: flex !important;
220
- align-items: center !important;
221
- justify-content: center !important;
222
- gap: 8px !important;
223
  }
224
 
225
- [data-testid="image"] [role="tab"]:hover {
 
 
226
  background: #667eea !important;
227
  border-color: #667eea !important;
228
  color: white !important;
@@ -230,25 +227,41 @@ input, textarea, select {
230
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3) !important;
231
  }
232
 
233
- [data-testid="image"] [role="tab"][aria-selected="true"] {
 
 
234
  background: #667eea !important;
235
  border-color: #667eea !important;
236
  color: white !important;
237
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4) !important;
238
  }
239
 
240
- /* Icon colors in tabs */
241
- [data-testid="image"] [role="tab"] svg {
242
- width: 22px !important;
243
- height: 22px !important;
 
 
 
 
244
  }
245
 
246
  [data-testid="image"] [role="tab"] svg path,
247
  [data-testid="image"] [role="tab"] svg line,
248
  [data-testid="image"] [role="tab"] svg circle,
249
- [data-testid="image"] [role="tab"] svg rect {
 
 
250
  stroke: currentColor !important;
251
- fill: none !important;
 
 
 
 
 
 
 
 
252
  }
253
 
254
  /* Upload area */
@@ -566,11 +579,16 @@ def create_checkout_item_display(item_data, index):
566
  item = item_data['item']
567
  desc = item_data['description']
568
 
569
- display = f"""**Detected:** {desc}
570
- **Matched:** {item['Item Name']}
571
- **Category:** {item['Category']}
572
- **Location:** {item['Location']}
573
- **Available:** {item['Quantity']} {item['Unit']}"""
 
 
 
 
 
574
 
575
  return display
576
 
@@ -676,7 +694,14 @@ def extract_text_from_receipt(file_path):
676
  text = ""
677
 
678
  if file_path.name.lower().endswith('.pdf'):
679
- images = convert_from_path(file_path.name)
 
 
 
 
 
 
 
680
  for img in images:
681
  text += pytesseract.image_to_string(img) + "\n"
682
  else:
@@ -1291,8 +1316,8 @@ with gr.Blocks(title="Makerspace Inventory System", css=CUSTOM_CSS) as demo:
1291
  checkout_scan_btn = gr.Button("🔍 Scan & Match Items", variant="primary", size="lg")
1292
 
1293
  with gr.Group(visible=False) as checkout_screen2:
1294
- gr.Markdown("### Review Items", elem_classes=["subsection-header"])
1295
- gr.Markdown("*Adjust quantities or remove items before checkout*")
1296
 
1297
  checkout_item_controls = []
1298
  for i in range(10):
 
196
  }
197
 
198
  /* Upload/Webcam tab buttons - make them visible and styled */
199
+ [data-testid="image"] [role="tablist"],
200
+ .image-container [role="tablist"],
201
+ button[role="tab"] {
202
+ background: transparent !important;
 
 
 
 
203
  }
204
 
205
+ [data-testid="image"] [role="tab"],
206
+ .image-container [role="tab"],
207
+ button[role="tab"] {
208
  background: white !important;
209
  border: 2px solid #cbd5e0 !important;
210
  border-radius: 10px !important;
211
+ padding: 14px 28px !important;
212
+ font-size: 1em !important;
213
  font-weight: 600 !important;
214
  color: #2d3748 !important;
215
  transition: all 0.3s ease !important;
216
+ min-width: 130px !important;
217
+ margin: 4px !important;
 
 
 
218
  }
219
 
220
+ [data-testid="image"] [role="tab"]:hover,
221
+ .image-container [role="tab"]:hover,
222
+ button[role="tab"]:hover {
223
  background: #667eea !important;
224
  border-color: #667eea !important;
225
  color: white !important;
 
227
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3) !important;
228
  }
229
 
230
+ [data-testid="image"] [role="tab"][aria-selected="true"],
231
+ .image-container [role="tab"][aria-selected="true"],
232
+ button[role="tab"][aria-selected="true"] {
233
  background: #667eea !important;
234
  border-color: #667eea !important;
235
  color: white !important;
236
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4) !important;
237
  }
238
 
239
+ /* Icon colors in tabs - force visibility */
240
+ [data-testid="image"] [role="tab"] svg,
241
+ .image-container [role="tab"] svg,
242
+ button[role="tab"] svg {
243
+ width: 20px !important;
244
+ height: 20px !important;
245
+ fill: currentColor !important;
246
+ stroke: currentColor !important;
247
  }
248
 
249
  [data-testid="image"] [role="tab"] svg path,
250
  [data-testid="image"] [role="tab"] svg line,
251
  [data-testid="image"] [role="tab"] svg circle,
252
+ [data-testid="image"] [role="tab"] svg rect,
253
+ .image-container [role="tab"] svg path,
254
+ button[role="tab"] svg path {
255
  stroke: currentColor !important;
256
+ fill: currentColor !important;
257
+ stroke-width: 2 !important;
258
+ }
259
+
260
+ /* Ensure tab text is visible */
261
+ [data-testid="image"] [role="tab"] span,
262
+ .image-container [role="tab"] span,
263
+ button[role="tab"] span {
264
+ color: inherit !important;
265
  }
266
 
267
  /* Upload area */
 
579
  item = item_data['item']
580
  desc = item_data['description']
581
 
582
+ display = f"""<div style="background: #f8f9fa; padding: 15px; border-radius: 8px; border-left: 4px solid #667eea; margin: 10px 0;">
583
+ <div style="color: #667eea; font-weight: 600; font-size: 0.9em; margin-bottom: 8px;">🔍 DETECTED ITEM</div>
584
+ <div style="color: #2d3748; font-size: 1.05em; margin-bottom: 12px;">{desc}</div>
585
+ <div style="display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: 0.95em;">
586
+ <span style="color: #718096; font-weight: 600;">Matched Item:</span><span style="color: #2d3748;">{item['Item Name']}</span>
587
+ <span style="color: #718096; font-weight: 600;">Category:</span><span style="color: #2d3748;">{item['Category']}</span>
588
+ <span style="color: #718096; font-weight: 600;">Location:</span><span style="color: #2d3748;">{item['Location']}</span>
589
+ <span style="color: #718096; font-weight: 600;">Available:</span><span style="color: #2d3748;">{item['Quantity']} {item['Unit']}</span>
590
+ </div>
591
+ </div>"""
592
 
593
  return display
594
 
 
694
  text = ""
695
 
696
  if file_path.name.lower().endswith('.pdf'):
697
+ # Hugging Face Spaces installs poppler in /usr/bin
698
+ # Try with explicit poppler path first, fall back to default
699
+ try:
700
+ images = convert_from_path(file_path.name, poppler_path='/usr/bin')
701
+ except:
702
+ # Fallback to default path detection
703
+ images = convert_from_path(file_path.name)
704
+
705
  for img in images:
706
  text += pytesseract.image_to_string(img) + "\n"
707
  else:
 
1316
  checkout_scan_btn = gr.Button("🔍 Scan & Match Items", variant="primary", size="lg")
1317
 
1318
  with gr.Group(visible=False) as checkout_screen2:
1319
+ gr.Markdown("### Review Selected Items", elem_classes=["subsection-header"])
1320
+ gr.Markdown("*Verify items, adjust quantities, or remove unwanted items before proceeding*")
1321
 
1322
  checkout_item_controls = []
1323
  for i in range(10):