Priyanka-Kumavat-At-TE commited on
Commit
51972b1
1 Parent(s): 2fc2c1f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -0
app.py ADDED
@@ -0,0 +1,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
+ def genVisitHistory(numUsers, convRate, label):
13
+ for i in range(numUsers):
14
+ userID = genID(12)
15
+ userSess = []
16
+ userSess.append(userID)
17
+
18
+ conv = randint(0, 100)
19
+ if (conv < convRate):
20
+ #converted
21
+ if (label):
22
+ if (randint(0,100) < 90):
23
+ userSess.append("T")
24
+ else:
25
+ userSess.append("F")
26
+
27
+
28
+ numSession = randint(2, 20)
29
+ for j in range(numSession):
30
+ sess = randint(0, 100)
31
+ if (sess <= 15):
32
+ elapsed = "H"
33
+ elif (sess > 15 and sess <= 40):
34
+ elapsed = "M"
35
+ else:
36
+ elapsed = "L"
37
+
38
+ sess = randint(0, 100)
39
+ if (sess <= 15):
40
+ duration = "L"
41
+ elif (sess > 15 and sess <= 40):
42
+ duration = "M"
43
+ else:
44
+ duration = "H"
45
+
46
+ sessSummary = elapsed + duration
47
+ userSess.append(sessSummary)
48
+
49
+
50
+ else:
51
+ #not converted
52
+ if (label):
53
+ if (randint(0,100) < 90):
54
+ userSess.append("F")
55
+ else:
56
+ userSess.append("T")
57
+
58
+ numSession = randint(2, 12)
59
+ for j in range(numSession):
60
+ sess = randint(0, 100)
61
+ if (sess <= 20):
62
+ elapsed = "L"
63
+ elif (sess > 20 and sess <= 45):
64
+ elapsed = "M"
65
+ else:
66
+ elapsed = "H"
67
+
68
+ sess = randint(0, 100)
69
+ if (sess <= 20):
70
+ duration = "H"
71
+ elif (sess > 20 and sess <= 45):
72
+ duration = "M"
73
+ else:
74
+ duration = "L"
75
+
76
+ sessSummary = elapsed + duration
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
+ main()