sagravela's picture
last model
11b1e95
raw
history blame
2.31 kB
import streamlit as st
import pandas as pd
from datetime import datetime
from inference import Inference
class QueryInputForm:
def __init__(self):
# Title of the Streamlit form
st.title("E-Commerce Recommendation Engine Demo")
# Predefined options for channel and device type
self.channel_options = [
'Paid Social', 'Paid Search - Brand', 'Organic', 'Email - Transactional',
'Affiliate', 'Paid Search', 'Direct', 'Referral', 'Email - Marketing',
'Paid Search - Brand Reactivation', 'SMS - Marketing', 'Email - Trigger',
'Referral - Whitelabel', 'Referral - Merchant', 'Social', 'SMS - Trigger',
]
self.device_type_options = [
'Mobile', 'Desktop', 'Phablet', 'Tablet', 'TV',
'Portable Media Player', 'Wearable',
]
# Default values for the form
self.default_query_text = "pizza"
# Initialize the recommender engine
self.recommender_engine = Inference()
def display_form(self):
# Input fields for user ID, channel, device type, and query text
self.channel = st.selectbox("Channel", options=self.channel_options)
self.device_type = st.selectbox("Device Type", options=self.device_type_options)
self.query_text = st.text_input("Query Text", value=self.default_query_text)
# Submit button
if st.button("Submit"):
self.submit()
def submit(self):
# Pass the query information to the recommender engine
raw_query = {
'user_id': "new_user", # any user will be considered as a new user
'channel': self.channel,
'device_type': self.device_type,
'query_text': self.query_text,
'time': datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"), # querytime
}
# Get recommendations
self.recommender_engine.get_recommendations(raw_query)
self.display_recommendations()
def display_recommendations(self):
# Output the recommendations from the inference engine
st.write("Top recommendations:")
st.dataframe(self.recommender_engine.recommendations, hide_index=True)
if __name__ == "__main__":
form = QueryInputForm()
form.display_form()