File size: 783 Bytes
cc146e8
 
6e00079
 
 
cc146e8
 
 
 
6e00079
 
 
cc146e8
 
 
 
6e00079
 
 
 
7aaf509
6e00079
 
 
 
7aaf509
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
import os
import hashlib
import pandas as pd
import streamlit as st

def create_hash(row):
    combined = str(row['name']) + str(row['short_story'])
    return hashlib.sha256(combined.encode()).hexdigest()

@st.cache_data
def load_data():
    """Загрузка и кэширование набора данных"""
    df = pd.read_json(os.getenv("DATASET_PATH"))
    df['hash'] = df.apply(create_hash, axis=1)

    return df

@st.cache_data
def get_unique_mood(_df):
    """Получение уникальных значений настроения"""
    return sorted(_df['mood'].unique().tolist())

@st.cache_data
def get_unique_tags(_df):
    """Получение уникальных тегов"""
    return sorted({tag for tags in _df['tags'] for tag in tags.split()})