Awlly's picture
Upload 5 files
07299cf verified
raw
history blame
2.42 kB
import streamlit as st
from PIL import Image
import requests
from io import BytesIO
from sentence_transformers import SentenceTransformer
import faiss
import pandas as pd
# import sys
# import subprocess
# import streamlit as st
# # Debug: Print Python executable and installed packages
# st.write(f"Python executable: {sys.executable}")
# installed_packages = subprocess.run([sys.executable, "-m", "pip", "list"], capture_output=True, text=True).stdout
# st.text(installed_packages)
model = SentenceTransformer('cointegrated/rubert-tiny2')
index = faiss.read_index('faiss_index.index')
data = pd.read_csv('datasetf.csv')
def vectorize(descriptions):
embeddings = model.encode(descriptions)
return embeddings
def find_similar_shows(user_description, index, k=5):
query_vector = vectorize([user_description])
_, indices = index.search(query_vector, k)
return data.iloc[indices.flatten()]
def load_image(url):
try:
response = requests.get(url)
img = Image.open(BytesIO(response.content))
except Exception:
# If an error occurs, load the dummy image
img = Image.open("cat.jpg") # Update the path to your dummy image
return img
st.title('TV Show Recommender')
# User input for the show description
user_description = st.text_area("Describe the TV show you're looking for:")
# Slider for the number of recommendations
num_recommendations = st.slider('Number of recommendations:', min_value=1, max_value=10, value=5)
# Button to get recommendations
if st.button('Recommend') and user_description:
try:
recommended_shows = find_similar_shows(user_description, index, num_recommendations)
for idx in recommended_shows.index:
with st.container():
link = data.loc[idx, 'url']
poster_url = data.loc[idx, 'poster']
title = data.loc[idx, 'title']
description = data.loc[idx, 'description']
img = load_image(poster_url) # Use the load_image function
col1, col2 = st.columns([1, 2])
with col1:
st.image(img, caption=title, use_column_width='always')
with col2:
st.write(description)
st.markdown(f"[More Info]({link})", unsafe_allow_html=True)
except Exception as e:
st.error(f"An error occurred: {e}")