Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from gradio import Interface, Textbox, Dropdown
|
3 |
+
|
4 |
+
# Load the prediction data for each algorithm and season
|
5 |
+
als_spring_data = pd.read_csv('als_pred_spring.csv')
|
6 |
+
als_fall_data = pd.read_csv('als_pred_fall.csv')
|
7 |
+
als_winter_data = pd.read_csv('als_pred_winter.csv')
|
8 |
+
als_summer_data = pd.read_csv('als_pred_summer.csv')
|
9 |
+
|
10 |
+
nmf_spring_data = pd.read_csv('nmf_pred_spring.csv')
|
11 |
+
nmf_fall_data = pd.read_csv('nmf_pred_fall.csv')
|
12 |
+
nmf_winter_data = pd.read_csv('nmf_pred_winter.csv')
|
13 |
+
nmf_summer_data = pd.read_csv('nmf_pred_summer.csv')
|
14 |
+
|
15 |
+
# Function to get recommendations based on customer ID, season, and algorithm
|
16 |
+
def get_recommendations(customer_id, season, algorithm):
|
17 |
+
if algorithm == 'ALS':
|
18 |
+
if season == 'Spring':
|
19 |
+
data = als_spring_data
|
20 |
+
elif season == 'Fall':
|
21 |
+
data = als_fall_data
|
22 |
+
elif season == 'Winter':
|
23 |
+
data = als_winter_data
|
24 |
+
elif season == 'Summer':
|
25 |
+
data = als_summer_data
|
26 |
+
else:
|
27 |
+
return 'Invalid season'
|
28 |
+
elif algorithm == 'NMF':
|
29 |
+
if season == 'Spring':
|
30 |
+
data = nmf_spring_data
|
31 |
+
elif season == 'Fall':
|
32 |
+
data = nmf_fall_data
|
33 |
+
elif season == 'Winter':
|
34 |
+
data = nmf_winter_data
|
35 |
+
elif season == 'Summer':
|
36 |
+
data = nmf_summer_data
|
37 |
+
else:
|
38 |
+
return 'Invalid season'
|
39 |
+
else:
|
40 |
+
return 'Invalid algorithm'
|
41 |
+
|
42 |
+
if customer_id not in data['customer_id'].values:
|
43 |
+
return 'Recommendation not found'
|
44 |
+
|
45 |
+
recommendations = data[data['customer_id'] == customer_id]['article_id'].iloc[0]
|
46 |
+
recommendations = recommendations.strip("[]").split(", ")
|
47 |
+
recommendations = [f"Item {i}: {item}" for i, item in enumerate(recommendations, 1)]
|
48 |
+
|
49 |
+
return '\n'.join(recommendations)
|
50 |
+
|
51 |
+
# Create the input and output interfaces
|
52 |
+
customer_id_input = Textbox(label="Customer ID")
|
53 |
+
season_input = Dropdown(choices=['Spring', 'Fall', 'Winter', 'Summer'], label="Season")
|
54 |
+
algorithm_input = Dropdown(choices=['ALS', 'NMF'], label="Algorithm")
|
55 |
+
output = Textbox(label="Recommendations")
|
56 |
+
|
57 |
+
# Create the interface with the title
|
58 |
+
title = "Collaborative Filtering for Recommendation System on Fashion Products"
|
59 |
+
interface = Interface(fn=get_recommendations, inputs=[customer_id_input, season_input, algorithm_input], outputs=output, title=title)
|
60 |
+
|
61 |
+
# Run the interface
|
62 |
+
interface.launch()
|