throaway2854 commited on
Commit
7251b41
·
verified ·
1 Parent(s): 0b3407c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -145,26 +145,26 @@ def prompt_generator_app(data_manager):
145
  refresh_characters_button = gr.Button("Refresh Character List")
146
 
147
  # Create a placeholder for the character_select component
148
- character_select = gr.Gallery(label="Select Characters").style(grid=[3], height='auto')
149
 
150
  # Load and display characters
151
  def load_characters():
152
  characters = data_manager.get_characters()
153
  if not characters:
154
- return [], [], []
155
  else:
156
  # Build character images and labels
157
  character_images = []
158
- character_indices = []
159
  for idx, char in enumerate(characters):
160
  image_path = char.get('image_path', '')
161
  if image_path and os.path.exists(image_path):
162
  image_url = image_path
163
  else:
164
  image_url = None # Or a placeholder image
165
- character_images.append(image_url)
166
- character_indices.append(idx)
167
- return character_images, character_indices, characters
 
168
 
169
  # Function to update selected characters
170
  def update_selected_characters(selected_indices):
@@ -175,14 +175,14 @@ def prompt_generator_app(data_manager):
175
 
176
  # Function to refresh characters
177
  def refresh_characters():
178
- character_images, character_indices, characters = load_characters()
179
  # Update character_select with new images
180
  return gr.update(value=character_images)
181
 
182
  # Load initial characters
183
- character_images, character_indices, characters = load_characters()
184
  if character_images:
185
- character_select.update(value=character_images)
186
  else:
187
  gr.Markdown("No characters available. Please add characters in the Character Creation tab.")
188
 
 
145
  refresh_characters_button = gr.Button("Refresh Character List")
146
 
147
  # Create a placeholder for the character_select component
148
+ character_select = gr.Gallery(label="Select Characters", columns=3, height='auto')
149
 
150
  # Load and display characters
151
  def load_characters():
152
  characters = data_manager.get_characters()
153
  if not characters:
154
+ return [], []
155
  else:
156
  # Build character images and labels
157
  character_images = []
 
158
  for idx, char in enumerate(characters):
159
  image_path = char.get('image_path', '')
160
  if image_path and os.path.exists(image_path):
161
  image_url = image_path
162
  else:
163
  image_url = None # Or a placeholder image
164
+ # Adding the character's name and gender as a caption
165
+ caption = f"{char['name']} ({char['gender']})"
166
+ character_images.append((image_url, caption))
167
+ return character_images, characters
168
 
169
  # Function to update selected characters
170
  def update_selected_characters(selected_indices):
 
175
 
176
  # Function to refresh characters
177
  def refresh_characters():
178
+ character_images, characters = load_characters()
179
  # Update character_select with new images
180
  return gr.update(value=character_images)
181
 
182
  # Load initial characters
183
+ character_images, characters = load_characters()
184
  if character_images:
185
+ character_select.value = character_images
186
  else:
187
  gr.Markdown("No characters available. Please add characters in the Character Creation tab.")
188