File size: 4,090 Bytes
a625342
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4368581
 
a625342
 
 
 
 
 
4368581
a625342
 
 
 
c356ab4
4368581
 
a625342
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113

import random
import streamlit as st
import pandas as pd
import numpy as np

movies = pd.read_csv('data.csv')


# name	description	link	year	imdb	kp	country	age	actors	genres	poster
# 0	Уэнсдэй	В американской хоррор-комедии показана детект...	https://www.lordfilm.bot/48211-ujensdjej-2022....	2022.0	8.1	8.0	США	0	Дженна Ортега, Гвендолин Кристи, Рики Линдхоум...	Сериалы, Фильмы про подростков	https://www.lordfilm.bot/uploads/posts/2022-12.

def display_movie_card(df, index):
    movie = df.iloc[index]
    col1, col2 = st.columns([1, 3])

    with col1:
        st.image(movie['Image'], use_column_width=True)
        button_id = f"button_{index}"
        full=st.button('Показать полное описание', key=button_id, help='Click to expand')

    with col2:

        st.markdown(f"<h2 style='text-align: left;'>{movie['Name']}</h2>", unsafe_allow_html=True)
        description = ' '.join(movie['Description'][:200].split(" ")[:-1]) + '...' if len(movie['Description']) > 200 else movie['Description']
        if len(movie['Description']) > 200:
            if full:
                st.write(movie['Description'])
            else:
                st.write(description, unsafe_allow_html=True)
        st.write(f"[{movie['Name']}]({movie['Link']})")
    st.write("----------------------")

def display_rating(rating):
    if np.isnan(rating): # Проверяем, является ли рейтинг NaN
        return "(╥﹏╥)" # Смайлик, обозначающий отсутствие рейтинга
    stars = int(rating / 2) # Переводим рейтинг из 0-10 в 0-5 и округляем до целого
    remainder = rating % 2 # Доля рейтинга, которая не переводится в целое количество звезд
    star_str = '🌕' * stars
    if remainder >= 0.5:
        star_str += '🌗' # Добавляем половину звезды в виде половины луны, если есть доля больше или равная 0.5
    return star_str



def display_movie_card(df, index):

    movie = df.iloc[index]
    col1, col2 = st.columns([1, 3])

    with col1:
        st.image(movie['poster'], use_column_width=True)

        st.write(f"Жанр: {movie['genres']}")
        
        st.write(f"Страна: {movie['country']}")
        st.write(f"рейтинг: {movie['age']}")
        

    with col2:
        year = str(int(movie['year'])) if not np.isnan(movie['year']) else ""
        st.markdown(f"<h2 style='text-align: left;'>{movie['name']} ({year})</h2>", unsafe_allow_html=True)
        

        description = ' '.join(movie['description'][:200].split(" ")[:-1]) + '...' if len(movie['description']) > 200 else movie['description']

        k='num'+ str(index)
        if k not in st.session_state:
            st.session_state[k] = False

        e = st.empty()
        b=False
        if movie['description'] !=description:
            b = st.button("раскрыть описание",key=index,)
        with e:
            if b:
                st.write(movie['description'])
            else:
                st.write(description)
        st.write(f"Актеры: {movie['actors']}")

        imdb,kp = st.columns([1,2])
        with imdb:
            st.write(f"IMDB: {display_rating(movie['imdb'])}")
        with kp:
            st.write(f"Кинопоиск: { display_rating(movie['kp'])}")
        
        st.write(f"[смотреть]({movie['link']})")
    st.write("----------------------")


reqs= st.session_state["reqs"] if "reqs" in st.session_state else {}

@st.cache_data
def getnums(df,size=10,text=''):
    if text in reqs:
        return reqs[text]
    else:
        reqs[text]=list(np.random.randint(len(df), size=size))
        st.session_state["reqs"] = reqs
        return reqs[text]


input_search = st.text_input('Search')
# 
for i in getnums(movies,text=input_search):
    display_movie_card(movies, i )