dltmdgus commited on
Commit
d292b25
ยท
verified ยท
1 Parent(s): 707603c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -57
app.py CHANGED
@@ -1,59 +1,55 @@
1
  import streamlit as st
2
  import pandas as pd
3
- import altair as alt
4
- from PIL import Image
5
- import os
6
-
7
- # Streamlit ์•ฑ ์„ค์ •
8
- st.title('์—ฐ๋ น/์„ฑ๋ณ„์— ๋”ฐ๋ฅธ ์˜ˆ์ธก ๋Œ€์ถœ ๊ฑด์ˆ˜')
9
-
10
- # ์ด๋ฏธ์ง€ ๊ฒฝ๋กœ ์„ค์ •
11
- image_paths = [
12
- r'image-1.jpeg',
13
- r'image-2.jpeg'
14
- ]
15
-
16
- # ๋‘ ๊ฐœ์˜ ์ด๋ฏธ์ง€๋ฅผ Streamlit์— ํ‘œ์‹œ
17
- for image_path in image_paths:
18
- if os.path.exists(image_path):
19
- image = Image.open(image_path)
20
- st.image(image, caption=os.path.basename(image_path))
21
- else:
22
- st.error(f"์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค: {image_path}")
23
-
24
- # Excel ํŒŒ์ผ ๊ฒฝ๋กœ ์„ค์ •
25
- excel_path = r'book_analysis_summary.xlsx'
26
-
27
- # Excel ๋ฐ์ดํ„ฐ ๋กœ๋“œ
28
- if os.path.exists(excel_path):
29
- df = pd.read_excel(excel_path)
30
-
31
- # '์—ฐ๋ น_์„ฑ๋ณ„' ์—ด์—์„œ ์œ ๋‹ˆํฌํ•œ ์นดํ…Œ๊ณ ๋ฆฌ ์ถ”์ถœ
32
- categories = df['์—ฐ๋ น_์„ฑ๋ณ„'].unique()
33
- selected_category = st.selectbox('์นดํ…Œ๊ณ ๋ฆฌ ์„ ํƒ', categories)
34
-
35
- # ์„ ํƒํ•œ ์นดํ…Œ๊ณ ๋ฆฌ์— ํ•ด๋‹นํ•˜๋Š” ๋ฐ์ดํ„ฐ ํ•„ํ„ฐ๋ง
36
- selected_data = df[df['์—ฐ๋ น_์„ฑ๋ณ„'] == selected_category]
37
-
38
- # ํ•„์š”ํ•œ ์—ด๋งŒ ์ถ”์ถœ (์˜ˆ์ธก ๋Œ€์ถœ๊ฑด์ˆ˜, ์‹ค์ œ ๋Œ€์ถœ๊ฑด์ˆ˜)
39
- filtered_data = selected_data[['์˜ˆ์ธก ๋Œ€์ถœ๊ฑด์ˆ˜', '์‹ค์ œ ๋Œ€์ถœ๊ฑด์ˆ˜']]
40
-
41
- # ํ•„ํ„ฐ๋ง๋œ ๋ฐ์ดํ„ฐ ํ‘œ์‹œ
42
- st.write(f"์„ ํƒํ•œ ์นดํ…Œ๊ณ ๋ฆฌ: {selected_category}")
43
- st.write(filtered_data)
44
-
45
- # ๋ฐ์ดํ„ฐ๋ฅผ ์„ธ๋กœ ๋ง‰๋Œ€ ๊ทธ๋ž˜ํ”„๋กœ ์‹œ๊ฐํ™”
46
- chart_data = filtered_data.reset_index().melt('index', var_name='Type', value_name='Count')
47
-
48
- bar_chart = alt.Chart(chart_data).mark_bar().encode(
49
- x=alt.X('Type:N', title=None),
50
- y=alt.Y('Count:Q', title='๋Œ€์ถœ๊ฑด์ˆ˜'),
51
- color='Type:N'
52
- ).properties(
53
- width=600,
54
- height=400
55
- )
56
-
57
- st.altair_chart(bar_chart, use_container_width=True)
58
- else:
59
- st.error("Excel ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")
 
1
  import streamlit as st
2
  import pandas as pd
