Spaces:
Configuration error
Configuration error
Delete app.py
Browse files
app.py
DELETED
@@ -1,27 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import pandas as pd
|
3 |
-
from sentence_transformers import SentenceTransformer
|
4 |
-
from sklearn.metrics.pairwise import cosine_similarity
|
5 |
-
|
6 |
-
# Load your trained SentenceTransformer model
|
7 |
-
|
8 |
-
import joblib
|
9 |
-
model = joblib.load("recommender_model.pkl")
|
10 |
-
|
11 |
-
# Load the posts
|
12 |
-
posts = pd.read_csv("posts_cleaned.csv")
|
13 |
-
|
14 |
-
# Precompute embeddings for all posts
|
15 |
-
post_texts = posts["post_text"].astype(str).tolist()
|
16 |
-
post_embeddings = model.encode(post_texts, convert_to_tensor=False)
|
17 |
-
|
18 |
-
# Recommendation function
|
19 |
-
def recommend(user_input):
|
20 |
-
user_embedding = model.encode([user_input], convert_to_tensor=False)
|
21 |
-
similarities = cosine_similarity(user_embedding, post_embeddings)[0]
|
22 |
-
top_indices = similarities.argsort()[-5:][::-1]
|
23 |
-
recommended = posts.iloc[top_indices]["post_text"].tolist()
|
24 |
-
return "\n\n".join(recommended)
|
25 |
-
|
26 |
-
# Launch Gradio app
|
27 |
-
gr.Interface(fn=recommend, inputs="text", outputs="text", title="AI Post Recommender").launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|