Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -138,6 +138,9 @@ def prompt_generator_app(data_manager):
|
|
138 |
with gr.Group():
|
139 |
gr.Markdown("### Character Selection")
|
140 |
|
|
|
|
|
|
|
141 |
characters = data_manager.get_characters()
|
142 |
if not characters:
|
143 |
gr.Markdown("No characters available. Please add characters in the Character Creation tab.")
|
@@ -156,14 +159,11 @@ def prompt_generator_app(data_manager):
|
|
156 |
character_labels.append(f"{char['name']} ({char['gender']})")
|
157 |
character_select = gr.Gallery(label="Select Characters").style(grid=[3], height='auto')
|
158 |
|
159 |
-
selected_characters_state = gr.State([])
|
160 |
-
|
161 |
# Function to update selected characters
|
162 |
def update_selected_characters(selected_indices):
|
163 |
selected_indices = selected_indices or []
|
164 |
selected_chars = [characters[i] for i in selected_indices]
|
165 |
-
|
166 |
-
return selected_characters_state.update(value=selected_chars)
|
167 |
|
168 |
# Update the gallery
|
169 |
character_select.render(character_images)
|
@@ -191,7 +191,6 @@ def prompt_generator_app(data_manager):
|
|
191 |
prompt_tags.extend(selected_tags)
|
192 |
|
193 |
# Handle Characters
|
194 |
-
# Since Gradio's State cannot be passed directly, we retrieve it via args
|
195 |
selected_chars = args[arg_idx]
|
196 |
random_chars = args[arg_idx + 1]
|
197 |
num_random_chars = args[arg_idx + 2]
|
@@ -205,7 +204,7 @@ def prompt_generator_app(data_manager):
|
|
205 |
selected_chars = random.sample(characters, num)
|
206 |
else:
|
207 |
# selected_chars is already set from the selected characters in the gallery
|
208 |
-
|
209 |
|
210 |
# Determine the number of boys and girls
|
211 |
num_girls = sum(1 for char in selected_chars if char.get('gender') == 'Girl')
|
@@ -229,7 +228,7 @@ def prompt_generator_app(data_manager):
|
|
229 |
# Get traits for the character
|
230 |
traits = ', '.join(char['traits'])
|
231 |
# Create a description for each character
|
232 |
-
# For SDXL models, use the format "[char1] AND [char2]"
|
233 |
# Each character's description is enclosed in parentheses
|
234 |
character_description = f"({traits})"
|
235 |
character_descriptions.append(character_description)
|
|
|
138 |
with gr.Group():
|
139 |
gr.Markdown("### Character Selection")
|
140 |
|
141 |
+
# Initialize selected_characters_state before the if statement
|
142 |
+
selected_characters_state = gr.State([])
|
143 |
+
|
144 |
characters = data_manager.get_characters()
|
145 |
if not characters:
|
146 |
gr.Markdown("No characters available. Please add characters in the Character Creation tab.")
|
|
|
159 |
character_labels.append(f"{char['name']} ({char['gender']})")
|
160 |
character_select = gr.Gallery(label="Select Characters").style(grid=[3], height='auto')
|
161 |
|
|
|
|
|
162 |
# Function to update selected characters
|
163 |
def update_selected_characters(selected_indices):
|
164 |
selected_indices = selected_indices or []
|
165 |
selected_chars = [characters[i] for i in selected_indices]
|
166 |
+
return selected_chars
|
|
|
167 |
|
168 |
# Update the gallery
|
169 |
character_select.render(character_images)
|
|
|
191 |
prompt_tags.extend(selected_tags)
|
192 |
|
193 |
# Handle Characters
|
|
|
194 |
selected_chars = args[arg_idx]
|
195 |
random_chars = args[arg_idx + 1]
|
196 |
num_random_chars = args[arg_idx + 2]
|
|
|
204 |
selected_chars = random.sample(characters, num)
|
205 |
else:
|
206 |
# selected_chars is already set from the selected characters in the gallery
|
207 |
+
selected_chars = selected_chars or []
|
208 |
|
209 |
# Determine the number of boys and girls
|
210 |
num_girls = sum(1 for char in selected_chars if char.get('gender') == 'Girl')
|
|
|
228 |
# Get traits for the character
|
229 |
traits = ', '.join(char['traits'])
|
230 |
# Create a description for each character
|
231 |
+
# For SDXL models, use the format "[char1 description] AND [char2 description]"
|
232 |
# Each character's description is enclosed in parentheses
|
233 |
character_description = f"({traits})"
|
234 |
character_descriptions.append(character_description)
|