File size: 2,219 Bytes
fbf704f
 
 
 
 
 
6dc0e14
3ffc179
 
608c6fe
3ffc179
 
 
 
 
 
6dc0e14
 
3ffc179
 
 
 
 
 
 
 
 
 
fbf704f
 
 
 
 
 
608c6fe
 
 
 
fbf704f
 
1c5f0be
fbf704f
 
 
 
6dc0e14
fbf704f
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gradio as gr
from transformers import pipeline

# Load fine-tuned model from Hugging Face Hub
t5_recommender = pipeline(model="RedaAlami/t5_recommendation_sports_equipment_english")

# Fixed list of candidates
all_candidates = [
    "Soccer Jersey", "Basketball Jersey", "Football Jersey", "Baseball Jersey", "Tennis Shirt", "Hockey Jersey",
    "Soccer Ball", "Basketball", "Football", "Baseball", "Tennis Ball", "Hockey Puck",
    "Soccer Cleats", "Basketball Shoes", "Football Cleats", "Baseball Cleats", "Tennis Shoes", "Hockey Helmet",
    "Goalie Gloves", "Basketball Arm Sleeve", "Football Shoulder Pads", "Baseball Cap", "Tennis Racket", "Hockey Skates",
    "Soccer Goal Post", "Basketball Hoop", "Football Helmet", "Baseball Bat", "Hockey Stick",
    "Soccer Cones", "Basketball Shorts", "Baseball Glove", "Hockey Pads",
    "Soccer Shin Guards", "Soccer Shorts"
]

def recommend(items_purchased):
    # Convert items purchased to a list and remove leading/trailing spaces
    items_purchased_list = [item.strip() for item in items_purchased.split(',')]
    
    # Filter out the purchased items from the candidates
    candidates = [item for item in all_candidates if item not in items_purchased_list]
    
    # Create the prompt
    prompt = f"ITEMS PURCHASED: {{{', '.join(items_purchased_list)}}} - CANDIDATES FOR RECOMMENDATION: {{{', '.join(candidates)}}} - RECOMMENDATION: "
    
    # Get the recommendation from the model
    model_output = t5_recommender(prompt)
    recommendation = model_output[0]['generated_text']
    return recommendation

with gr.Blocks() as demo:
    gr.Markdown("# Sports Equipment Recommender")
    
    gr.Markdown("## All Possible Candidates")
    gr.Markdown(", ".join(all_candidates))
    
    with gr.Row():
        with gr.Column():
            items_input = gr.Textbox(label="Items Purchased", placeholder="Enter a list of items purchased from the possible candidates above, separated by commas.")
        with gr.Column():
            recommendation_output = gr.Textbox(label="Recommendation")

    recommend_button = gr.Button("Get Recommendation")
    recommend_button.click(fn=recommend, inputs=items_input, outputs=recommendation_output)

demo.launch()