Spaces:
Configuration error
Configuration error
Delete app.py
Browse files
app.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import pickle
|
| 3 |
-
import pandas as pd
|
| 4 |
-
from sklearn.metrics.pairwise import cosine_similarity
|
| 5 |
-
|
| 6 |
-
# Load model and dataset
|
| 7 |
-
with open("recommender_model.pkl", "rb") as f:
|
| 8 |
-
model = pickle.load(f)
|
| 9 |
-
|
| 10 |
-
posts_df = pd.read_csv("posts_cleaned.csv") # your full dataset with post content
|
| 11 |
-
post_embeddings = model["embeddings"] # precomputed post embeddings
|
| 12 |
-
vectorizer = model["vectorizer"] # for transforming user input
|
| 13 |
-
|
| 14 |
-
# Predict function
|
| 15 |
-
def recommend_from_input(user_text):
|
| 16 |
-
user_vec = vectorizer.encode([user_text])
|
| 17 |
-
sims = cosine_similarity(user_vec, post_embeddings)[0]
|
| 18 |
-
top_idxs = sims.argsort()[-5:][::-1]
|
| 19 |
-
top_posts = posts_df.iloc[top_idxs]["post_text"].tolist()
|
| 20 |
-
return "\n\n".join(top_posts)
|
| 21 |
-
|
| 22 |
-
# Gradio UI
|
| 23 |
-
interface = gr.Interface(
|
| 24 |
-
fn=recommend_from_input,
|
| 25 |
-
inputs="text",
|
| 26 |
-
outputs="text",
|
| 27 |
-
title="AI Content Recommender",
|
| 28 |
-
description="Enter a sample interest or post to receive recommendations"
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|