Spaces:
Runtime error
Runtime error
Commit ·
b48f9b8
1
Parent(s): 0a3ff2c
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123import osimport sysfrom random import randintimport timeimport uuidimport argparsesys.path.append(os.path.abspath("../supv"))from matumizi.util import *from mcclf import *def genVisitHistory(numUsers, convRate, label):for i in range(numUsers):userID = genID(12)userSess = []userSess.append(userID)conv = randint(0, 100)if (conv < convRate):#convertedif (label):if (randint(0,100) < 90):userSess.append("T")else:userSess.append("F")numSession = randint(2, 20)for j in range(numSession):sess = randint(0, 100)if (sess <= 15):elapsed = "H"elif (sess > 15 and sess <= 40):elapsed = "M"else:elapsed = "L"sess = randint(0, 100)if (sess <= 15):duration = "L"elif (sess > 15 and sess <= 40):duration = "M"else:duration = "H"sessSummary = elapsed + durationuserSess.append(sessSummary)else:#not convertedif (label):if (randint(0,100) < 90):userSess.append("F")else:userSess.append("T")numSession = randint(2, 12)for j in range(numSession):sess = randint(0, 100)if (sess <= 20):elapsed = "L"elif (sess > 20 and sess <= 45):elapsed = "M"else:elapsed = "H"sess = randint(0, 100)if (sess <= 20):duration = "H"elif (sess > 20 and sess <= 45):duration = "M"else:duration = "L"sessSummary = elapsed + durationuserSess.append(sessSummary)print(",".join(userSess))def main():st.set_page_config(page_title="Markov Chain Classifier", page_icon=":guardsman:", layout="wide")st.title("Markov Chain Classifier")# Add sidebarst.sidebar.title("Navigation")app_mode = st.sidebar.selectbox("Choose the app mode",["Instructions", "Generate User Visit History", "Train Model", "Predict Conversion"])if app_mode == "Instructions":st.write("Welcome to the Markov Chain Classifier app!")st.write("This app allows you to generate user visit history, train a Markov Chain Classifier model, and predict conversion.")st.write("To get started, use the sidebar to navigate to the desired functionality.")st.write("1. **Generate User Visit History**: Select the number of users and conversion rate, and click the 'Generate' button to generate user visit history.")st.write("2. **Train Model**: Upload an ML config file using the file uploader, and click the 'Train' button to train the Markov Chain Classifier model.")st.write("3. **Predict Conversion**: Upload an ML config file using the file uploader, and click the 'Predict' button to make predictions with the trained model.")elif app_mode == "Generate User Visit History":st.subheader("Generate User Visit History")num_users = st.number_input("Number of users", min_value=1, max_value=10000, value=100, step=1)conv_rate = st.slider("Conversion rate", min_value=0, max_value=100, value=10, step=1)add_label = st.checkbox("Add label", value=False)if st.button("Generate"):genVisitHistory(num_users, conv_rate, add_label)elif app_mode == "Train Model":st.subheader("Train Model")mlf_path = st.file_uploader("Upload ML config file")if st.button("Train"):if mlf_path is not None:model = MarkovChainClassifier(mlf_path)model.train()elif app_mode == "Predict Conversion":st.subheader("Predict Conversion")mlf_path = st.file_uploader("Upload ML config file")if st.button("Predict"):if mlf_path is not None:model = MarkovChainClassifier(mlf_path)model.predict()if __name__ == "__main__":main()
app.py+123