SeungHyun111 commited on
Commit
877f6f9
ยท
verified ยท
1 Parent(s): eb92ad4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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'C:\Users\user\Desktop\๋„์„œ๊ด€_๊ณต๋ชจ์ „\์ตœ์ข…\12_๋‹ค๋Œ€์ถœ๊ทธ๋ฃน\๋Œ€์ถœ๊ฑด์ˆ˜ ์˜ˆ์ธก\book_analysis_plots-์ด๋ฏธ์ง€-0.jpg',
13
+ r'C:\Users\user\Desktop\๋„์„œ๊ด€_๊ณต๋ชจ์ „\์ตœ์ข…\12_๋‹ค๋Œ€์ถœ๊ทธ๋ฃน\๋Œ€์ถœ๊ฑด์ˆ˜ ์˜ˆ์ธก\book_analysis_plots-์ด๋ฏธ์ง€-1.jpg'
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'C:\Users\user\Desktop\๋„์„œ๊ด€_๊ณต๋ชจ์ „\์ตœ์ข…\12_๋‹ค๋Œ€์ถœ๊ทธ๋ฃน\๋Œ€์ถœ๊ฑด์ˆ˜ ์˜ˆ์ธก\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 ํŒŒ์ผ์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.")