awacke1 commited on
Commit
8c940ba
1 Parent(s): 7d03ac1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py CHANGED
@@ -599,11 +599,43 @@ def create_search_url_ai(keyword):
599
  base_url = "https://huggingface.co/spaces/awacke1/GraphicAINovel?q="
600
  return base_url + keyword.replace(' ', '+')
601
 
 
 
602
  def display_images_and_wikipedia_summaries():
603
  image_files = [f for f in os.listdir('.') if f.endswith('.png')]
604
  if not image_files:
605
  st.write("No PNG images found in the current directory.")
606
  return
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
607
 
608
  for image_file in image_files:
609
  image = Image.open(image_file)
 
599
  base_url = "https://huggingface.co/spaces/awacke1/GraphicAINovel?q="
600
  return base_url + keyword.replace(' ', '+')
601
 
602
+
603
+
604
  def display_images_and_wikipedia_summaries():
605
  image_files = [f for f in os.listdir('.') if f.endswith('.png')]
606
  if not image_files:
607
  st.write("No PNG images found in the current directory.")
608
  return
609
+
610
+ # Sort image_files based on the length of the keyword to create a visually consistent grid
611
+ image_files_sorted = sorted(image_files, key=lambda x: len(x.split('.')[0]))
612
+ # Calculate the grid size based on the sorted keywords
613
+ grid_sizes = [len(f.split('.')[0]) for f in image_files_sorted]
614
+ # Dynamically adjust column size based on keyword length
615
+ col_sizes = ['small' if size <= 4 else 'medium' if size <= 8 else 'large' for size in grid_sizes]
616
+
617
+ # Create a map for number of columns to use for each size
618
+ num_columns_map = {"small": 4, "medium": 3, "large": 2}
619
+ current_grid_size = 0
620
+
621
+ for image_file, col_size in zip(image_files_sorted, col_sizes):
622
+ if current_grid_size != num_columns_map[col_size]:
623
+ cols = st.columns(num_columns_map[col_size])
624
+ current_grid_size = num_columns_map[col_size]
625
+ col_index = 0
626
+
627
+ with cols[col_index % current_grid_size]:
628
+ image = Image.open(image_file)
629
+ st.image(image, caption=image_file, use_column_width=True)
630
+ # Display of links or other information follows here
631
+
632
+ col_index += 1
633
+
634
+ def display_images_and_wikipedia_summaries_deprecated():
635
+ image_files = [f for f in os.listdir('.') if f.endswith('.png')]
636
+ if not image_files:
637
+ st.write("No PNG images found in the current directory.")
638
+ return
639
 
640
  for image_file in image_files:
641
  image = Image.open(image_file)