Spaces:
Runtime error
Runtime error
Commit
·
0ba77fc
1
Parent(s):
3e5d933
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,6 +9,7 @@ from matumizi.util import *
|
|
| 9 |
from mcclf import *
|
| 10 |
import streamlit as st
|
| 11 |
|
|
|
|
| 12 |
def genVisitHistory(numUsers, convRate, label):
|
| 13 |
for i in range(numUsers):
|
| 14 |
userID = genID(12)
|
|
@@ -80,20 +81,26 @@ def genVisitHistory(numUsers, convRate, label):
|
|
| 80 |
|
| 81 |
|
| 82 |
def main():
|
| 83 |
-
st.set_page_config(page_title="
|
| 84 |
st.title("Markov Chain Classifier")
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
# Add sidebar
|
| 87 |
st.sidebar.title("Navigation")
|
| 88 |
-
app_mode = st.sidebar.selectbox("Choose the
|
| 89 |
-
["Instructions", "Generate User Visit History", "
|
| 90 |
|
| 91 |
if app_mode == "Instructions":
|
| 92 |
st.write("Welcome to the Markov Chain Classifier app!")
|
|
|
|
| 93 |
st.write("This app allows you to generate user visit history, train a Markov Chain Classifier model, and predict conversion.")
|
| 94 |
st.write("To get started, use the sidebar to navigate to the desired functionality.")
|
| 95 |
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.")
|
| 96 |
-
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.")
|
| 97 |
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.")
|
| 98 |
|
| 99 |
elif app_mode == "Generate User Visit History":
|
|
@@ -104,20 +111,31 @@ def main():
|
|
| 104 |
if st.button("Generate"):
|
| 105 |
genVisitHistory(num_users, conv_rate, add_label)
|
| 106 |
|
| 107 |
-
elif app_mode == "Train Model":
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
|
| 115 |
elif app_mode == "Predict Conversion":
|
| 116 |
st.subheader("Predict Conversion")
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
model.predict()
|
| 122 |
|
| 123 |
if __name__ == "__main__":
|
|
|
|
| 9 |
from mcclf import *
|
| 10 |
import streamlit as st
|
| 11 |
|
| 12 |
+
|
| 13 |
def genVisitHistory(numUsers, convRate, label):
|
| 14 |
for i in range(numUsers):
|
| 15 |
userID = genID(12)
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
def main():
|
| 84 |
+
st.set_page_config(page_title="Customer Conversion Prediction", page_icon=":guardsman:", layout="wide")
|
| 85 |
st.title("Markov Chain Classifier")
|
| 86 |
|
| 87 |
+
# # Add sidebar
|
| 88 |
+
# st.sidebar.title("Navigation")
|
| 89 |
+
# app_mode = st.sidebar.selectbox("Choose the app mode",
|
| 90 |
+
# ["Instructions", "Generate User Visit History", "Train Model", "Predict Conversion"])
|
| 91 |
+
|
| 92 |
# Add sidebar
|
| 93 |
st.sidebar.title("Navigation")
|
| 94 |
+
app_mode = st.sidebar.selectbox("Choose the App Mode",
|
| 95 |
+
["Instructions", "Generate User Visit History", "Predict Conversion"])
|
| 96 |
|
| 97 |
if app_mode == "Instructions":
|
| 98 |
st.write("Welcome to the Markov Chain Classifier app!")
|
| 99 |
+
# st.write("This app allows you to generate user visit history, train a Markov Chain Classifier model, and predict conversion.")
|
| 100 |
st.write("This app allows you to generate user visit history, train a Markov Chain Classifier model, and predict conversion.")
|
| 101 |
st.write("To get started, use the sidebar to navigate to the desired functionality.")
|
| 102 |
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.")
|
| 103 |
+
# 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.")
|
| 104 |
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.")
|
| 105 |
|
| 106 |
elif app_mode == "Generate User Visit History":
|
|
|
|
| 111 |
if st.button("Generate"):
|
| 112 |
genVisitHistory(num_users, conv_rate, add_label)
|
| 113 |
|
| 114 |
+
# elif app_mode == "Train Model":
|
| 115 |
+
# st.subheader("Train Model")
|
| 116 |
+
# mlf_path = st.file_uploader("Upload ML config file")
|
| 117 |
+
# if st.button("Train"):
|
| 118 |
+
# if mlf_path is not None:
|
| 119 |
+
# model = MarkovChainClassifier(mlf_path)
|
| 120 |
+
# model.train()
|
| 121 |
|
| 122 |
elif app_mode == "Predict Conversion":
|
| 123 |
st.subheader("Predict Conversion")
|
| 124 |
+
# Upload ML config file using Streamlit's file_uploader function
|
| 125 |
+
mlf_file = st.file_uploader("Upload ML config file", type=["properties"])
|
| 126 |
+
|
| 127 |
+
# Check if ML config file was uploaded
|
| 128 |
+
if mlf_file is not None:
|
| 129 |
+
# Save the uploaded file to a local file
|
| 130 |
+
with open("mcclf_cc.properties", "wb") as f:
|
| 131 |
+
f.write(mlf_file.read())
|
| 132 |
+
|
| 133 |
+
# Create an instance of MarkovChainClassifier with the uploaded ML config file
|
| 134 |
+
model = MarkovChainClassifier("mcclf_cc.properties")
|
| 135 |
+
|
| 136 |
+
# Check if the "Predict" button was clicked
|
| 137 |
+
if st.button("Predict"):
|
| 138 |
+
# Call the predict method of the MarkovChainClassifier instance
|
| 139 |
model.predict()
|
| 140 |
|
| 141 |
if __name__ == "__main__":
|