Update app.py
Browse files
app.py
CHANGED
|
@@ -45,7 +45,7 @@ tfidf_matrix = tfidf.fit_transform(products_df['description'].fillna(''))
|
|
| 45 |
# Compute the cosine similarity matrix
|
| 46 |
cosine_sim = linear_kernel(tfidf_matrix, tfidf_matrix)
|
| 47 |
|
| 48 |
-
# Function to get recommendations
|
| 49 |
def get_recommendations(product_name, cosine_sim=cosine_sim):
|
| 50 |
if product_name not in products_df['product_name'].values:
|
| 51 |
return pd.DataFrame(columns=['product_name', 'description']) # Return empty DataFrame if not found
|
|
@@ -56,6 +56,11 @@ def get_recommendations(product_name, cosine_sim=cosine_sim):
|
|
| 56 |
product_indices = [i[0] for i in sim_scores]
|
| 57 |
return products_df.iloc[product_indices][['product_name', 'description']]
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# Create the Gradio interface
|
| 60 |
product_names = products_df['product_name'].dropna().tolist() # List of product names
|
| 61 |
interface = gr.Interface(
|
|
|
|
| 45 |
# Compute the cosine similarity matrix
|
| 46 |
cosine_sim = linear_kernel(tfidf_matrix, tfidf_matrix)
|
| 47 |
|
| 48 |
+
# Function to get recommendations based on product name
|
| 49 |
def get_recommendations(product_name, cosine_sim=cosine_sim):
|
| 50 |
if product_name not in products_df['product_name'].values:
|
| 51 |
return pd.DataFrame(columns=['product_name', 'description']) # Return empty DataFrame if not found
|
|
|
|
| 56 |
product_indices = [i[0] for i in sim_scores]
|
| 57 |
return products_df.iloc[product_indices][['product_name', 'description']]
|
| 58 |
|
| 59 |
+
# Define the recommend_product function for Gradio
|
| 60 |
+
def recommend_product(selected_product):
|
| 61 |
+
recommendations = get_recommendations(selected_product)
|
| 62 |
+
return recommendations
|
| 63 |
+
|
| 64 |
# Create the Gradio interface
|
| 65 |
product_names = products_df['product_name'].dropna().tolist() # List of product names
|
| 66 |
interface = gr.Interface(
|