Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,6 +30,20 @@ df = pd.read_excel(EXCEL_PATH)
|
|
| 30 |
strain_names = df['Microalgae_Strain'].unique().tolist()
|
| 31 |
single_strain_value = 0 # training used LabelEncoder -> 0
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# -----------------------------
|
| 34 |
# 3️⃣ Prediction function
|
| 35 |
# -----------------------------
|
|
@@ -105,6 +119,7 @@ with gr.Blocks(
|
|
| 105 |
gr.Markdown("### Crop & Microalgae Selection")
|
| 106 |
crop = gr.Dropdown(["Corn"], label="Select Crop", value="Corn")
|
| 107 |
strain = gr.Dropdown(strain_names, label="Microalgae Strain", value=strain_names[0])
|
|
|
|
| 108 |
gr.Markdown("### Soil Parameters")
|
| 109 |
soil_n = gr.Number(label="Soil N (ppm)")
|
| 110 |
soil_p = gr.Number(label="Soil P (ppm)")
|
|
@@ -142,6 +157,13 @@ with gr.Blocks(
|
|
| 142 |
</div>
|
| 143 |
"""
|
| 144 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
predict_btn.click(
|
| 146 |
fn=predict_dose,
|
| 147 |
inputs=[crop, strain, soil_n, soil_p, soil_k, soil_ec, soil_moisture,
|
|
|
|
| 30 |
strain_names = df['Microalgae_Strain'].unique().tolist()
|
| 31 |
single_strain_value = 0 # training used LabelEncoder -> 0
|
| 32 |
|
| 33 |
+
# ==================== New Integration ====================
|
| 34 |
+
# Create a list of row indices for dropdown
|
| 35 |
+
row_options = [str(i) for i in range(len(df))]
|
| 36 |
+
|
| 37 |
+
# Function to autofill input fields from selected row
|
| 38 |
+
def autofill_fields(row_index):
|
| 39 |
+
row = df.iloc[int(row_index)]
|
| 40 |
+
return (
|
| 41 |
+
row['Soil_N_ppm'], row['Soil_P_ppm'], row['Soil_K_ppm'],
|
| 42 |
+
row['Soil_EC_dS_m'], row['Soil_Moisture_%'], row['Chlorophyll_SPAD'],
|
| 43 |
+
row['Shoot_Length_cm'], row['Root_Length_cm'], row['Yield_g_per_pot'],
|
| 44 |
+
row['Relative_Yield_%'], row['Dose_g_per_pot'] if 'Dose_g_per_pot' in row else None
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
# -----------------------------
|
| 48 |
# 3️⃣ Prediction function
|
| 49 |
# -----------------------------
|
|
|
|
| 119 |
gr.Markdown("### Crop & Microalgae Selection")
|
| 120 |
crop = gr.Dropdown(["Corn"], label="Select Crop", value="Corn")
|
| 121 |
strain = gr.Dropdown(strain_names, label="Microalgae Strain", value=strain_names[0])
|
| 122 |
+
row_selector = gr.Dropdown(row_options, label="Select Row (from XLSX)", value="0")
|
| 123 |
gr.Markdown("### Soil Parameters")
|
| 124 |
soil_n = gr.Number(label="Soil N (ppm)")
|
| 125 |
soil_p = gr.Number(label="Soil P (ppm)")
|
|
|
|
| 157 |
</div>
|
| 158 |
"""
|
| 159 |
)
|
| 160 |
+
# ✅ Autofill fields when row selected
|
| 161 |
+
row_selector.change(fn=autofill_fields,
|
| 162 |
+
inputs=[row_selector],
|
| 163 |
+
outputs=[soil_n, soil_p, soil_k, soil_ec, soil_moisture,
|
| 164 |
+
chlorophyll, shoot_length, root_length, yield_g,
|
| 165 |
+
relative_yield, actual_dose]
|
| 166 |
+
)
|
| 167 |
predict_btn.click(
|
| 168 |
fn=predict_dose,
|
| 169 |
inputs=[crop, strain, soil_n, soil_p, soil_k, soil_ec, soil_moisture,
|