productizationlabs
commited on
Commit
·
a29b06a
1
Parent(s):
e264ccb
Upload app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,15 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
for T in S:I.add(F.lemmatize(T))
|
17 |
-
U=I.intersection(G);H.append(len(U))
|
18 |
-
A[J]=H;A=A.sort_values(by=J,ascending=K);A.drop_duplicates(subset=L,keep='first',inplace=D);A.sort_values(M,ascending=K,inplace=D);A.reset_index(inplace=D);return A[[L,M,'Hotel_Address']].head(10)
|
19 |
-
inputs=[gr.inputs.Textbox(label='Location'),gr.inputs.Textbox(label='Purpose of Travel')]
|
20 |
-
outputs=gr.outputs.Dataframe(label='Hotel Recommendations',type='pandas')
|
21 |
-
gr.Interface(fn=Input_your_destination_and_description,inputs=inputs,outputs=outputs,theme=gr.themes.Default(primary_hue='slate')).launch()
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
3 |
+
import gradio as gr
|
4 |
+
def recommend_items(customer_id_1,customer_id_2):
|
5 |
+
H='Error';G=customer_id_2;F=customer_id_1;D='StockCode';C='CustomerID'
|
6 |
+
try:I=pd.read_excel('UBCF_Online_Retail.xlsx')
|
7 |
+
except FileNotFoundError:return'Error: Excel file not found.'
|
8 |
+
E=I.dropna(subset=[C]);A=E.pivot_table(index=C,columns=D,values='Quantity',aggfunc='sum');A=A.applymap(lambda x:1 if x>0 else 0);B=pd.DataFrame(cosine_similarity(A));B.columns=A.index;B[C]=A.index;B=B.set_index(C)
|
9 |
+
try:J=set(A.loc[F].iloc[A.loc[F].to_numpy().nonzero()].index)
|
10 |
+
except KeyError:return pd.DataFrame({H:['Customer ID 1 is invalid. Please enter a valid Customer ID']})
|
11 |
+
try:K=set(A.loc[G].iloc[A.loc[G].to_numpy().nonzero()].index)
|
12 |
+
except KeyError:return pd.DataFrame({H:['Customer ID 2 is invalid. Please enter a valid Customer ID']})
|
13 |
+
L=J-K;return E.loc[E[D].isin(L),[D,'Description']].drop_duplicates().set_index(D)
|
14 |
+
iface=gr.Interface(fn=recommend_items,inputs=[gr.inputs.Number(label='Customer ID 1'),gr.inputs.Number(label='Customer ID 2')],outputs=gr.outputs.Dataframe(label='Recommended Items for Customer 2',type='pandas'),theme=gr.themes.Default(primary_hue='slate'),allow_flagging=False)
|
15 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|