NTEIGBANAM OKE commited on
Commit
24a03f0
·
verified ·
1 Parent(s): fe3b74d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -32
app.py CHANGED
@@ -601,7 +601,7 @@ We can use the questions farmers submit to decide which answers, calculators and
601
 
602
 
603
  # ============================================================
604
- # UPDATE BENCHMARK TABLE
605
  # ============================================================
606
 
607
  def update_benchmark(breed):
@@ -610,17 +610,16 @@ def update_benchmark(breed):
610
  return table_data
611
 
612
 
613
- def update_price(country_code):
614
- """Update default price when country changes."""
615
- _, _, currency_code = get_country_info(country_code)
616
- default_price = get_default_price(currency_code)
617
- return default_price
618
-
619
 
620
- def update_currency(country_code):
621
- """Update currency symbol when country changes."""
622
- _, symbol, _ = get_country_info(country_code)
623
- return symbol
624
 
625
 
626
  # ============================================================
@@ -700,7 +699,7 @@ with gr.Blocks(title=APP_NAME) as demo:
700
  detected_country = detect_country_from_env() or "NG"
701
 
702
  # Country dropdown with auto-detect label
703
- country_choices = ["Auto-Detect"] + [f"{code}" for code, _ in COUNTRY_LIST]
704
 
705
  country_dropdown = gr.Dropdown(
706
  choices=country_choices,
@@ -712,14 +711,6 @@ with gr.Blocks(title=APP_NAME) as demo:
712
  # Hidden state for actual country code
713
  country_code_state = gr.State(detected_country)
714
 
715
- # Currency symbol display
716
- currency_display = gr.Textbox(
717
- value="₦",
718
- label="Currency Symbol",
719
- interactive=False,
720
- visible=False,
721
- )
722
-
723
  gr.Markdown("## 🌾 4. Feed")
724
 
725
  with gr.Row():
@@ -887,21 +878,22 @@ with gr.Blocks(title=APP_NAME) as demo:
887
  )
888
 
889
  # Update price and currency when country changes
890
- def on_country_change(country_selection):
891
- if country_selection == "Auto-Detect":
892
- country_code = detect_country_from_env() or "NG"
893
- else:
894
- country_code = country_selection
895
-
896
- _, symbol, currency_code = get_country_info(country_code)
897
- default_price = get_default_price(currency_code)
898
- return country_code, default_price, symbol, f"Price per bag ({symbol})"
899
-
900
  country_dropdown.change(
901
  fn=on_country_change,
902
  inputs=[country_dropdown],
903
- outputs=[country_code_state, price, currency_display, price],
904
  )
905
 
906
  # Calculate button
907
- def
 
 
 
 
 
 
 
 
 
 
 
 
601
 
602
 
603
  # ============================================================
604
+ # UPDATE FUNCTIONS
605
  # ============================================================
606
 
607
  def update_benchmark(breed):
 
610
  return table_data
611
 
612
 
613
+ def on_country_change(country_selection):
614
+ """Update price and currency when country changes."""
615
+ if country_selection == "Auto-Detect":
616
+ country_code = detect_country_from_env() or "NG"
617
+ else:
618
+ country_code = country_selection
619
 
620
+ _, symbol, currency_code = get_country_info(country_code)
621
+ default_price = get_default_price(currency_code)
622
+ return country_code, default_price, symbol, f"Price per bag ({symbol})"
 
623
 
624
 
625
  # ============================================================
 
699
  detected_country = detect_country_from_env() or "NG"
700
 
701
  # Country dropdown with auto-detect label
702
+ country_choices = ["Auto-Detect"] + [code for code, _ in COUNTRY_LIST]
703
 
704
  country_dropdown = gr.Dropdown(
705
  choices=country_choices,
 
711
  # Hidden state for actual country code
712
  country_code_state = gr.State(detected_country)
713
 
 
 
 
 
 
 
 
 
714
  gr.Markdown("## 🌾 4. Feed")
715
 
716
  with gr.Row():
 
878
  )
879
 
880
  # Update price and currency when country changes
 
 
 
 
 
 
 
 
 
 
881
  country_dropdown.change(
882
  fn=on_country_change,
883
  inputs=[country_dropdown],
884
+ outputs=[country_code_state, price, price, price],
885
  )
886
 
887
  # Calculate button
888
+ def calculate_wrapper(birds, weeks, days, bag_size, price_per_bag, email, country_code_state, breed):
889
+ if not country_code_state:
890
+ country_code_state = "NG"
891
+ return calculate_feed(birds, weeks, days, bag_size, price_per_bag, email, country_code_state, breed)
892
+
893
+ calculate_btn.click(
894
+ fn=calculate_wrapper,
895
+ inputs=[birds, weeks, days, bag_size, price, email, country_code_state, breed],
896
+ outputs=[result, save_status],
897
+ )
898
+
899
+ ask_btn.click(