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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# ============================================================
|
| 7 |
+
# ROSS 308 / ROSS 308 FF — AS-HATCHED PERFORMANCE OBJECTIVES
|
| 8 |
+
# Weekly checkpoints based on Aviagen performance objectives.
|
| 9 |
+
# ============================================================
|
| 10 |
+
|
| 11 |
+
ROSS_WEEKLY = pd.DataFrame([
|
| 12 |
+
{
|
| 13 |
+
"Week": 0,
|
| 14 |
+
"Day": 0,
|
| 15 |
+
"Body Weight (kg/bird)": 0.044,
|
| 16 |
+
"Daily Intake (g/bird/day)": None,
|
| 17 |
+
"Cumulative Feed (kg/bird)": 0.000,
|
| 18 |
+
"FCR": None,
|
| 19 |
+
},
|
| 20 |
+
{
|
| 21 |
+
"Week": 1,
|
| 22 |
+
"Day": 7,
|
| 23 |
+
"Body Weight (kg/bird)": 0.213,
|
| 24 |
+
"Daily Intake (g/bird/day)": 35,
|
| 25 |
+
"Cumulative Feed (kg/bird)": 0.166,
|
| 26 |
+
"FCR": 0.780,
|
| 27 |
+
},
|
| 28 |
+
{
|
| 29 |
+
"Week": 2,
|
| 30 |
+
"Day": 14,
|
| 31 |
+
"Body Weight (kg/bird)": 0.533,
|
| 32 |
+
"Daily Intake (g/bird/day)": 67,
|
| 33 |
+
"Cumulative Feed (kg/bird)": 0.535,
|
| 34 |
+
"FCR": 1.005,
|
| 35 |
+
},
|
| 36 |
+
{
|
| 37 |
+
"Week": 3,
|
| 38 |
+
"Day": 21,
|
| 39 |
+
"Body Weight (kg/bird)": 1.046,
|
| 40 |
+
"Daily Intake (g/bird/day)": 111,
|
| 41 |
+
"Cumulative Feed (kg/bird)": 1.193,
|
| 42 |
+
"FCR": 1.141,
|
| 43 |
+
},
|
| 44 |
+
{
|
| 45 |
+
"Week": 4,
|
| 46 |
+
"Day": 28,
|
| 47 |
+
"Body Weight (kg/bird)": 1.697,
|
| 48 |
+
"Daily Intake (g/bird/day)": 155,
|
| 49 |
+
"Cumulative Feed (kg/bird)": 2.147,
|
| 50 |
+
"FCR": 1.266,
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"Week": 5,
|
| 54 |
+
"Day": 35,
|
| 55 |
+
"Body Weight (kg/bird)": 2.441,
|
| 56 |
+
"Daily Intake (g/bird/day)": 195,
|
| 57 |
+
"Cumulative Feed (kg/bird)": 3.394,
|
| 58 |
+
"FCR": 1.390,
|
| 59 |
+
},
|
| 60 |
+
{
|
| 61 |
+
"Week": 6,
|
| 62 |
+
"Day": 42,
|
| 63 |
+
"Body Weight (kg/bird)": 3.222,
|
| 64 |
+
"Daily Intake (g/bird/day)": 226,
|
| 65 |
+
"Cumulative Feed (kg/bird)": 4.886,
|
| 66 |
+
"FCR": 1.517,
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"Week": 7,
|
| 70 |
+
"Day": 49,
|
| 71 |
+
"Body Weight (kg/bird)": 3.991,
|
| 72 |
+
"Daily Intake (g/bird/day)": 247,
|
| 73 |
+
"Cumulative Feed (kg/bird)": 6.556,
|
| 74 |
+
"FCR": 1.643,
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"Week": 8,
|
| 78 |
+
"Day": 56,
|
| 79 |
+
"Body Weight (kg/bird)": 4.714,
|
| 80 |
+
"Daily Intake (g/bird/day)": 258,
|
| 81 |
+
"Cumulative Feed (kg/bird)": 8.332,
|
| 82 |
+
"FCR": 1.768,
|
| 83 |
+
},
|
| 84 |
+
])
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
# ============================================================
|
| 88 |
+
# CALCULATOR
|
| 89 |
+
# ============================================================
|
| 90 |
+
|
| 91 |
+
def calculate(
|
| 92 |
+
birds,
|
| 93 |
+
age,
|
| 94 |
+
bag_size,
|
| 95 |
+
bag_price,
|
| 96 |
+
actual_feed,
|
| 97 |
+
actual_weight,
|
| 98 |
+
):
|
| 99 |
+
"""
|
| 100 |
+
Calculate expected feed requirement, bags, cost,
|
| 101 |
+
benchmark weight and optional farm comparison.
|
| 102 |
+
"""
|
| 103 |
+
|
| 104 |
+
# ----------------------------
|
| 105 |
+
# Clean inputs
|
| 106 |
+
# ----------------------------
|
| 107 |
+
|
| 108 |
+
try:
|
| 109 |
+
birds = max(1, int(birds))
|
| 110 |
+
except Exception:
|
| 111 |
+
birds = 100
|
| 112 |
+
|
| 113 |
+
try:
|
| 114 |
+
age = int(age)
|
| 115 |
+
except Exception:
|
| 116 |
+
age = 6
|
| 117 |
+
|
| 118 |
+
try:
|
| 119 |
+
bag_size = max(1.0, float(bag_size))
|
| 120 |
+
except Exception:
|
| 121 |
+
bag_size = 25.0
|
| 122 |
+
|
| 123 |
+
try:
|
| 124 |
+
bag_price = max(0.0, float(bag_price))
|
| 125 |
+
except Exception:
|
| 126 |
+
bag_price = 24000.0
|
| 127 |
+
|
| 128 |
+
try:
|
| 129 |
+
actual_feed = max(0.0, float(actual_feed))
|
| 130 |
+
except Exception:
|
| 131 |
+
actual_feed = 0.0
|
| 132 |
+
|
| 133 |
+
try:
|
| 134 |
+
actual_weight = max(0.0, float(actual_weight))
|
| 135 |
+
except Exception:
|
| 136 |
+
actual_weight = 0.0
|
| 137 |
+
|
| 138 |
+
# Make sure age is valid.
|
| 139 |
+
if age < 1:
|
| 140 |
+
age = 1
|
| 141 |
+
|
| 142 |
+
if age > 8:
|
| 143 |
+
age = 8
|
| 144 |
+
|
| 145 |
+
# ----------------------------
|
| 146 |
+
# Get Ross benchmark
|
| 147 |
+
# ----------------------------
|
| 148 |
+
|
| 149 |
+
row = ROSS_WEEKLY.loc[
|
| 150 |
+
ROSS_WEEKLY["Week"] == age
|
| 151 |
+
].iloc[0]
|
| 152 |
+
|
| 153 |
+
cumulative_feed = float(
|
| 154 |
+
row["Cumulative Feed (kg/bird)"]
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
body_weight = float(
|
| 158 |
+
row["Body Weight (kg/bird)"]
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
daily_intake = row[
|
| 162 |
+
"Daily Intake (g/bird/day)"
|
| 163 |
+
]
|
| 164 |
+
|
| 165 |
+
fcr = row["FCR"]
|
| 166 |
+
|
| 167 |
+
# ----------------------------
|
| 168 |
+
# Feed calculations
|
| 169 |
+
# ----------------------------
|
| 170 |
+
|
| 171 |
+
expected_feed_total = (
|
| 172 |
+
birds * cumulative_feed
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
expected_bags = (
|
| 176 |
+
expected_feed_total / bag_size
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
bags_to_buy = math.ceil(
|
| 180 |
+
expected_bags
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
expected_cost = (
|
| 184 |
+
bags_to_buy * bag_price
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
expected_live_weight = (
|
| 188 |
+
birds * body_weight
|
| 189 |
+
)
|
| 190 |
+
|
| 191 |
+
bags_25kg = (
|
| 192 |
+
expected_feed_total / 25.0
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
# ----------------------------
|
| 196 |
+
# Summary
|
| 197 |
+
# ----------------------------
|
| 198 |
+
|
| 199 |
+
summary = f"""
|
| 200 |
+
## 🐔 Results — Week {age}
|
| 201 |
+
|
| 202 |
+
| Metric | Result |
|
| 203 |
+
|---|---:|
|
| 204 |
+
| Expected weight / bird | **{body_weight:.2f} kg** |
|
| 205 |
+
| Cumulative feed / bird | **{cumulative_feed:.2f} kg** |
|
| 206 |
+
| Feed needed for {birds:,} birds | **{expected_feed_total:,.1f} kg** |
|
| 207 |
+
| Exact bags at {bag_size:g} kg | **{expected_bags:,.2f} bags** |
|
| 208 |
+
| Whole bags to buy | **{bags_to_buy:,}** |
|
| 209 |
+
| Estimated feed cost | **₦{expected_cost:,.0f}** |
|
| 210 |
+
| Expected flock live weight | **{expected_live_weight:,.1f} kg** |
|
| 211 |
+
| 25-kg equivalent bags | **{bags_25kg:,.1f}** |
|
| 212 |
+
"""
|
| 213 |
+
|
| 214 |
+
# ----------------------------
|
| 215 |
+
# Benchmark
|
| 216 |
+
# ----------------------------
|
| 217 |
+
|
| 218 |
+
daily_intake_text = (
|
| 219 |
+
"-"
|
| 220 |
+
if pd.isna(daily_intake)
|
| 221 |
+
else f"{int(daily_intake)}"
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
fcr_text = (
|
| 225 |
+
"-"
|
| 226 |
+
if pd.isna(fcr)
|
| 227 |
+
else f"{float(fcr):.3f}"
|
| 228 |
+
)
|
| 229 |
+
|
| 230 |
+
benchmark = f"""
|
| 231 |
+
## 📊 Ross 308 benchmark — Week {age}
|
| 232 |
+
|
| 233 |
+
- **Body weight:** {body_weight:.3f} kg/bird
|
| 234 |
+
- **Daily feed intake at checkpoint:** {daily_intake_text} g/bird/day
|
| 235 |
+
- **Cumulative feed:** {cumulative_feed:.3f} kg/bird
|
| 236 |
+
- **Benchmark FCR:** {fcr_text}
|
| 237 |
+
"""
|
| 238 |
+
|
| 239 |
+
# ----------------------------
|
| 240 |
+
# Farm comparison
|
| 241 |
+
# ----------------------------
|
| 242 |
+
|
| 243 |
+
comparison = ""
|
| 244 |
+
|
| 245 |
+
if actual_feed > 0 or actual_weight > 0:
|
| 246 |
+
|
| 247 |
+
lines = [
|
| 248 |
+
"## 📈 Your farm vs benchmark"
|
| 249 |
+
]
|
| 250 |
+
|
| 251 |
+
if actual_feed > 0:
|
| 252 |
+
|
| 253 |
+
feed_diff = (
|
| 254 |
+
actual_feed
|
| 255 |
+
- expected_feed_total
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
lines.append(
|
| 259 |
+
f"- **Actual feed used:** "
|
| 260 |
+
f"{actual_feed:,.1f} kg "
|
| 261 |
+
f"({feed_diff:+,.1f} kg vs benchmark)"
|
| 262 |
+
)
|
| 263 |
+
|
| 264 |
+
if actual_weight > 0:
|
| 265 |
+
|
| 266 |
+
weight_diff = (
|
| 267 |
+
actual_weight
|
| 268 |
+
- body_weight
|
| 269 |
+
)
|
| 270 |
+
|
| 271 |
+
lines.append(
|
| 272 |
+
f"- **Actual average weight:** "
|
| 273 |
+
f"{actual_weight:.2f} kg "
|
| 274 |
+
f"({weight_diff:+.2f} kg vs benchmark)"
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
if actual_weight > 0 and actual_feed > 0:
|
| 278 |
+
|
| 279 |
+
# Starting chick weight.
|
| 280 |
+
starting_weight = 0.044
|
| 281 |
+
|
| 282 |
+
gain_per_bird = (
|
| 283 |
+
actual_weight
|
| 284 |
+
- starting_weight
|
| 285 |
+
)
|
| 286 |
+
|
| 287 |
+
total_gain = (
|
| 288 |
+
birds * gain_per_bird
|
| 289 |
+
)
|
| 290 |
+
|
| 291 |
+
if total_gain > 0:
|
| 292 |
+
|
| 293 |
+
actual_fcr = (
|
| 294 |
+
actual_feed
|
| 295 |
+
/ total_gain
|
| 296 |
+
)
|
| 297 |
+
|
| 298 |
+
lines.append(
|
| 299 |
+
f"- **Approx. FCR:** "
|
| 300 |
+
f"{actual_fcr:.3f}"
|
| 301 |
+
)
|
| 302 |
+
|
| 303 |
+
else:
|
| 304 |
+
|
| 305 |
+
lines.append(
|
| 306 |
+
"- **Approx. FCR:** "
|
| 307 |
+
"not available yet"
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
comparison = "\n".join(lines)
|
| 311 |
+
|
| 312 |
+
return (
|
| 313 |
+
summary,
|
| 314 |
+
benchmark,
|
| 315 |
+
comparison,
|
| 316 |
+
)
|
| 317 |
+
|
| 318 |
+
|
| 319 |
+
# ============================================================
|
| 320 |
+
# BENCHMARK TABLE
|
| 321 |
+
# ============================================================
|
| 322 |
+
|
| 323 |
+
def benchmark_table():
|
| 324 |
+
|
| 325 |
+
display = ROSS_WEEKLY.copy()
|
| 326 |
+
|
| 327 |
+
display[
|
| 328 |
+
"Body Weight (kg/bird)"
|
| 329 |
+
] = display[
|
| 330 |
+
"Body Weight (kg/bird)"
|
| 331 |
+
].map(
|
| 332 |
+
lambda x: f"{x:.3f}"
|
| 333 |
+
)
|
| 334 |
+
|
| 335 |
+
display[
|
| 336 |
+
"Cumulative Feed (kg/bird)"
|
| 337 |
+
] = display[
|
| 338 |
+
"Cumulative Feed (kg/bird)"
|
| 339 |
+
].map(
|
| 340 |
+
lambda x: f"{x:.3f}"
|
| 341 |
+
)
|
| 342 |
+
|
| 343 |
+
display[
|
| 344 |
+
"Daily Intake (g/bird/day)"
|
| 345 |
+
] = display[
|
| 346 |
+
"Daily Intake (g/bird/day)"
|
| 347 |
+
].map(
|
| 348 |
+
lambda x:
|
| 349 |
+
"-"
|
| 350 |
+
if pd.isna(x)
|
| 351 |
+
else f"{int(x)}"
|
| 352 |
+
)
|
| 353 |
+
|
| 354 |
+
display["FCR"] = display[
|
| 355 |
+
"FCR"
|
| 356 |
+
].map(
|
| 357 |
+
lambda x:
|
| 358 |
+
"-"
|
| 359 |
+
if pd.isna(x)
|
| 360 |
+
else f"{x:.3f}"
|
| 361 |
+
)
|
| 362 |
+
|
| 363 |
+
return display
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
# ============================================================
|
| 367 |
+
# GRADIO APP
|
| 368 |
+
# ============================================================
|
| 369 |
+
|
| 370 |
+
with gr.Blocks(
|
| 371 |
+
title="PoultryFeedCalc"
|
| 372 |
+
) as demo:
|
| 373 |
+
|
| 374 |
+
gr.Markdown(
|
| 375 |
+
"""
|
| 376 |
+
# 🐔 PoultryFeedCalc
|
| 377 |
+
|
| 378 |
+
### Broiler feed, weight and cost calculator — Nigeria MVP
|
| 379 |
+
|
| 380 |
+
Use this calculator to estimate feed requirements,
|
| 381 |
+
feed bags, feed cost and expected broiler weight.
|
| 382 |
+
"""
|
| 383 |
+
)
|
| 384 |
+
|
| 385 |
+
gr.Markdown(
|
| 386 |
+
"""
|
| 387 |
+
**Important:** Ross performance objectives are used as
|
| 388 |
+
the numerical benchmark. Nigerian management guidance
|
| 389 |
+
is presented separately and should not be treated as
|
| 390 |
+
a replacement for veterinary or farm-specific advice.
|
| 391 |
+
"""
|
| 392 |
+
)
|
| 393 |
+
|
| 394 |
+
# ========================================================
|
| 395 |
+
# INPUT / RESULTS
|
| 396 |
+
# ========================================================
|
| 397 |
+
|
| 398 |
+
with gr.Row():
|
| 399 |
+
|
| 400 |
+
# ----------------------------------------------------
|
| 401 |
+
# INPUTS
|
| 402 |
+
# ----------------------------------------------------
|
| 403 |
+
|
| 404 |
+
with gr.Column(scale=1):
|
| 405 |
+
|
| 406 |
+
gr.Markdown(
|
| 407 |
+
"## 🧮 Farm inputs"
|
| 408 |
+
)
|
| 409 |
+
|
| 410 |
+
birds = gr.Number(
|
| 411 |
+
label="Number of birds",
|
| 412 |
+
minimum=1,
|
| 413 |
+
value=100,
|
| 414 |
+
precision=0,
|
| 415 |
+
)
|
| 416 |
+
|
| 417 |
+
age = gr.Dropdown(
|
| 418 |
+
label="Target age",
|
| 419 |
+
choices=list(range(1, 9)),
|
| 420 |
+
value=6,
|
| 421 |
+
)
|
| 422 |
+
|
| 423 |
+
bag_size = gr.Number(
|
| 424 |
+
label="Feed bag size (kg)",
|
| 425 |
+
minimum=1,
|
| 426 |
+
value=25,
|
| 427 |
+
)
|
| 428 |
+
|
| 429 |
+
bag_price = gr.Number(
|
| 430 |
+
label="Price per bag (₦)",
|
| 431 |
+
minimum=0,
|
| 432 |
+
value=24000,
|
| 433 |
+
)
|
| 434 |
+
|
| 435 |
+
gr.Markdown(
|
| 436 |
+
"### Optional actual farm figures"
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
actual_feed = gr.Number(
|
| 440 |
+
label="Feed already used (kg)",
|
| 441 |
+
minimum=0,
|
| 442 |
+
value=0,
|
| 443 |
+
)
|
| 444 |
+
|
| 445 |
+
actual_weight = gr.Number(
|
| 446 |
+
label="Current average weight (kg/bird)",
|
| 447 |
+
minimum=0,
|
| 448 |
+
value=0,
|
| 449 |
+
)
|
| 450 |
+
|
| 451 |
+
calculate_btn = gr.Button(
|
| 452 |
+
"🐔 Calculate",
|
| 453 |
+
variant="primary",
|
| 454 |
+
)
|
| 455 |
+
|
| 456 |
+
# ----------------------------------------------------
|
| 457 |
+
# RESULTS
|
| 458 |
+
# ----------------------------------------------------
|
| 459 |
+
|
| 460 |
+
with gr.Column(scale=2):
|
| 461 |
+
|
| 462 |
+
summary = gr.Markdown()
|
| 463 |
+
|
| 464 |
+
benchmark = gr.Markdown()
|
| 465 |
+
|
| 466 |
+
comparison = gr.Markdown()
|
| 467 |
+
|
| 468 |
+
# ========================================================
|
| 469 |
+
# BENCHMARK TABLE
|
| 470 |
+
# ========================================================
|
| 471 |
+
|
| 472 |
+
gr.Markdown(
|
| 473 |
+
"## 📊 Ross 308 weekly benchmark"
|
| 474 |
+
)
|
| 475 |
+
|
| 476 |
+
gr.Dataframe(
|
| 477 |
+
value=benchmark_table(),
|
| 478 |
+
interactive=False,
|
| 479 |
+
wrap=True,
|
| 480 |
+
)
|
| 481 |
+
|
| 482 |
+
# ========================================================
|
| 483 |
+
# NIGERIA MANAGEMENT REFERENCE
|
| 484 |
+
# ========================================================
|
| 485 |
+
|
| 486 |
+
gr.Markdown(
|
| 487 |
+
"## 🇳🇬 Nigeria management reference"
|
| 488 |
+
)
|
| 489 |
+
|
| 490 |
+
gr.Info(
|
| 491 |
+
"""
|
| 492 |
+
Agrited's Nigeria broiler guide is kept separate from
|
| 493 |
+
the Ross numerical benchmark.
|
| 494 |
+
|
| 495 |
+
It covers brooding temperature, crop-fill checks,
|
| 496 |
+
7-day weight and mortality monitoring, ventilation,
|
| 497 |
+
feed handling, water quality, stocking density,
|
| 498 |
+
vaccination handling and biosecurity.
|
| 499 |
+
"""
|
| 500 |
+
)
|
| 501 |
+
|
| 502 |
+
with gr.Row():
|
| 503 |
+
|
| 504 |
+
with gr.Column():
|
| 505 |
+
|
| 506 |
+
gr.Markdown(
|
| 507 |
+
"""
|
| 508 |
+
### 🌡️ Brooding
|
| 509 |
+
|
| 510 |
+
Agrited guidance:
|
| 511 |
+
|
| 512 |
+
Start warming the brooding area
|
| 513 |
+
24–48 hours before chick arrival.
|
| 514 |
+
|
| 515 |
+
Initial chick-level temperature:
|
| 516 |
+
**31–33°C**
|
| 517 |
+
|
| 518 |
+
Temperature is reduced progressively
|
| 519 |
+
toward approximately **21°C by day 28**.
|
| 520 |
+
"""
|
| 521 |
+
)
|
| 522 |
+
|
| 523 |
+
with gr.Column():
|
| 524 |
+
|
| 525 |
+
gr.Markdown(
|
| 526 |
+
"""
|
| 527 |
+
### 💧 Water
|
| 528 |
+
|
| 529 |
+
Use tested water.
|
| 530 |
+
|
| 531 |
+
Reference pH:
|
| 532 |
+
**5.5–7.5**
|
| 533 |
+
|
| 534 |
+
Avoid supplying water above
|
| 535 |
+
approximately **30°C**.
|
| 536 |
+
"""
|
| 537 |
+
)
|
| 538 |
+
|
| 539 |
+
with gr.Column():
|
| 540 |
+
|
| 541 |
+
gr.Markdown(
|
| 542 |
+
"""
|
| 543 |
+
### 🐔 Stocking density
|
| 544 |
+
|
| 545 |
+
Agrited reference:
|
| 546 |
+
|
| 547 |
+
Around **25 kg live weight/m²**
|
| 548 |
+
at slaughter for hot Nigerian conditions.
|
| 549 |
+
|
| 550 |
+
Actual stocking density should account
|
| 551 |
+
for house design, ventilation and climate.
|
| 552 |
+
"""
|
| 553 |
+
)
|
| 554 |
+
|
| 555 |
+
# ========================================================
|
| 556 |
+
# SOURCES / DISCLAIMER
|
| 557 |
+
# ========================================================
|
| 558 |
+
|
| 559 |
+
gr.Markdown(
|
| 560 |
+
"""
|
| 561 |
+
---
|
| 562 |
+
|
| 563 |
+
### 📚 References
|
| 564 |
+
|
| 565 |
+
**Benchmark source:**
|
| 566 |
+
Aviagen — Ross 308 / Ross 308 FF Broiler Performance Objectives (2022).
|
| 567 |
+
|
| 568 |
+
**Nigeria management reference:**
|
| 569 |
+
Agrited — *Everything You Need To Know About Raising Excellent Broiler Chickens in Nigeria*.
|
| 570 |
+
|
| 571 |
+
This MVP is a planning and calculation tool.
|
| 572 |
+
It is not veterinary advice.
|
| 573 |
+
"""
|
| 574 |
+
)
|
| 575 |
+
|
| 576 |
+
# ========================================================
|
| 577 |
+
# BUTTON ACTION
|
| 578 |
+
# ========================================================
|
| 579 |
+
|
| 580 |
+
calculate_btn.click(
|
| 581 |
+
fn=calculate,
|
| 582 |
+
inputs=[
|
| 583 |
+
birds,
|
| 584 |
+
age,
|
| 585 |
+
bag_size,
|
| 586 |
+
bag_price,
|
| 587 |
+
actual_feed,
|
| 588 |
+
actual_weight,
|
| 589 |
+
],
|
| 590 |
+
outputs=[
|
| 591 |
+
summary,
|
| 592 |
+
benchmark,
|
| 593 |
+
comparison,
|
| 594 |
+
],
|
| 595 |
+
)
|
| 596 |
+
|
| 597 |
+
# ========================================================
|
| 598 |
+
# INITIAL LOAD
|
| 599 |
+
# ========================================================
|
| 600 |
+
|
| 601 |
+
demo.load(
|
| 602 |
+
fn=calculate,
|
| 603 |
+
inputs=[
|
| 604 |
+
birds,
|
| 605 |
+
age,
|
| 606 |
+
bag_size,
|
| 607 |
+
bag_price,
|
| 608 |
+
actual_feed,
|
| 609 |
+
actual_weight,
|
| 610 |
+
],
|
| 611 |
+
outputs=[
|
| 612 |
+
summary,
|
| 613 |
+
benchmark,
|
| 614 |
+
comparison,
|
| 615 |
+
],
|
| 616 |
+
)
|
| 617 |
+
|
| 618 |
+
|
| 619 |
+
# ============================================================
|
| 620 |
+
# START APP
|
| 621 |
+
# ============================================================
|
| 622 |
+
|
| 623 |
+
if __name__ == "__main__":
|
| 624 |
+
demo.launch()
|