RedaAlami commited on
Commit
3ffc179
·
verified ·
1 Parent(s): 6dc0e14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -9
app.py CHANGED
@@ -5,17 +5,27 @@ from transformers import pipeline
5
  t5_recommender = pipeline(model="RedaAlami/t5_recommendation_sports_equipment_english")
6
 
7
  # Fixed list of candidates
8
- candidates = (
9
- "Soccer Jersey, Basketball Jersey, Football Jersey, Baseball Jersey, Tennis Shirt, "
10
- "Hockey Jersey, Soccer Ball, Basketball, Football, Baseball, Tennis Ball, Hocket Puck, "
11
- "Soccer Cleats, Basketball Shoes, Football Cleats, Baseball Cleats, Tennis Shoes, Hockey Helmet, "
12
- "Goalie Gloves, Basketball Arm Sleeve, Football Shoulder Pads, Baseball Cap, Tennis Racket, Hockey Skates, "
13
- "Soccer Goal Post, Basketball Hoop, Football Helmet, Baseball Bat, Hockey Stick, Soccer Cones, Basketball Shorts, "
14
- "Baseball Glove, Hockey Pads, Soccer Shorts"
15
- )
 
16
 
17
  def recommend(items_purchased):
18
- prompt = f"ITEMS PURCHASED: {{{items_purchased}}} - CANDIDATES FOR RECOMMENDATION: {{{candidates}}} - RECOMMENDATION: "
 
 
 
 
 
 
 
 
 
19
  model_output = t5_recommender(prompt)
20
  recommendation = model_output[0]['generated_text']
21
  return recommendation
 
5
  t5_recommender = pipeline(model="RedaAlami/t5_recommendation_sports_equipment_english")
6
 
7
  # Fixed list of candidates
8
+ all_candidates = [
9
+ "Soccer Jersey", "Basketball Jersey", "Football Jersey", "Baseball Jersey", "Tennis Shirt", "Hockey Jersey",
10
+ "Soccer Ball", "Basketball", "Football", "Baseball", "Tennis Ball", "Hocket Puck",
11
+ "Soccer Cleats", "Basketball Shoes", "Football Cleats", "Baseball Cleats", "Tennis Shoes", "Hockey Helmet",
12
+ "Goalie Gloves", "Basketball Arm Sleeve", "Football Shoulder Pads", "Baseball Cap", "Tennis Racket", "Hockey Skates",
13
+ "Soccer Goal Post", "Basketball Hoop", "Football Helmet", "Baseball Bat", "Hockey Stick",
14
+ "Soccer Cones", "Basketball Shorts", "Baseball Glove", "Hockey Pads",
15
+ "Soccer Shin Guards", "Soccer Shorts"
16
+ ]
17
 
18
  def recommend(items_purchased):
19
+ # Convert items purchased to a list and remove leading/trailing spaces
20
+ items_purchased_list = [item.strip() for item in items_purchased.split(',')]
21
+
22
+ # Filter out the purchased items from the candidates
23
+ candidates = [item for item in all_candidates if item not in items_purchased_list]
24
+
25
+ # Create the prompt
26
+ prompt = f"ITEMS PURCHASED: {{{', '.join(items_purchased_list)}}} - CANDIDATES FOR RECOMMENDATION: {{{', '.join(candidates)}}} - RECOMMENDATION: "
27
+
28
+ # Get the recommendation from the model
29
  model_output = t5_recommender(prompt)
30
  recommendation = model_output[0]['generated_text']
31
  return recommendation