VipDest's picture
Upload 4 files
dd665d0 verified
import streamlit as st
import pandas as pd
import joblib
from sklearn.linear_model import LinearRegression
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import RandomForestRegressor
# Load the trained models (make sure these pickle files are uploaded in the same directory as your app.py in Hugging Face Space)
lr = joblib.load('linear_regression_model.pkl')
dt = joblib.load('decision_tree_model.pkl')
rf = joblib.load('random_forest_model.pkl')
# Streamlit UI
st.title("Indian Food Cook Time Prediction")
st.write("Enter the features to predict the cook time of Indian food.")
# Input fields
diet = st.selectbox("Diet Type", options=["vegetarian", "non vegetarian"])
prep_time = st.number_input("Preparation Time (minutes)", min_value=0, step=1)
ingredients = st.number_input("Number of Ingredients", min_value=1, step=1)
# Convert diet to numeric (0 for vegetarian, 1 for non-vegetarian)
diet = 0 if diet == "vegetarian" else 1
# Combine inputs into a DataFrame for prediction
input_data = pd.DataFrame({
'diet': [diet],
'prep_time': [prep_time],
'num_ingredients': [ingredients]
})
# Model selection
model_choice = st.selectbox("Select a Model", ["Linear Regression", "Decision Tree", "Random Forest"])
if st.button("Predict Cook Time"):
# Make prediction based on model choice
if model_choice == "Linear Regression":
prediction = lr.predict(input_data)[0]
elif model_choice == "Decision Tree":
prediction = dt.predict(input_data)[0]
elif model_choice == "Random Forest":
prediction = rf.predict(input_data)[0]
# Display the predicted cook time
st.write(f"Predicted Cook Time: {round(prediction, 2)} minutes")