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