Skip to content

Commit

Permalink
alter code
Browse files Browse the repository at this point in the history
  • Loading branch information
giaphong28 committed Dec 10, 2023
1 parent 369a754 commit fe79e74
Show file tree
Hide file tree
Showing 4 changed files with 3,581 additions and 5 deletions.
39 changes: 34 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@
from streamlit_elements import elements, mui, html, sync
from streamlit_star_rating import st_star_rating
import pandas as pd
import pymongo

st.set_page_config(page_title="Movie Web", layout="wide")
st.header("Sản phẩm demo Web Application")
st.markdown("***")
poster_data = pd.read_csv("movie_poster.csv", names=["itemID", "url"])
# @st.cache()
# Hàm liên kết với mongodb
def get_collection(connection_str):
myclient = pymongo.MongoClient(connection_str)
mydb = myclient["result"]
mycol = mydb["06-12-2023"]
return mycol
# Hàm lấy hình ảnh - bổ sung thêm title các thứ
def fetchposter(movie_id):
url = str(poster_data[poster_data["itemID"] == movie_id]["url"].values[0])
return url
# Nhập userID
userID = st.number_input("Nhập vào id người dùng: ", min_value=1, max_value=6040, step=1)
def fetch_img_url(id):
connection_str = "mongodb://longnguyenuit:ZkhrACfJflUhurRi1xUBFVLXMxNQrn2czSp5yHvomR4pvzmRPJX4niIdQT0FxdJCRVUtTx0eUkv4ACDbiTmXsQ%3D%3D@longnguyenuit.mongo.cosmos.azure.com:10255/?ssl=true&retrywrites=false&replicaSet=globaldb&maxIdleTimeMS=120000&appName=@longnguyenuit@"
res_collection = get_collection(connection_str)
# Duyệt qua từng dòng trên collection dựa trên userID, duyệt qua các movieID trong list 10 movieID
data = res_collection.find({"userID": id})
img_urls = []
for row in data:
for movieID in row["itemIDs"]:
img_urls.append(fetchposter(movieID))
return img_urls


movies = pickle.load(open("movie_list.pkl", 'rb'))
similarity = np.load("similarity.npy")
Expand All @@ -31,10 +61,9 @@ def fetch_poster(movie_id):
return full_path

# st.header("Recent hot movies")
# imageCarouselComponent = components.declare_component("image-carousel-component", path="frontend/public")


imageCarouselComponent = components.declare_component("image-carousel-component", path="frontend/public")

image_urls = fetch_img_url(userID)
# imageUrls = [
# fetch_poster(1632),
# fetch_poster(299536),
Expand All @@ -53,9 +82,9 @@ def fetch_poster(movie_id):
# ]


# imageCarouselComponent(imageUrls=imageUrls, height=200)

imageCarouselComponent(imageUrls=image_urls, height=200)

st.markdown('***')

def recommend(movie):
index=movies[movies['title']== movie].index[0]
Expand Down
30 changes: 30 additions & 0 deletions app2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import streamlit as st
import requests
import pandas as pd
import pymongo
st.set_page_config(page_title="Movie Web", layout="wide")
st.header("Sản phẩm demo Web Application")
st.markdown("***")
poster_data = pd.read_csv("movie_poster.csv", names=["itemID", "url"])
# @st.cache()
# Hàm liên kết với mongodb
def get_collection(connection_str):
myclient = pymongo.MongoClient(connection_str)
mydb = myclient["result"]
mycol = mydb["06-12-2023"]
return mycol
# Hàm lấy hình ảnh - bổ sung thêm title các thứ
def fetch_poster(movie_id):
url = str(poster_data[poster_data["itemID"] == movie_id]["url"].values[0])
st.image(url, width = 100)
# Nhập userID
userID = st.number_input("Nhập vào id người dùng: ", min_value=1, max_value=6040, step=1)
connection_str = "mongodb://longnguyenuit:ZkhrACfJflUhurRi1xUBFVLXMxNQrn2czSp5yHvomR4pvzmRPJX4niIdQT0FxdJCRVUtTx0eUkv4ACDbiTmXsQ%3D%3D@longnguyenuit.mongo.cosmos.azure.com:10255/?ssl=true&retrywrites=false&replicaSet=globaldb&maxIdleTimeMS=120000&appName=@longnguyenuit@"
res_collection = get_collection(connection_str)
# Duyệt qua từng dòng trên collection dựa trên userID, duyệt qua các movieID trong list 10 movieID
data = res_collection.find({"userID": userID})
img_urls = []
for row in data:
for movieID in row["itemIDs"]:
img_urls.append(fetch_poster(movieID))

Loading

0 comments on commit fe79e74

Please sign in to comment.