|
import streamlit as st |
|
import pandas as pd |
|
from datetime import datetime |
|
from inference import Inference |
|
|
|
|
|
class QueryInputForm: |
|
def __init__(self): |
|
|
|
st.title("E-Commerce Recommendation Engine Demo") |
|
|
|
|
|
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', |
|
] |
|
|
|
|
|
self.default_query_text = "pizza" |
|
|
|
|
|
self.recommender_engine = Inference() |
|
|
|
def display_form(self): |
|
|
|
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) |
|
|
|
|
|
if st.button("Submit"): |
|
self.submit() |
|
|
|
def submit(self): |
|
|
|
raw_query = { |
|
'user_id': "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"), |
|
} |
|
|
|
|
|
self.recommender_engine.get_recommendations(raw_query) |
|
self.display_recommendations() |
|
|
|
def display_recommendations(self): |
|
|
|
st.write("Top recommendations:") |
|
st.dataframe(self.recommender_engine.recommendations, hide_index=True) |
|
|
|
|
|
if __name__ == "__main__": |
|
form = QueryInputForm() |
|
form.display_form() |