/
HelbyVal
/
PE_StreamlitLab
Обзор
Документация
Войти
/
HelbyVal
/
PE_StreamlitLab
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
main.py
63 строки
2 KB
Tikhomirov
refactor: flake8 issues
26 май 2026, 22:29
26 май 2026, 22:29
b79c06d
Код
Авторство
О чём код?
import streamlit as st import pandas as pd import altair as alt from brains import TranslateAndEmotion as TaEModel PAGE_TITLE = "Программная инженерия: лабораторная работа №3" AUTHORS = "Выполнили Тихомиров Алексей и Рудин Валентин" APP_DESCRIPTION = ( "Приложение позволяет определить эмоциональную окраску " "отзывов о фильме" ) UPLOAD_LABEL = "Загрузите файл с разделителями" st.title(PAGE_TITLE) st.header(AUTHORS) st.subheader(APP_DESCRIPTION) colors = { 'love': '#FF6B6B', 'admiration': '#FFA500', 'approval': '#32CD32', 'neutral': '#87CEEB', 'disappointment': '#6A5ACD', 'disapproval': '#9370DB', 'anger': '#DC143C', 'disgust': '#8B4513' } @st.cache_resource def load_model(): model = TaEModel() return model model = load_model() uploaded_file = st.file_uploader(UPLOAD_LABEL, ".txt") if uploaded_file: text = uploaded_file.getvalue().decode("utf-8") comments = model.get_sentences_from_text(text) translated_commets = model.translate_all_sentences(comments) model_outputs = model.classified_emotions_from_data(translated_commets) result, label_counts = model.count_emotions(model_outputs) bar_colors = [ colors.get(category, '#888888') for category in label_counts.keys() ] result["Цвет"] = bar_colors df = pd.DataFrame(result) bars = ( alt.Chart(df) .mark_bar() .encode( x="Эмоции", y="Количество", color="Цвет" ) ) st.altair_chart(bars, theme=None, use_container_width=True)