Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -352,7 +352,12 @@ async def get_preset_prompts(char_id, language):
|
|
352 |
|
353 |
|
354 |
async def update_preset_prompt(char_id, language):
|
355 |
-
|
|
|
|
|
|
|
|
|
|
|
356 |
avatar_image_url = id_to_avatar(char_id)
|
357 |
response = requests.get(avatar_image_url)
|
358 |
image = Image.open(io.BytesIO(response.content))
|
@@ -473,6 +478,8 @@ def update_character_gallery(language):
|
|
473 |
def select_character(evt: gr.SelectData, gallery, language):
|
474 |
print(f"Event triggered. Index: {evt.index}")
|
475 |
print(f"Selected character from gallery: {gallery[evt.index]}")
|
|
|
|
|
476 |
|
477 |
selected_char = gallery[evt.index]
|
478 |
selected_char_id = os.path.basename(selected_char[0]).split('_')[1].split('.')[0]
|
@@ -616,7 +623,6 @@ with gr.Blocks() as demo:
|
|
616 |
inputs=[char_gallery, language],
|
617 |
outputs=[selected_char_name, selected_char_id]
|
618 |
)
|
619 |
-
|
620 |
selected_char_id.change(
|
621 |
fn=update_preset_prompt,
|
622 |
inputs=[selected_char_id, language],
|
|
|
352 |
|
353 |
|
354 |
async def update_preset_prompt(char_id, language):
|
355 |
+
if not char_id:
|
356 |
+
return gr.update(), None
|
357 |
+
try:
|
358 |
+
preset_prompts = await get_preset_prompts(char_id, language)
|
359 |
+
except TypeError:
|
360 |
+
return gr.update(), None
|
361 |
avatar_image_url = id_to_avatar(char_id)
|
362 |
response = requests.get(avatar_image_url)
|
363 |
image = Image.open(io.BytesIO(response.content))
|
|
|
478 |
def select_character(evt: gr.SelectData, gallery, language):
|
479 |
print(f"Event triggered. Index: {evt.index}")
|
480 |
print(f"Selected character from gallery: {gallery[evt.index]}")
|
481 |
+
if evt.index >= len(gallery):
|
482 |
+
return None, None
|
483 |
|
484 |
selected_char = gallery[evt.index]
|
485 |
selected_char_id = os.path.basename(selected_char[0]).split('_')[1].split('.')[0]
|
|
|
623 |
inputs=[char_gallery, language],
|
624 |
outputs=[selected_char_name, selected_char_id]
|
625 |
)
|
|
|
626 |
selected_char_id.change(
|
627 |
fn=update_preset_prompt,
|
628 |
inputs=[selected_char_id, language],
|