sentiment / app.py
dltmdgus's picture
Update app.py
9e01318 verified
import pandas as pd
import streamlit as st
# ์—‘์…€ ํŒŒ์ผ ๋กœ๋“œ
file_path = "book_introductions_with_predictions.xlsx"
df = pd.read_excel(file_path)
# ์ฑ… ์ œ๋ชฉ ๊ฒ€์ƒ‰
st.title("์ฑ… ์†Œ๊ฐœ๊ธ€ ๊ธฐ๋ฐ˜ ๊ฐ์ •๋ถ„์„")
# ์‚ฌ์šฉ์ž๊ฐ€ ๊ฒ€์ƒ‰ํ•  ์ฑ… ์ œ๋ชฉ ์ž…๋ ฅ
search_title = st.text_input("์ฑ… ์ œ๋ชฉ์„ ์ž…๋ ฅํ•˜์„ธ์š”:")
if search_title:
# ๊ฒ€์ƒ‰ํ•œ ์ฑ… ์ œ๋ชฉ์— ํ•ด๋‹นํ•˜๋Š” ์ตœ์ข… ๊ฐ์ • ๊ฐ€์ ธ์˜ค๊ธฐ
result = df[df['์ฑ… ์ œ๋ชฉ'] == search_title]
if not result.empty:
st.write(f"**{search_title}**์— ๋Œ€ํ•œ ์ตœ์ข… ๊ฐ์ •: **{result.iloc[0]['์ตœ์ข…๊ฐ์ •']}**")
else:
st.write("ํ•ด๋‹น ์ฑ… ์ œ๋ชฉ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
# ๊ฐ ๊ฐ์ •์— ๋Œ€ํ•ด ์ƒ์œ„ 10๊ฐœ์˜ ์ฑ… ์ œ๋ชฉ๊ณผ ํ™•๋ฅ ์„ ์ถ”์ถœ
st.title("๊ฐ ๊ฐ์ •๋ณ„ ํ™•๋ฅ  ์ƒ์œ„ 10๊ฐœ์˜ ์ฑ…")
# ํ™•๋ฅ  ๋ฐ์ดํ„ฐ๋ฅผ ๊ณต๋ฐฑ์œผ๋กœ ๋ถ„๋ฆฌํ•˜์—ฌ ๊ธ์ •, ๋ถ€์ •, ์ค‘๋ฆฝ ์—ด๋กœ ๋ถ„๋ฆฌ
df[['๊ธ์ •', '๋ถ€์ •', '์ค‘๋ฆฝ']] = df['ํ™•๋ฅ '].str.strip('[]').str.split(expand=True).astype(float)
def get_top_n_unique(df, column, n=10):
# ์ƒ์œ„ n๊ฐœ์˜ ๋„์„œ๋ฅผ ์ถ”์ถœํ•˜๋˜ ์ค‘๋ณต ์ œ๊ฑฐ
top_n = df.sort_values(by=column, ascending=False)
top_n_unique = []
seen_titles = set()
for index, row in top_n.iterrows():
if len(top_n_unique) >= n:
break
title = row['์ฑ… ์ œ๋ชฉ']
if title not in seen_titles:
top_n_unique.append(row)
seen_titles.add(title)
return pd.DataFrame(top_n_unique)[['์ฑ… ์ œ๋ชฉ', column]]
# ๊ธ์ • ํ™•๋ฅ  ์ƒ์œ„ 10๊ฐœ
top_positive = get_top_n_unique(df, '๊ธ์ •', n=10)
st.subheader("๊ธ์ • ํ™•๋ฅ  ์ƒ์œ„ 10๊ฐœ ์ฑ…")
st.table(top_positive)
# ๋ถ€์ • ํ™•๋ฅ  ์ƒ์œ„ 10๊ฐœ
top_negative = get_top_n_unique(df, '๋ถ€์ •', n=10)
st.subheader("๋ถ€์ • ํ™•๋ฅ  ์ƒ์œ„ 10๊ฐœ ์ฑ…")
st.table(top_negative)
# ์ค‘๋ฆฝ ํ™•๋ฅ  ์ƒ์œ„ 10๊ฐœ
top_neutral = get_top_n_unique(df, '์ค‘๋ฆฝ', n=10)
st.subheader("์ค‘๋ฆฝ ํ™•๋ฅ  ์ƒ์œ„ 10๊ฐœ ์ฑ…")
st.table(top_neutral)