update
Browse files- app.py +1 -1
- as.py +20 -0
- inference.py +2 -2
app.py
CHANGED
@@ -7,7 +7,7 @@ from inference import Inference
|
|
7 |
class QueryInputForm:
|
8 |
def __init__(self):
|
9 |
# Title of the Streamlit form
|
10 |
-
st.title("
|
11 |
|
12 |
# Predefined options for channel and device type
|
13 |
self.channel_options = [
|
|
|
7 |
class QueryInputForm:
|
8 |
def __init__(self):
|
9 |
# Title of the Streamlit form
|
10 |
+
st.title("E-Commerce Recommendation Engine Demo")
|
11 |
|
12 |
# Predefined options for channel and device type
|
13 |
self.channel_options = [
|
as.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import os
|
3 |
+
from datetime import datetime
|
4 |
+
from inference import Inference
|
5 |
+
|
6 |
+
products_path = os.path.join("products")
|
7 |
+
inference = Inference()
|
8 |
+
|
9 |
+
raw_query = {
|
10 |
+
'user_id': "new_user", # any user will be considered as a new user
|
11 |
+
'channel': 'Organic',
|
12 |
+
'device_type': 'Desktop',
|
13 |
+
'query_text': 'pizza',
|
14 |
+
'time': datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"), # querytime
|
15 |
+
}
|
16 |
+
|
17 |
+
inference.get_recommendations(raw_query)
|
18 |
+
print(inference.recommendations)
|
19 |
+
|
20 |
+
|
inference.py
CHANGED
@@ -4,7 +4,6 @@ import os
|
|
4 |
|
5 |
class Inference():
|
6 |
def __init__(self):
|
7 |
-
|
8 |
index_path = os.path.join("recommendation_model", "index")
|
9 |
model_path = os.path.join("recommendation_model", "model")
|
10 |
self.index = tf.keras.models.load_model(index_path)
|
@@ -34,6 +33,7 @@ class Inference():
|
|
34 |
filtered_recs = self.products.filter(self.filter_by_id)
|
35 |
# Add query input
|
36 |
query_added_recs = filtered_recs.map(lambda x: {**self.query_input, **x})
|
|
|
37 |
# Get score
|
38 |
score_added_recs = query_added_recs.batch(8).map(self.get_score).unbatch()
|
39 |
|
@@ -43,7 +43,7 @@ class Inference():
|
|
43 |
# Order by score
|
44 |
ordered_recs = self.order_by_score(recs)
|
45 |
|
46 |
-
# Decode values
|
47 |
self.recommendations = list(map(self.decode_values, ordered_recs))
|
48 |
|
49 |
def filter_by_id(self, item):
|
|
|
4 |
|
5 |
class Inference():
|
6 |
def __init__(self):
|
|
|
7 |
index_path = os.path.join("recommendation_model", "index")
|
8 |
model_path = os.path.join("recommendation_model", "model")
|
9 |
self.index = tf.keras.models.load_model(index_path)
|
|
|
33 |
filtered_recs = self.products.filter(self.filter_by_id)
|
34 |
# Add query input
|
35 |
query_added_recs = filtered_recs.map(lambda x: {**self.query_input, **x})
|
36 |
+
|
37 |
# Get score
|
38 |
score_added_recs = query_added_recs.batch(8).map(self.get_score).unbatch()
|
39 |
|
|
|
43 |
# Order by score
|
44 |
ordered_recs = self.order_by_score(recs)
|
45 |
|
46 |
+
# Decode values and return
|
47 |
self.recommendations = list(map(self.decode_values, ordered_recs))
|
48 |
|
49 |
def filter_by_id(self, item):
|