Spaces:
Paused
Paused
NTEIGBANAM OKE commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -117,6 +117,50 @@ def interpolate_feed(day, breed):
|
|
| 117 |
return feed_data[56]
|
| 118 |
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
# ============================================================
|
| 121 |
# CURRENCY
|
| 122 |
# ============================================================
|
|
@@ -373,7 +417,7 @@ def calculate_feed(birds, weeks, days, bag_size, price_per_bag, email, country_c
|
|
| 373 |
<div style="background: #f0fdf4; padding: 16px 20px; border-radius: 12px; border-left: 5px solid #22c55e; margin-bottom: 20px;">
|
| 374 |
<div style="font-size: 14px; color: #16a34a; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;">π― Quick Answer</div>
|
| 375 |
<div style="font-size: 22px; font-weight: 700; color: #166534;">
|
| 376 |
-
{rounded_bags} bags of {bag_size:g} kg feed
|
| 377 |
</div>
|
| 378 |
<div style="color: #4b5563; margin-top: 4px;">
|
| 379 |
To raise <strong>{birds:,} birds</strong> for <strong>{age_text} ({total_days} days)</strong>
|
|
@@ -530,6 +574,16 @@ def get_country_info():
|
|
| 530 |
DEFAULT_COUNTRY, DEFAULT_CURRENCY = get_country_info()
|
| 531 |
|
| 532 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 533 |
# ============================================================
|
| 534 |
# CSS
|
| 535 |
# ============================================================
|
|
@@ -648,26 +702,48 @@ with gr.Blocks(title=APP_NAME, css=CSS) as demo:
|
|
| 648 |
elem_classes=["answer-box"],
|
| 649 |
)
|
| 650 |
|
| 651 |
-
#
|
|
|
|
|
|
|
|
|
|
| 652 |
gr.Markdown("---")
|
| 653 |
|
| 654 |
-
with gr.
|
| 655 |
-
with gr.
|
| 656 |
-
gr.Markdown(""
|
| 657 |
-
# β Ask a question
|
| 658 |
-
### What would you like to know about raising your birds?
|
| 659 |
-
""")
|
| 660 |
|
| 661 |
-
|
| 662 |
-
|
| 663 |
-
|
| 664 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 665 |
)
|
| 666 |
|
| 667 |
-
|
| 668 |
-
|
| 669 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 670 |
# BREED REFERENCE
|
|
|
|
|
|
|
| 671 |
gr.Markdown("---")
|
| 672 |
|
| 673 |
gr.Markdown("""
|
|
@@ -682,26 +758,13 @@ with gr.Blocks(title=APP_NAME, css=CSS) as demo:
|
|
| 682 |
π‘ **Tip:** Before buying chicks, ask about the breed and hatchery. Not all broilers are the same!
|
| 683 |
""")
|
| 684 |
|
| 685 |
-
#
|
|
|
|
|
|
|
|
|
|
| 686 |
gr.Markdown("---")
|
| 687 |
|
| 688 |
with gr.Row():
|
| 689 |
-
with gr.Column(scale=1):
|
| 690 |
-
gr.Markdown("""
|
| 691 |
-
### π Ross 308 Weekly Benchmark
|
| 692 |
-
|
| 693 |
-
| Days | Body Weight (kg) | Cum Feed (kg) |
|
| 694 |
-
|------|------------------|---------------|
|
| 695 |
-
| 7 | 0.213 | 0.166 |
|
| 696 |
-
| 14 | 0.533 | 0.535 |
|
| 697 |
-
| 21 | 1.012 | 1.155 |
|
| 698 |
-
| 28 | 1.616 | 2.051 |
|
| 699 |
-
| 35 | 2.296 | 3.211 |
|
| 700 |
-
| 42 | 2.998 | 4.586 |
|
| 701 |
-
| 49 | 3.681 | 6.115 |
|
| 702 |
-
| 56 | 4.318 | 7.733 |
|
| 703 |
-
""")
|
| 704 |
-
|
| 705 |
with gr.Column(scale=1):
|
| 706 |
gr.Markdown("""
|
| 707 |
### π How it works
|
|
@@ -715,7 +778,28 @@ with gr.Blocks(title=APP_NAME, css=CSS) as demo:
|
|
| 715 |
β οΈ Actual results may vary with management, feed quality, and other conditions.
|
| 716 |
""")
|
| 717 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 718 |
# EVENTS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 719 |
calculate_btn.click(
|
| 720 |
fn=calculate_feed,
|
| 721 |
inputs=[birds, weeks, days, bag_size, price, email, country_state, breed],
|
|
|
|
| 117 |
return feed_data[56]
|
| 118 |
|
| 119 |
|
| 120 |
+
# ============================================================
|
| 121 |
+
# BENCHMARK TABLE GENERATOR
|
| 122 |
+
# ============================================================
|
| 123 |
+
|
| 124 |
+
def get_benchmark_table(breed):
|
| 125 |
+
"""Generate benchmark table for the selected breed."""
|
| 126 |
+
weight_data = get_breed_weight_data(breed)
|
| 127 |
+
feed_data = get_breed_feed_data(breed)
|
| 128 |
+
|
| 129 |
+
days = [7, 14, 21, 28, 35, 42, 49, 56]
|
| 130 |
+
|
| 131 |
+
table_data = []
|
| 132 |
+
for day in days:
|
| 133 |
+
weight = weight_data.get(day, 0)
|
| 134 |
+
feed = feed_data.get(day, 0)
|
| 135 |
+
# Calculate FCR = feed / weight
|
| 136 |
+
fcr = feed / weight if weight > 0 else 0
|
| 137 |
+
table_data.append([day, f"{weight:.3f}", f"{feed:.3f}", f"{fcr:.3f}"])
|
| 138 |
+
|
| 139 |
+
return table_data, days
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def get_breed_comparison_table():
|
| 143 |
+
"""Generate comparison table for all three breeds."""
|
| 144 |
+
breeds = ["Ross 308", "Cobb 500", "Arbor Acres"]
|
| 145 |
+
days = [7, 14, 21, 28, 35, 42, 49, 56]
|
| 146 |
+
|
| 147 |
+
table_data = []
|
| 148 |
+
for day in days:
|
| 149 |
+
row = [day]
|
| 150 |
+
for breed in breeds:
|
| 151 |
+
weight_data = get_breed_weight_data(breed)
|
| 152 |
+
feed_data = get_breed_feed_data(breed)
|
| 153 |
+
weight = weight_data.get(day, 0)
|
| 154 |
+
feed = feed_data.get(day, 0)
|
| 155 |
+
fcr = feed / weight if weight > 0 else 0
|
| 156 |
+
row.append(f"{weight:.3f}")
|
| 157 |
+
row.append(f"{feed:.3f}")
|
| 158 |
+
row.append(f"{fcr:.3f}")
|
| 159 |
+
table_data.append(row)
|
| 160 |
+
|
| 161 |
+
return table_data, breeds, days
|
| 162 |
+
|
| 163 |
+
|
| 164 |
# ============================================================
|
| 165 |
# CURRENCY
|
| 166 |
# ============================================================
|
|
|
|
| 417 |
<div style="background: #f0fdf4; padding: 16px 20px; border-radius: 12px; border-left: 5px solid #22c55e; margin-bottom: 20px;">
|
| 418 |
<div style="font-size: 14px; color: #16a34a; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px;">π― Quick Answer</div>
|
| 419 |
<div style="font-size: 22px; font-weight: 700; color: #166534;">
|
| 420 |
+
You will need approximately {rounded_bags} bags of {bag_size:g} kg feed
|
| 421 |
</div>
|
| 422 |
<div style="color: #4b5563; margin-top: 4px;">
|
| 423 |
To raise <strong>{birds:,} birds</strong> for <strong>{age_text} ({total_days} days)</strong>
|
|
|
|
| 574 |
DEFAULT_COUNTRY, DEFAULT_CURRENCY = get_country_info()
|
| 575 |
|
| 576 |
|
| 577 |
+
# ============================================================
|
| 578 |
+
# UPDATE BENCHMARK TABLE
|
| 579 |
+
# ============================================================
|
| 580 |
+
|
| 581 |
+
def update_benchmark(breed):
|
| 582 |
+
"""Update the benchmark table when breed changes."""
|
| 583 |
+
table_data, days = get_benchmark_table(breed)
|
| 584 |
+
return table_data
|
| 585 |
+
|
| 586 |
+
|
| 587 |
# ============================================================
|
| 588 |
# CSS
|
| 589 |
# ============================================================
|
|
|
|
| 702 |
elem_classes=["answer-box"],
|
| 703 |
)
|
| 704 |
|
| 705 |
+
# ============================================================
|
| 706 |
+
# BENCHMARK SECTION - Dynamic Tables
|
| 707 |
+
# ============================================================
|
| 708 |
+
|
| 709 |
gr.Markdown("---")
|
| 710 |
|
| 711 |
+
with gr.Tabs():
|
| 712 |
+
with gr.TabItem("π Selected Breed Benchmark"):
|
| 713 |
+
gr.Markdown("### π Weekly Benchmark for Selected Breed")
|
|
|
|
|
|
|
|
|
|
| 714 |
|
| 715 |
+
# Get initial benchmark table
|
| 716 |
+
initial_table, _ = get_benchmark_table("Ross 308")
|
| 717 |
+
|
| 718 |
+
benchmark_table = gr.Dataframe(
|
| 719 |
+
value=initial_table,
|
| 720 |
+
headers=["Days", "Body Weight (kg)", "Cumulative Feed (kg)", "FCR"],
|
| 721 |
+
interactive=False,
|
| 722 |
+
wrap=True,
|
| 723 |
)
|
| 724 |
|
| 725 |
+
with gr.TabItem("π Breed Comparison"):
|
| 726 |
+
gr.Markdown("### π Breed Comparison (As-Hatched Performance)")
|
| 727 |
|
| 728 |
+
comp_data, breeds, days = get_breed_comparison_table()
|
| 729 |
+
|
| 730 |
+
headers = ["Days"]
|
| 731 |
+
for breed in breeds:
|
| 732 |
+
headers.append(f"{breed} Weight (kg)")
|
| 733 |
+
headers.append(f"{breed} Feed (kg)")
|
| 734 |
+
headers.append(f"{breed} FCR")
|
| 735 |
+
|
| 736 |
+
comparison_table = gr.Dataframe(
|
| 737 |
+
value=comp_data,
|
| 738 |
+
headers=headers,
|
| 739 |
+
interactive=False,
|
| 740 |
+
wrap=True,
|
| 741 |
+
)
|
| 742 |
+
|
| 743 |
+
# ============================================================
|
| 744 |
# BREED REFERENCE
|
| 745 |
+
# ============================================================
|
| 746 |
+
|
| 747 |
gr.Markdown("---")
|
| 748 |
|
| 749 |
gr.Markdown("""
|
|
|
|
| 758 |
π‘ **Tip:** Before buying chicks, ask about the breed and hatchery. Not all broilers are the same!
|
| 759 |
""")
|
| 760 |
|
| 761 |
+
# ============================================================
|
| 762 |
+
# HOW IT WORKS
|
| 763 |
+
# ============================================================
|
| 764 |
+
|
| 765 |
gr.Markdown("---")
|
| 766 |
|
| 767 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 768 |
with gr.Column(scale=1):
|
| 769 |
gr.Markdown("""
|
| 770 |
### π How it works
|
|
|
|
| 778 |
β οΈ Actual results may vary with management, feed quality, and other conditions.
|
| 779 |
""")
|
| 780 |
|
| 781 |
+
with gr.Column(scale=1):
|
| 782 |
+
gr.Markdown("""
|
| 783 |
+
### π Data Sources
|
| 784 |
+
|
| 785 |
+
- **Ross 308** β Aviagen (2022)
|
| 786 |
+
- **Cobb 500** β Cobb-Vantress
|
| 787 |
+
- **Arbor Acres** β Aviagen (2022)
|
| 788 |
+
|
| 789 |
+
*All data from official breed performance objectives.*
|
| 790 |
+
""")
|
| 791 |
+
|
| 792 |
+
# ============================================================
|
| 793 |
# EVENTS
|
| 794 |
+
# ============================================================
|
| 795 |
+
|
| 796 |
+
# Update benchmark table when breed changes
|
| 797 |
+
breed.change(
|
| 798 |
+
fn=update_benchmark,
|
| 799 |
+
inputs=breed,
|
| 800 |
+
outputs=benchmark_table,
|
| 801 |
+
)
|
| 802 |
+
|
| 803 |
calculate_btn.click(
|
| 804 |
fn=calculate_feed,
|
| 805 |
inputs=[birds, weeks, days, bag_size, price, email, country_state, breed],
|