test_4 / main.py
swaraj
grapes_model
099ad54
import streamlit as st
import importlib
# Map model names to their module info (lazy loading)
MODELS = {
"1_Banana_Harvest_Forecasting": ("model_interface.a_2_banana_harvest_forecasting", "banana_harvest_forecasting"),
"2_Sales_forecasting_1": ("model_interface.a_1_sales_forecasting_1", "sales_forecasting"),
"3_Customer_scoring": ("model_interface.a_3_customer_scoring_1", "run_sales_score_app"),
"4_Inventory_management": ("model_interface.a_4_inventory_managemnt", "inventory_management"),
"5_Customer_wise_sales_forecasting": ("model_interface.a_5_customerwise_sales_forecasting", "customer_wise_sales_forecast"),
"6_Farmer_scoring_1": ("model_interface.a_6_farmer_scoring_1", "farmer_score_silal"),
"7_Stress_prediction": ("model_interface.a_7_stress_prediction", "stress_prediction"),
"8_Expense_Forecasting": ("model_interface.a_8_expense_forecasting", "expense_forecasting"),
"9_Harvest_Forecasting_v1": ("model_interface.a_9_harvest_forecasting", "harvest_forecasting"),
"10_Sales_Forecasting_2": ("model_interface.a_10_sales_forecasting_2", "sales_forecasting_mfarm"),
"11_Harvest_Forecasting(FarmERP)": ("model_interface.a_11_harvest_forecast_FarmERP", "harvest_forecast_farmerp"),
"12_Farmer_Scoring(FarmERP)": ("model_interface.a_12_farmer_scoring_FarmERP", "farmer_scoring_farmerp"),
"13_Expense_Forecasting(FarmERP)": ("model_interface.a_13_expense_forecasting_FarmERP", "expense_forecasting_farmerp"),
"14_Sales_Forecasting(FarmERP)": ("model_interface.a_14_sales_forecasting_FarmERP", "sales_forecasting_vegpro_farmerp"),
"15_Activity_date_planner": ("model_interface.a_15_activity_date_planner", "activity_date_planner"),
"16_Harvest_Forecasting_V1.1_FarmGyan": ("model_interface.a_16_harvest_forecast_V1_1_FARMGYAN", "harvest_forecast_farmgyan"),
"17_Grapes_count": ("model_interface.a_17_grapes_count", "grapes_count"),
}
# Lazy import function
def load_and_run_model(project):
"""Dynamically import and run the selected model"""
if project not in MODELS:
st.error("Model not found!")
return
module_name, func_name = MODELS[project]
try:
module = importlib.import_module(module_name)
func = getattr(module, func_name)
func()
except ImportError as e:
st.error(f"Error loading module: {e}")
except AttributeError:
st.error(f"Function {func_name} not found in {module_name}")
# App Layout
st.set_page_config(page_title="🌾 Agri ML Hub", layout="wide")
st.sidebar.title("🔘 Select DS Model")
project = st.sidebar.selectbox("Choose a Model:", list(MODELS.keys()))
# Run the selected model
if project:
load_and_run_model(project)