Spaces:
Runtime error
Runtime error
Commit
·
0a3ff2c
1
Parent(s):
60f8dcb
Update app.py
Browse files
app.py
CHANGED
@@ -1,219 +0,0 @@
|
|
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 *
|
25 |
-
# # from markov_chain_classifier import MarkovChainClassifier
|
26 |
-
|
27 |
-
# def genVisitHistory(numUsers, convRate, label):
|
28 |
-
# for i in range(numUsers):
|
29 |
-
# userID = genID(12)
|
30 |
-
# userSess = []
|
31 |
-
# userSess.append(userID)
|
32 |
-
|
33 |
-
# conv = randint(0, 100)
|
34 |
-
# if (conv < convRate):
|
35 |
-
# #converted
|
36 |
-
# if (label):
|
37 |
-
# if (randint(0,100) < 90):
|
38 |
-
# userSess.append("T")
|
39 |
-
# else:
|
40 |
-
# userSess.append("F")
|
41 |
-
|
42 |
-
|
43 |
-
# numSession = randint(2, 20)
|
44 |
-
# for j in range(numSession):
|
45 |
-
# sess = randint(0, 100)
|
46 |
-
# if (sess <= 15):
|
47 |
-
# elapsed = "H"
|
48 |
-
# elif (sess > 15 and sess <= 40):
|
49 |
-
# elapsed = "M"
|
50 |
-
# else:
|
51 |
-
# elapsed = "L"
|
52 |
-
|
53 |
-
# sess = randint(0, 100)
|
54 |
-
# if (sess <= 15):
|
55 |
-
# duration = "L"
|
56 |
-
# elif (sess > 15 and sess <= 40):
|
57 |
-
# duration = "M"
|
58 |
-
# else:
|
59 |
-
# duration = "H"
|
60 |
-
|
61 |
-
# sessSummary = elapsed + duration
|
62 |
-
# userSess.append(sessSummary)
|
63 |
-
|
64 |
-
|
65 |
-
# else:
|
66 |
-
# #not converted
|
67 |
-
# if (label):
|
68 |
-
# if (randint(0,100) < 90):
|
69 |
-
# userSess.append("F")
|
70 |
-
# else:
|
71 |
-
# userSess.append("T")
|
72 |
-
|
73 |
-
# numSession = randint(2, 12)
|
74 |
-
# for j in range(numSession):
|
75 |
-
# sess = randint(0, 100)
|
76 |
-
# if (sess <= 20):
|
77 |
-
# elapsed = "L"
|
78 |
-
# elif (sess > 20 and sess <= 45):
|
79 |
-
# elapsed = "M"
|
80 |
-
# else:
|
81 |
-
# elapsed = "H"
|
82 |
-
|
83 |
-
# sess = randint(0, 100)
|
84 |
-
# if (sess <= 20):
|
85 |
-
# duration = "H"
|
86 |
-
# elif (sess > 20 and sess <= 45):
|
87 |
-
# duration = "M"
|
88 |
-
# else:
|
89 |
-
# duration = "L"
|
90 |
-
|
91 |
-
# sessSummary = elapsed + duration
|
92 |
-
# userSess.append(sessSummary)
|
93 |
-
|
94 |
-
# print(",".join(userSess))
|
95 |
-
|
96 |
-
# # def trainModel(mlfpath):
|
97 |
-
# # model = MarkovChainClassifier(mlfpath)
|
98 |
-
# # model.train()
|
99 |
-
|
100 |
-
# # def predictModel(mlfpath):
|
101 |
-
# # model = MarkovChainClassifier(mlfpath)
|
102 |
-
# # model.predict()
|
103 |
-
|
104 |
-
# def trainModel(mlfpath):
|
105 |
-
# model = MarkovChainClassifier(mlfpath)
|
106 |
-
# model.train()
|
107 |
-
# return model
|
108 |
-
|
109 |
-
|
110 |
-
# def predictModel(mlfpath, userID):
|
111 |
-
# model = MarkovChainClassifier(mlfpath)
|
112 |
-
# res = model.predict(userID)
|
113 |
-
# return res
|
114 |
-
|
115 |
-
|
116 |
-
# # Define MLF path and user ID
|
117 |
-
# mlfpath = "mcclf_cc.properties"
|
118 |
-
# userID = "56C96HWLR9ZO"
|
119 |
-
|
120 |
-
# # Load the Markov chain classifier model
|
121 |
-
# model = MarkovChainClassifier('cc.mod')
|
122 |
-
|
123 |
-
# # Perform prediction
|
124 |
-
# result = model.predict(userID)
|
125 |
-
|
126 |
-
# # Display the prediction result
|
127 |
-
# st.title("Conversion Prediction App")
|
128 |
-
# 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.")
|
129 |
-
# st.write("Prediction Result for User ID: ", userID)
|
130 |
-
# st.write("Conversion: ", result)
|
131 |
-
|
132 |
-
import os
|
133 |
-
import streamlit as st
|
134 |
-
from mcclf import MarkovChainClassifier
|
135 |
-
|
136 |
-
def app():
|
137 |
-
st.title("Hugging Face Prediction App")
|
138 |
-
st.subheader("Enter User ID:")
|
139 |
-
userID = st.text_input("User ID")
|
140 |
-
|
141 |
-
# Add any other input fields or widgets for user interaction
|
142 |
-
# Add a "Predict" button
|
143 |
-
if st.button("Predict"):
|
144 |
-
# Load the Markov chain classifier model from the model folder
|
145 |
-
model_path = os.path.join("model", "cc.mod")
|
146 |
-
model = MarkovChainClassifier(model_path)
|
147 |
-
|
148 |
-
# Call the predict method on the loaded model
|
149 |
-
prediction = model.predict(userID)
|
150 |
-
|
151 |
-
# Display the prediction result
|
152 |
-
st.write("Prediction: ", prediction)
|
153 |
-
|
154 |
-
if __name__ == "__main__":
|
155 |
-
app()
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
# # if op == "Predict":
|
164 |
-
# # st.write("Enter the parameters to make a prediction:")
|
165 |
-
# # userID = st.text_input("User ID")
|
166 |
-
# # st.write("Click the button below to make a prediction")
|
167 |
-
# # if st.button("Predict"):
|
168 |
-
# # prediction = predictModel(mlfpath, userID)
|
169 |
-
# # st.write("Prediction:", prediction)
|
170 |
-
|
171 |
-
# # if __name__ == "__main__":
|
172 |
-
# # st.title("Conversion Prediction App")
|
173 |
-
# # 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.")
|
174 |
-
|
175 |
-
# # op = st.sidebar.selectbox("Select Operation", ["Generate Visit History", "Train Model", "Predict"])
|
176 |
-
|
177 |
-
# # if op == "Generate Visit History":
|
178 |
-
# # st.write("Enter the parameters to generate the visit history:")
|
179 |
-
# # numUsers = st.number_input("Number of users", min_value=1, max_value=1000, value=100, step=1)
|
180 |
-
# # convRate = st.number_input("Conversion Rate (in percentage)", min_value=0, max_value=100, value=10, step=1)
|
181 |
-
# # label = st.checkbox("Add Labels")
|
182 |
-
# # st.write("Click the button below to generate the visit history")
|
183 |
-
# # if st.button("Generate"):
|
184 |
-
# # genVisitHistory(numUsers, convRate, label)
|
185 |
-
|
186 |
-
# # elif op == "Train Model":
|
187 |
-
# # st.write("Train the model using the following parameters:")
|
188 |
-
# # mlfpath = st.text_input("MLF Path")
|
189 |
-
# # if st.button("Train"):
|
190 |
-
# # trainModel(mlfpath)
|
191 |
-
|
192 |
-
# # elif op == "Predict":
|
193 |
-
# # st.write("Predict using the trained model:")
|
194 |
-
# # mlfpath = st.text_input("MLF Path")
|
195 |
-
# # userID = st.text_input("User ID")
|
196 |
-
# # if st.button("Predict"):
|
197 |
-
# # result = predictModel(mlfpath, userID)
|
198 |
-
# # st.write("Prediction Result: ", result)
|
199 |
-
|
200 |
-
# # def main():
|
201 |
-
# # st.title("Markov Chain Classifier")
|
202 |
-
|
203 |
-
# # # Add input fields for command line arguments
|
204 |
-
# # op = st.selectbox("Operation", ["gen", "train", "pred"])
|
205 |
-
# # numUsers = st.slider("Number of Users", 1, 1000, 100)
|
206 |
-
# # convRate = st.slider("Conversion Rate", 1, 100, 10)
|
207 |
-
# # label = st.checkbox("Add Label")
|
208 |
-
# # mlfpath = st.text_input("ML Config File Path", value="false")
|
209 |
-
|
210 |
-
# # # Call functions based on selected operation
|
211 |
-
# # if op == "gen":
|
212 |
-
# # st.button("Generate Visit History", on_click=lambda: genVisitHistory(numUsers, convRate, label))
|
213 |
-
# # elif op == "train":
|
214 |
-
# # st.button("Train Model", on_click=lambda: trainModel(mlfpath))
|
215 |
-
# # elif op == "pred":
|
216 |
-
# # st.button("Predict Model", on_click=lambda: predictModel(mlfpath))
|
217 |
-
|
218 |
-
# # if __name__ == "__main__":
|
219 |
-
# # main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|