Spaces:
Runtime error
Runtime error
Commit
·
1d09c8e
1
Parent(s):
f3f1ffd
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import sys
|
3 |
from random import randint
|
4 |
import time
|
5 |
import uuid
|
6 |
import argparse
|
|
|
7 |
import streamlit as st
|
|
|
|
|
8 |
sys.path.append(os.path.abspath("../supv"))
|
9 |
from matumizi.util import *
|
10 |
from mcclf import *
|
@@ -77,31 +91,72 @@ def genVisitHistory(numUsers, convRate, label):
|
|
77 |
userSess.append(sessSummary)
|
78 |
|
79 |
print(",".join(userSess))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
def trainModel(mlfpath):
|
81 |
model = MarkovChainClassifier(mlfpath)
|
82 |
model.train()
|
|
|
|
|
83 |
|
84 |
-
def predictModel(mlfpath):
|
85 |
model = MarkovChainClassifier(mlfpath)
|
86 |
-
model.predict()
|
87 |
-
|
88 |
-
def main():
|
89 |
-
st.title("Markov Chain Classifier")
|
90 |
-
|
91 |
-
# Add input fields for command line arguments
|
92 |
-
op = st.selectbox("Operation", ["gen", "train", "pred"])
|
93 |
-
numUsers = st.slider("Number of Users", 1, 1000, 100)
|
94 |
-
convRate = st.slider("Conversion Rate", 1, 100, 10)
|
95 |
-
label = st.checkbox("Add Label")
|
96 |
-
mlfpath = st.text_input("ML Config File Path", value="false")
|
97 |
-
|
98 |
-
# Call functions based on selected operation
|
99 |
-
if op == "gen":
|
100 |
-
st.button("Generate Visit History", on_click=lambda: genVisitHistory(numUsers, convRate, label))
|
101 |
-
elif op == "train":
|
102 |
-
st.button("Train Model", on_click=lambda: trainModel(mlfpath))
|
103 |
-
elif op == "pred":
|
104 |
-
st.button("Predict Model", on_click=lambda: predictModel(mlfpath))
|
105 |
|
106 |
if __name__ == "__main__":
|
107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import os
|
2 |
+
# import sys
|
3 |
+
# from random import randint
|
4 |
+
# import time
|
5 |
+
# import uuid
|
6 |
+
# import argparse
|
7 |
+
# import streamlit as st
|
8 |
+
# sys.path.append(os.path.abspath("../supv"))
|
9 |
+
# from matumizi.util import *
|
10 |
+
# from mcclf import *
|
11 |
+
|
12 |
import os
|
13 |
import sys
|
14 |
from random import randint
|
15 |
import time
|
16 |
import uuid
|
17 |
import argparse
|
18 |
+
import pandas as pd
|
19 |
import streamlit as st
|
20 |
+
|
21 |
+
# Add the directory containing the required modules to sys.path
|
22 |
sys.path.append(os.path.abspath("../supv"))
|
23 |
from matumizi.util import *
|
24 |
from mcclf import *
|
|
|
91 |
userSess.append(sessSummary)
|
92 |
|
93 |
print(",".join(userSess))
|
94 |
+
|
95 |
+
# def trainModel(mlfpath):
|
96 |
+
# model = MarkovChainClassifier(mlfpath)
|
97 |
+
# model.train()
|
98 |
+
|
99 |
+
# def predictModel(mlfpath):
|
100 |
+
# model = MarkovChainClassifier(mlfpath)
|
101 |
+
# model.predict()
|
102 |
+
|
103 |
def trainModel(mlfpath):
|
104 |
model = MarkovChainClassifier(mlfpath)
|
105 |
model.train()
|
106 |
+
return model
|
107 |
+
|
108 |
|
109 |
+
def predictModel(mlfpath, userID):
|
110 |
model = MarkovChainClassifier(mlfpath)
|
111 |
+
res = model.predict(userID)
|
112 |
+
return res
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
if __name__ == "__main__":
|
115 |
+
st.title("Conversion Prediction App")
|
116 |
+
st.write("Welcome to the Conversion Prediction App. This app uses a Markov chain based classifier to predict whether a customer will convert or not based on their visit history.")
|
117 |
+
|
118 |
+
op = st.sidebar.selectbox("Select Operation", ["Generate Visit History", "Train Model", "Predict"])
|
119 |
+
|
120 |
+
if op == "Generate Visit History":
|
121 |
+
st.write("Enter the parameters to generate the visit history:")
|
122 |
+
numUsers = st.number_input("Number of users", min_value=1, max_value=1000, value=100, step=1)
|
123 |
+
convRate = st.number_input("Conversion Rate (in percentage)", min_value=0, max_value=100, value=10, step=1)
|
124 |
+
label = st.checkbox("Add Labels")
|
125 |
+
st.write("Click the button below to generate the visit history")
|
126 |
+
if st.button("Generate"):
|
127 |
+
genVisitHistory(numUsers, convRate, label)
|
128 |
+
|
129 |
+
elif op == "Train Model":
|
130 |
+
st.write("Train the model using the following parameters:")
|
131 |
+
mlfpath = st.text_input("MLF Path")
|
132 |
+
if st.button("Train"):
|
133 |
+
trainModel(mlfpath)
|
134 |
+
|
135 |
+
elif op == "Predict":
|
136 |
+
st.write("Predict using the trained model:")
|
137 |
+
mlfpath = st.text_input("MLF Path")
|
138 |
+
userID = st.text_input("User ID")
|
139 |
+
if st.button("Predict"):
|
140 |
+
result = predictModel(mlfpath, userID)
|
141 |
+
st.write("Prediction Result: ", result)
|
142 |
+
|
143 |
+
# def main():
|
144 |
+
# st.title("Markov Chain Classifier")
|
145 |
+
|
146 |
+
# # Add input fields for command line arguments
|
147 |
+
# op = st.selectbox("Operation", ["gen", "train", "pred"])
|
148 |
+
# numUsers = st.slider("Number of Users", 1, 1000, 100)
|
149 |
+
# convRate = st.slider("Conversion Rate", 1, 100, 10)
|
150 |
+
# label = st.checkbox("Add Label")
|
151 |
+
# mlfpath = st.text_input("ML Config File Path", value="false")
|
152 |
+
|
153 |
+
# # Call functions based on selected operation
|
154 |
+
# if op == "gen":
|
155 |
+
# st.button("Generate Visit History", on_click=lambda: genVisitHistory(numUsers, convRate, label))
|
156 |
+
# elif op == "train":
|
157 |
+
# st.button("Train Model", on_click=lambda: trainModel(mlfpath))
|
158 |
+
# elif op == "pred":
|
159 |
+
# st.button("Predict Model", on_click=lambda: predictModel(mlfpath))
|
160 |
+
|
161 |
+
# if __name__ == "__main__":
|
162 |
+
# main()
|