DawnC commited on
Commit
50c8543
โ€ข
1 Parent(s): 2c0def4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -25
app.py CHANGED
@@ -455,8 +455,11 @@ def show_details(choice, previous_output, initial_state):
455
  breed = choice.split("More about ")[-1]
456
  description = get_dog_description(breed)
457
  formatted_description = format_description(description, breed)
458
- initial_state["current_description"] = formatted_description # ไฟๅญ˜็•ถๅ‰้กฏ็คบ็š„ๆ่ฟฐ
459
- initial_state["show_back"] = True # ็ขบไฟ back ๆŒ‰้ˆ•ๅฏ่ฆ‹
 
 
 
460
  return formatted_description, gr.update(visible=True), initial_state
461
  except Exception as e:
462
  error_msg = f"An error occurred while showing details: {e}"
@@ -464,29 +467,16 @@ def show_details(choice, previous_output, initial_state):
464
  return error_msg, gr.update(visible=True), initial_state
465
 
466
  def go_back(state):
467
- if state.get("is_multi_dog", False):
468
- # ๆขๅพฉๅˆฐๅคš็‹—ๆƒ…ๅขƒ็š„ๅˆๅง‹็‹€ๆ…‹
469
- buttons = state.get("buttons", [])
470
- return (
471
- state["explanation"],
472
- state["image"],
473
- buttons[0] if len(buttons) > 0 else gr.update(visible=False),
474
- buttons[1] if len(buttons) > 1 else gr.update(visible=False),
475
- buttons[2] if len(buttons) > 2 else gr.update(visible=False),
476
- gr.update(visible=False), # ้šฑ่— back ๆŒ‰้ˆ•
477
- state
478
- )
479
- else:
480
- # ๅ–ฎ็‹—ๆƒ…ๅขƒ๏ผŒไธ้œ€่ฆ็‰นๆฎŠ่™•็†
481
- return (
482
- state["explanation"],
483
- state["image"],
484
- gr.update(visible=False),
485
- gr.update(visible=False),
486
- gr.update(visible=False),
487
- gr.update(visible=False),
488
- state
489
- )
490
 
491
  with gr.Blocks() as iface:
492
  gr.HTML("<h1 style='text-align: center;'>๐Ÿถ Dog Breed Classifier ๐Ÿ”</h1>")
 
455
  breed = choice.split("More about ")[-1]
456
  description = get_dog_description(breed)
457
  formatted_description = format_description(description, breed)
458
+
459
+ # ไฟๅญ˜็•ถๅ‰ๆ่ฟฐๅ’ŒๅŽŸๅง‹ๆŒ‰้ˆ•็‹€ๆ…‹
460
+ initial_state["current_description"] = formatted_description
461
+ initial_state["original_buttons"] = initial_state.get("buttons", [])
462
+
463
  return formatted_description, gr.update(visible=True), initial_state
464
  except Exception as e:
465
  error_msg = f"An error occurred while showing details: {e}"
 
467
  return error_msg, gr.update(visible=True), initial_state
468
 
469
  def go_back(state):
470
+ buttons = state.get("buttons", [])
471
+ return (
472
+ state["explanation"],
473
+ state["image"],
474
+ buttons[0] if len(buttons) > 0 else gr.update(visible=False),
475
+ buttons[1] if len(buttons) > 1 else gr.update(visible=False),
476
+ buttons[2] if len(buttons) > 2 else gr.update(visible=False),
477
+ gr.update(visible=False), # ้šฑ่— back ๆŒ‰้ˆ•
478
+ state
479
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
480
 
481
  with gr.Blocks() as iface:
482
  gr.HTML("<h1 style='text-align: center;'>๐Ÿถ Dog Breed Classifier ๐Ÿ”</h1>")