guyinbal commited on
Commit
8f46540
verified
1 Parent(s): 1bdc897

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +27 -6
  2. app1.py +41 -0
  3. requirements.txt +5 -0
README.md CHANGED
@@ -1,13 +1,34 @@
1
  ---
2
- title: Yannayguy1
3
- emoji: 馃寲
4
- colorFrom: green
5
  colorTo: indigo
6
  sdk: gradio
7
- sdk_version: 5.37.0
8
  app_file: app.py
9
  pinned: false
10
- license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: Movie Recommender
3
+ emoji: 馃幀
4
+ colorFrom: blue
5
  colorTo: indigo
6
  sdk: gradio
7
+ sdk_version: "4.16.0"
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
+ # Movie Recommender
13
+
14
+ A simple web app to recommend movies based on your text description, using embeddings and cosine similarity.
15
+
16
+ ## How it works
17
+
18
+ - The app uses [SentenceTransformers](https://www.sbert.net/) to encode your text and the movie descriptions into embeddings.
19
+ - Then it calculates the cosine similarity between your input and all movies in the dataset.
20
+ - It shows the top 5 most similar movies.
21
+
22
+ ## How to run
23
+
24
+ 1. Install dependencies:
25
+ ```bash
26
+ pip install -r requirements.txt
27
+ ```
28
+
29
+ 2. Run the app:
30
+ ```bash
31
+ python app.py
32
+ ```
33
+
34
+ Or just run it here on Spaces!
app1.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sklearn.metrics.pairwise import cosine_similarity
2
+ import numpy as np
3
+ import gradio as gr
4
+ import pandas as pd
5
+ from sentence_transformers import SentenceTransformer
6
+
7
+ # 讟注谉 讗转 讛诪讜讚诇
8
+ model = SentenceTransformer("all-MiniLM-L6-v2")
9
+
10
+ # 讟注谉 讗转 讛讚讗讟讛住讟 诪讛诇讬谞拽
11
+ url = "https://huggingface.co/datasets/Pablinho/movies-dataset/resolve/main/9000plus.csv"
12
+ print("Loading dataset...")
13
+ dataset = pd.read_csv(url)
14
+
15
+ # 讜讚讗 砖讛注诪讜讚讜转 拽讬讬诪讜转
16
+ assert "Title" in dataset.columns
17
+ assert "Overview" in dataset.columns
18
+
19
+ print("Encoding movie descriptions...")
20
+ MAX_MOVIES = 1000
21
+ dataset = dataset.head(MAX_MOVIES)
22
+ dataset["embeddings"] = dataset["Overview"].apply(lambda x: model.encode(x).tolist())
23
+ print("Done encoding!")
24
+
25
+ def recommend_similar_movies(input_text, top_n=5):
26
+ input_embedding = model.encode([input_text])
27
+ similarities = cosine_similarity(input_embedding, np.vstack(dataset['embeddings'].to_numpy()))[0]
28
+ top_indices = similarities.argsort()[::-1][:top_n]
29
+ results = dataset.iloc[top_indices][['Title', 'Overview']]
30
+ return "\n\n".join(f"馃幀 **{row['Title']}**\n{row['Overview']}" for _, row in results.iterrows())
31
+
32
+ demo = gr.Interface(
33
+ fn=recommend_similar_movies,
34
+ inputs=gr.Textbox(lines=2, placeholder="Describe a movie..."),
35
+ outputs="text",
36
+ title="Movie Recommender",
37
+ description="Get movie recommendations based on your description. Powered by sentence-transformers and cosine similarity."
38
+ )
39
+
40
+ if __name__ == "__main__":
41
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ numpy
2
+ pandas
3
+ scikit-learn
4
+ gradio
5
+ sentence-transformers