prernajeet14 commited on
Commit
165ef5e
·
verified ·
1 Parent(s): f756a21

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -33
app.py CHANGED
@@ -513,43 +513,34 @@ def get_images_html():
513
  # Create HTML for displaying images
514
  html = "<div class='image-gallery'>"
515
 
516
- if not image_files:
517
- html += "<p>No images found in the database.</p>"
518
- else:
519
- current_page = None
520
-
521
- for image_file in image_files:
522
- # Extract page number for section headers
523
- parts = image_file.split('_')
524
- if len(parts) >= 2:
525
- page_num = parts[0].replace('page', '')
526
-
527
- # Add page section header if we're on a new page
528
- if current_page != page_num:
529
- current_page = page_num
530
- html += f"<h2 class='page-header'>Page {page_num}</h2>"
531
 
532
- # Determine file extension for MIME type
533
- file_ext = os.path.splitext(image_file)[1].lower()
534
- if file_ext == '.jpeg' or file_ext == '.jpg':
535
- image_type = 'jpeg'
536
- elif file_ext == '.png':
537
- image_type = 'png'
538
- else:
539
- image_type = 'jpeg' # Default fallback
540
 
541
- # In Hugging Face Spaces, files are directly accessible via the path
542
- # Format the HTML to use the image directly from the space
543
  html += f"""
544
- <div class='image-card'>
545
- <div class='image-container'>
546
- <img src="{image_file}" alt="{image_file}">
547
- </div>
548
- <div class='image-details'>
549
- <h3>{image_file}</h3>
550
- <p><strong>Page:</strong> {page_num}</p>
551
- </div>
552
  </div>
 
553
  """
554
 
555
  html += "</div>"
 
513
  # Create HTML for displaying images
514
  html = "<div class='image-gallery'>"
515
 
516
+ # The problem was that we were checking if image_files is empty, but it's not empty
517
+ # We have the list of files, we just need to display them
518
+
519
+ current_page = None
520
+ for image_file in image_files:
521
+ # Extract page number for section headers
522
+ parts = image_file.split('_')
523
+ if len(parts) >= 2:
524
+ page_num = parts[0].replace('page', '')
525
+ # Add page section header if we're on a new page
526
+ if current_page != page_num:
527
+ current_page = page_num
528
+ html += f"<h2 class='page-header'>Page {page_num}</h2>"
 
 
529
 
530
+ # In Hugging Face Spaces, files need the correct path
531
+ # This is the likely source of your error - incorrect path to the images
532
+ img_path = f"files/{image_file}" # Adjust this path based on your Hugging Face Space structure
 
 
 
 
 
533
 
 
 
534
  html += f"""
535
+ <div class='image-card'>
536
+ <div class='image-container'>
537
+ <img src="{img_path}" alt="{image_file}">
538
+ </div>
539
+ <div class='image-details'>
540
+ <h3>{image_file}</h3>
541
+ <p><strong>Page:</strong> {page_num}</p>
 
542
  </div>
543
+ </div>
544
  """
545
 
546
  html += "</div>"