Awlly commited on
Commit
1af5c4b
·
verified ·
1 Parent(s): c093a73

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -71
app.py DELETED
@@ -1,71 +0,0 @@
1
- import streamlit as st
2
- from PIL import Image
3
- import requests
4
- from io import BytesIO
5
- from sentence_transformers import SentenceTransformer
6
- import faiss
7
- import pandas as pd
8
-
9
- # import sys
10
- # import subprocess
11
- # import streamlit as st
12
-
13
- # # Debug: Print Python executable and installed packages
14
- # st.write(f"Python executable: {sys.executable}")
15
- # installed_packages = subprocess.run([sys.executable, "-m", "pip", "list"], capture_output=True, text=True).stdout
16
- # st.text(installed_packages)
17
-
18
- model = SentenceTransformer('cointegrated/rubert-tiny2')
19
- index = faiss.read_index('faiss_index.index')
20
- data = pd.read_csv('datasetf.csv')
21
-
22
- def vectorize(descriptions):
23
- embeddings = model.encode(descriptions)
24
- return embeddings
25
-
26
-
27
- def find_similar_shows(user_description, index, k=5):
28
- query_vector = vectorize([user_description])
29
- _, indices = index.search(query_vector, k)
30
- return data.iloc[indices.flatten()]
31
-
32
- def load_image(url):
33
- try:
34
- response = requests.get(url)
35
- img = Image.open(BytesIO(response.content))
36
- except Exception:
37
- # If an error occurs, load the dummy image
38
- img = Image.open("cat.jpg") # Update the path to your dummy image
39
- return img
40
-
41
- st.title('TV Show Recommender')
42
-
43
- # User input for the show description
44
- user_description = st.text_area("Describe the TV show you're looking for:")
45
-
46
- # Slider for the number of recommendations
47
- num_recommendations = st.slider('Number of recommendations:', min_value=1, max_value=10, value=5)
48
-
49
- # Button to get recommendations
50
- if st.button('Recommend') and user_description:
51
- try:
52
- recommended_shows = find_similar_shows(user_description, index, num_recommendations)
53
-
54
- for idx in recommended_shows.index:
55
- with st.container():
56
- link = data.loc[idx, 'url']
57
- poster_url = data.loc[idx, 'poster']
58
- title = data.loc[idx, 'title']
59
- description = data.loc[idx, 'description']
60
-
61
- img = load_image(poster_url) # Use the load_image function
62
-
63
- col1, col2 = st.columns([1, 2])
64
- with col1:
65
- st.image(img, caption=title, use_column_width='always')
66
- with col2:
67
- st.write(description)
68
- st.markdown(f"[More Info]({link})", unsafe_allow_html=True)
69
-
70
- except Exception as e:
71
- st.error(f"An error occurred: {e}")