throaway2854 commited on
Commit
c8ef0ce
·
verified ·
1 Parent(s): b2f9b37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -124,10 +124,19 @@ def display_dataset_html(dataset, page_number=0, items_per_page=2):
124
  idx = start_idx + idx_offset
125
  image_data = entry['image']
126
  prompt = entry['prompt']
 
 
 
 
 
 
 
 
 
127
  html_content += f"""
128
  <div style="display: flex; flex-direction: column; align-items: center; margin-right: 20px;">'''
129
  <div style="margin-bottom: 5px;">{idx}</div>
130
- <img src="{image_data}" alt="Image {idx}" style="max-height: 150px;"/>
131
  <div style="max-width: 150px; word-wrap: break-word; text-align: center;">{prompt}</div>
132
  </div>
133
  """
@@ -444,7 +453,7 @@ with gr.Blocks() as demo:
444
 
445
  # Update all components when an entry is deleted
446
  def update_all_components_after_delete(current_dataset_name, datasets):
447
- time.sleep(2) # Add a small delay to allow other componenets to finish processing
448
  dataset = datasets[current_dataset_name]
449
  html_content = display_dataset_html(dataset, page_number=0)
450
  entry_options = [f"{idx}: {entry['prompt'][:30]}" for idx, entry in enumerate(dataset)]
 
124
  idx = start_idx + idx_offset
125
  image_data = entry['image']
126
  prompt = entry['prompt']
127
+ # Decode base64 image data to numpy array
128
+ image_bytes = base64.b64decode(image_data.split(",")[1])
129
+ image = Image.open(BytesIO(image_bytes))
130
+ # Compress image
131
+ image.thumbnail((100, 100)) # Resize image to 100x100 pixels
132
+ buffered = BytesIO()
133
+ image.save(buffered, format="PNG")
134
+ img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')
135
+ img_data = f"data:image/png;base64,{img_str}"
136
  html_content += f"""
137
  <div style="display: flex; flex-direction: column; align-items: center; margin-right: 20px;">'''
138
  <div style="margin-bottom: 5px;">{idx}</div>
139
+ <img src="{img_data}" alt="Image {idx}" style="max-height: 150px;"/>
140
  <div style="max-width: 150px; word-wrap: break-word; text-align: center;">{prompt}</div>
141
  </div>
142
  """
 
453
 
454
  # Update all components when an entry is deleted
455
  def update_all_components_after_delete(current_dataset_name, datasets):
456
+ time.sleep(0.1) # Add a small delay
457
  dataset = datasets[current_dataset_name]
458
  html_content = display_dataset_html(dataset, page_number=0)
459
  entry_options = [f"{idx}: {entry['prompt'][:30]}" for idx, entry in enumerate(dataset)]