dltmdgus commited on
Commit
a2dcc43
Β·
verified Β·
1 Parent(s): cf0ade7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -43
app.py CHANGED
@@ -1,54 +1,42 @@
1
- import streamlit as st
2
  import pandas as pd
 
3
 
4
- # 파일 경둜 μ„€μ •
5
- FILE_PATH = "book_topics_output_modified.xlsx"
6
-
7
- # μ—‘μ…€ νŒŒμΌμ„ μ½μ–΄μ˜€λŠ” ν•¨μˆ˜
8
- def load_data(file_path):
9
- return pd.read_excel(file_path)
10
-
11
- # Streamlit μ• ν”Œλ¦¬μΌ€μ΄μ…˜
12
- def main():
13
- st.title("ν‚€μ›Œλ“œ 기반 λ„μ„œ μΆ”μ²œ")
14
-
15
- # 데이터 λ‘œλ“œ
16
- data = load_data(FILE_PATH)
17
 
18
- # μ΅œμ’…ν† ν”½ 열이 μžˆλŠ”μ§€ 확인
19
- if 'μ΅œμ’…ν† ν”½' not in data.columns:
20
- st.error("μ΅œμ’…ν† ν”½ 열이 데이터에 μ—†μŠ΅λ‹ˆλ‹€.")
21
- return
22
 
23
- # μ΅œμ’…ν† ν”½ μΉ΄ν…Œκ³ λ¦¬ 선택
24
- topic_category = st.selectbox(
25
- "μ΅œμ’…ν† ν”½μ„ μ„ νƒν•˜μ„Έμš”:",
26
- sorted(data['μ΅œμ’…ν† ν”½'].unique())
27
- )
28
 
29
- # μ„ νƒλœ 토픽에 ν•΄λ‹Ήν•˜λŠ” λ„μ„œ λͺ©λ‘ 필터링
30
- filtered_data = data[data['μ΅œμ’…ν† ν”½'] == topic_category]
 
31
 
32
- # λ„μ„œλͺ… 열이 μžˆλŠ”μ§€ 확인
33
- if 'λ„μ„œλͺ…' not in data.columns:
34
- st.error("λ„μ„œλͺ… 열이 데이터에 μ—†μŠ΅λ‹ˆλ‹€.")
35
- return
36
 
37
- # 숫자 열이 μžˆλŠ”μ§€ 확인
38
- numeric_cols = [col for col in filtered_data.columns if pd.api.types.is_numeric_dtype(filtered_data[col])]
39
- if not numeric_cols:
40
- st.error("숫자 열이 μ—†μŠ΅λ‹ˆλ‹€.")
41
- return
42
 
43
- # κ°€μž₯ 높은 값을 κ°€μ§„ 숫자 μ—΄ 선택
44
- number_col = numeric_cols[0] # 첫 번째 숫자 μ—΄ μ‚¬μš©
45
 
46
- # μƒμœ„ 10개 λ„μ„œλͺ… μΆ”μΆœ
47
- top_books = filtered_data.nlargest(20, number_col)[['λ„μ„œλͺ…', number_col]]
 
 
48
 
49
- # λ„μ„œλͺ…λ§Œ 좜λ ₯
50
- st.write(f"μ΅œμ’…ν† ν”½ '{topic_category}'에 ν•΄λ‹Ήν•˜λŠ” μƒμœ„ 20개 λ„μ„œλͺ…:")
51
- st.dataframe(top_books[['λ„μ„œλͺ…']]) # λ„μ„œλͺ…λ§Œ ν‘œμ‹œ
 
52
 
53
- if __name__ == "__main__":
54
- main()
 
 
 
 
1
  import pandas as pd
2
+ import streamlit as st
3
 
4
+ # μ—‘μ…€ 파일 λ‘œλ“œ
5
+ file_path = "book_introductions_with_predictions.xlsx"
6
+ df = pd.read_excel(file_path)
 
 
 
 
 
 
 
 
 
 
7
 
8
+ # μ±… 제λͺ© 검색
9
+ st.title(" μ±… μ†Œκ°œκΈ€ 기반 감정뢄석")
 
 
10
 
11
+ # μ‚¬μš©μžκ°€ 검색할 μ±… 제λͺ© μž…λ ₯
12
+ search_title = st.text_input("μ±… 제λͺ©μ„ μž…λ ₯ν•˜μ„Έμš”:")
 
 
 
13
 
14
+ if search_title:
15
+ # κ²€μƒ‰ν•œ μ±… 제λͺ©μ— ν•΄λ‹Ήν•˜λŠ” μ΅œμ’… 감정 κ°€μ Έμ˜€κΈ°
16
+ result = df[df['μ±… 제λͺ©'] == search_title]
17
 
18
+ if not result.empty:
19
+ st.write(f"**{search_title}**에 λŒ€ν•œ μ΅œμ’… 감정: **{result.iloc[0]['μ΅œμ’…κ°μ •']}**")
20
+ else:
21
+ st.write("ν•΄λ‹Ή μ±… 제λͺ©μ„ 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.")
22
 
23
+ # 각 감정에 λŒ€ν•΄ μƒμœ„ 10개의 μ±… 제λͺ©κ³Ό ν™•λ₯ μ„ μΆ”μΆœ
24
+ st.title("각 감정별 ν™•λ₯  μƒμœ„ 10개의 μ±…")
 
 
 
25
 
26
+ # ν™•λ₯  데이터λ₯Ό 곡백으둜 λΆ„λ¦¬ν•˜μ—¬ 긍정, λΆ€μ •, 쀑립 μ—΄λ‘œ 뢄리
27
+ df[['긍정', 'λΆ€μ •', '쀑립']] = df['ν™•λ₯ '].str.strip('[]').str.split(expand=True).astype(float)
28
 
29
+ # 긍정 ν™•λ₯  μƒμœ„ 10개
30
+ top_positive = df.sort_values(by='긍정', ascending=False).head(10)[['μ±… 제λͺ©', '긍정']]
31
+ st.subheader("긍정 ν™•λ₯  μƒμœ„ 10개 μ±…")
32
+ st.table(top_positive)
33
 
34
+ # λΆ€μ • ν™•λ₯  μƒμœ„ 10개
35
+ top_negative = df.sort_values(by='λΆ€μ •', ascending=False).head(10)[['μ±… 제λͺ©', 'λΆ€μ •']]
36
+ st.subheader("λΆ€μ • ν™•λ₯  μƒμœ„ 10개 μ±…")
37
+ st.table(top_negative)
38
 
39
+ # 쀑립 ν™•λ₯  μƒμœ„ 10개
40
+ top_neutral = df.sort_values(by='쀑립', ascending=False).head(10)[['μ±… 제λͺ©', '쀑립']]
41
+ st.subheader("쀑립 ν™•λ₯  μƒμœ„ 10개 μ±…")
42
+ st.table(top_neutral)