Daniel commited on
Commit
74385db
1 Parent(s): 932ae75

cambios en la interfaz

Browse files
__pycache__/pinecone_client.cpython-310.pyc ADDED
Binary file (1.33 kB). View file
 
app.py CHANGED
@@ -1,19 +1,57 @@
1
  from sentence_transformers import SentenceTransformer
2
  from pinecone_client import PineconeClient
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  model = SentenceTransformer('all-MiniLM-L6-v2')
5
 
6
  def model_embedder(text):
7
- embedding = model.encode(text) # np.array converted to list
8
  return embedding.tolist()
9
 
10
-
11
-
12
- text_search = "Mens Casual T-Shirts"
13
  vector_search = model_embedder(text_search)
14
 
15
  index_name = "movies-embeddings"
16
- namespace = "ianews"
17
- p_client = PineconeClient(index_name, namespace)
18
- result = p_client.query_similarity(vector_search)
19
- print(result)
 
 
1
  from sentence_transformers import SentenceTransformer
2
  from pinecone_client import PineconeClient
3
+ import streamlit as st
4
+ import pandas as pd
5
+ from PIL import Image
6
+
7
+
8
+ im = Image.open('video.png')
9
+ st.set_page_config(page_title="Movie Recommender System App",page_icon = im)
10
+
11
+ import base64
12
+ def add_bg_from_local(image_file):
13
+ with open(image_file, "rb") as image_file:
14
+ encoded_string = base64.b64encode(image_file.read())
15
+ st.markdown(
16
+ f"""
17
+ <style>
18
+ .stApp {{
19
+ background-image: url(data:image/{"gif"};base64,{encoded_string.decode()});
20
+ background-size: cover
21
+ }}
22
+ </style>
23
+ """,
24
+ unsafe_allow_html=True
25
+ )
26
+ add_bg_from_local('wallpaper_home.jpg')
27
+
28
+ text_search = st.text_input('Provide a movie description',
29
+ placeholder='E.g. A thrilling adventure in space')
30
+
31
+ genre = st.selectbox('Select movie genre',
32
+ options = ['All', 'Action', 'Drama', 'Adventure', 'Sci-Fi', 'Animation', 'Crime',
33
+ 'Comedy', 'Thriller', 'Fantasy', 'Horror', 'History', 'Mystery',
34
+ 'Biography', 'War', 'Western', 'Sport', 'Family', 'Romance',
35
+ 'Music', 'Musical', 'Film-Noir', 'Game-Show', 'Adult',
36
+ 'Reality-TV']
37
+ )
38
+ genre = [] if genre is "All" else [genre]
39
+
40
+ ratting = st.slider('Movie Rating (IMDb)', 0.0, 10.0, 0.0, 0.1, format = "%f")
41
+
42
+ top_k = st.slider('Select Movie Limit', 0, 10, 3)
43
 
44
  model = SentenceTransformer('all-MiniLM-L6-v2')
45
 
46
  def model_embedder(text):
47
+ embedding = model.encode(text)
48
  return embedding.tolist()
49
 
 
 
 
50
  vector_search = model_embedder(text_search)
51
 
52
  index_name = "movies-embeddings"
53
+ p_client = PineconeClient(index_name)
54
+ results = p_client.query_similarity(vector_search, top_k=top_k, genre=genre, filter_rating=ratting)
55
+
56
+ df = pd.DataFrame([result['metadata'] for result in results])
57
+ df
pinecone_client.py CHANGED
@@ -1,26 +1,28 @@
1
  import pinecone
2
  import os
3
 
4
- API_KEY = os.getenv("PINECONE_API_KEY")
5
  pinecone.init(api_key=API_KEY,
6
- environment="asia-southeast1-gcp-free")
7
 
8
  class PineconeClient:
9
 
10
- def __init__(self, index_name:str, namespace:str):
11
  self.index_name = index_name
12
- self.namespace = namespace
13
  self.index = pinecone.Index(self.index_name)
14
 
15
  def upsert_vectors(self, vectors:list):
16
- return self.index.upsert(vectors=vectors, namespace=self.namespace)
17
 
18
- def query_similarity(self, query_vector:list, top_k=5):
19
- return self.index.query(
20
- namespace=self.namespace,
21
  top_k=top_k,
22
  include_values=False,
23
  include_metadata=True,
24
  vector=query_vector,
25
- filter={}
26
- )
 
 
 
 
 
1
  import pinecone
2
  import os
3
 
4
+ API_KEY = "a46ed9ad-4f13-448d-b8ea-28028777a373"
5
  pinecone.init(api_key=API_KEY,
6
+ environment="gcp-starter")
7
 
8
  class PineconeClient:
9
 
10
+ def __init__(self, index_name:str):
11
  self.index_name = index_name
 
12
  self.index = pinecone.Index(self.index_name)
13
 
14
  def upsert_vectors(self, vectors:list):
15
+ return self.index.upsert(vectors=vectors)
16
 
17
+ def query_similarity(self, query_vector:list, top_k=5, genre:list=[], filter_rating=0):
18
+ response = self.index.query(
 
19
  top_k=top_k,
20
  include_values=False,
21
  include_metadata=True,
22
  vector=query_vector,
23
+ filter={
24
+ "Generes": { "${}in".format('n' if not genre else ''): genre },
25
+ "Rating": { "$gte": filter_rating }
26
+ }
27
+ )
28
+ return response.to_dict()["matches"]
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  streamlit==1.28.2
2
- pinecone-client==2.2.4
 
 
1
  streamlit==1.28.2
2
+ pinecone-client==2.2.4
3
+ sentence-transformers
video.png ADDED
wallpaper_home.jpg ADDED