3
+ import matplotlib.pyplot as plt
4
+ import seaborn as sns
5
+ from matplotlib.font_manager import FontProperties, get_cachedir
6
+ from matplotlib import rcParams
7
+
8
+ # Streamlit ํŽ˜์ด์ง€ ์„ค์ •
9
+ st.set_page_config(page_title="๋„์„œ ๋Œ€์ถœ ์ˆ˜์š” ์˜ˆ์ธก", layout="wide")
10
+
11
+ # ์ด๋ฏธ์ง€ ์—…๋กœ๋“œ
12
+ st.sidebar.title("์ด๋ฏธ์ง€ ๋ณด๊ธฐ")
13
+ image1 = "image-1.jpeg"
14
+ image2 = "image-2.jpeg"
15
+ st.sidebar.image(image1, caption="์ด๋ฏธ์ง€ 1", use_column_width=True)
16
+ st.sidebar.image(image2, caption="์ด๋ฏธ์ง€ 2", use_column_width=True)
17
+
18
+ # ์—‘์…€ ํŒŒ์ผ ๊ฒฝ๋กœ
19
+ file_path = r'book_analysis_summary.xlsx'
20
+
21
+ # ์—‘์…€ ํŒŒ์ผ ์ฝ๊ธฐ
22
+ df = pd.read_excel(file_path)
23
+
24
+ # Streamlit ์•ฑ ์ œ๋ชฉ
25
+ st.title("๋„์„œ ๋Œ€์ถœ ์˜ˆ์ธก ๋ถ„์„")
26
+
27
+ # ์—ฐ๋ น_์„ฑ๋ณ„ ์—ด์„ ๊ธฐ์ค€์œผ๋กœ ๊ทธ๋ฃนํ™”
28
+ group_column = '์—ฐ๋ น_์„ฑ๋ณ„'
29
+ if group_column in df.columns:
30
+ st.sidebar.title("๊ทธ๋ฃน ์„ ํƒ")
31
+ groups = df[group_column].unique()
32
+ selected_group = st.sidebar.selectbox("๊ทธ๋ฃน ์„ ํƒ", groups)
33
+
34
+ # ์„ ํƒ๋œ ๊ทธ๋ฃน์˜ ๋ฐ์ดํ„ฐ ํ•„ํ„ฐ๋ง
35
+ filtered_data = df[df[group_column] == selected_group]
36
+
37
+ # ํฐํŠธ ์„ค์ •
38
+ font_path = "H2GTRM.TTF" # ํฐํŠธ ํŒŒ์ผ ๊ฒฝ๋กœ
39
+ font_prop = FontProperties(fname=font_path)
40
+
41
+ # ํฐํŠธ ์†์„ฑ ์„ค์ •
42
+ rcParams['font.family'] = font_prop.get_name() # ํฐํŠธ ์„ค์ •
43
+ rcParams['font.size'] = 12 # ๊ธฐ๋ณธ ํฐํŠธ ํฌ๊ธฐ ์„ค์ •
44
+
45
+ fig, ax = plt.subplots(figsize=(10, 6))
46
+ sns.barplot(data=filtered_data, x='์—ฐ๋ น_์„ฑ๋ณ„', y='์˜ˆ์ธก ๋Œ€์ถœ๊ฑด์ˆ˜', ax=ax, color='blue', label='์˜ˆ์ธก ๋Œ€์ถœ๊ฑด์ˆ˜')
47
+ sns.barplot(data=filtered_data, x='์—ฐ๋ น_์„ฑ๋ณ„', y='์‹ค์ œ ๋Œ€์ถœ๊ฑด์ˆ˜', ax=ax, color='red', label='์‹ค์ œ ๋Œ€์ถœ๊ฑด์ˆ˜')
48
+ ax.set_title(f'์˜ˆ์ธก ๋Œ€์ถœ ๊ฑด์ˆ˜ vs ์‹ค์ œ ๋Œ€์ถœ ๊ฑด์ˆ˜ ({selected_group})')
49
+ ax.set_xlabel('์—ฐ๋ น๋Œ€ ๋ฐ ์„ฑ๋ณ„')
50
+ ax.set_ylabel('๋Œ€์ถœ ๊ฑด์ˆ˜')
51
+ ax.legend()
52
+ plt.xticks(rotation=45)
53
+
54
+ # Matplotlib ๊ทธ๋ž˜ํ”„๋ฅผ Streamlit์—์„œ ๋ Œ๋”๋ง
55
+ st.pyplot(fig)