dltmdgus commited on
Commit
b8a570e
Β·
verified Β·
1 Parent(s): 2bc3c9f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import matplotlib.pyplot as plt
3
+ from matplotlib import font_manager
4
+ import streamlit as st
5
+ from io import BytesIO
6
+
7
+ # μ‚¬μš©μž μ§€μ • 폰트 파일 경둜
8
+ font_path = r"H2GTRM.TTF"
9
+
10
+ # μ‚¬μš©μž μ§€μ • 폰트λ₯Ό matplotlib에 μΆ”κ°€
11
+ font_prop = font_manager.FontProperties(fname=font_path)
12
+ font_manager.fontManager.addfont(font_path)
13
+
14
+ # matplotlib의 κΈ°λ³Έ 폰트λ₯Ό μ‚¬μš©μž μ§€μ • 폰트둜 μ„€μ •
15
+ plt.rcParams['font.family'] = font_prop.get_name()
16
+
17
+ # μ—‘μ…€ νŒŒμΌμ„ μ½μ–΄μ˜΅λ‹ˆλ‹€.
18
+ file_path = r"book_analysis_predictions_summary.xlsx"
19
+ df = pd.read_excel(file_path)
20
+
21
+ # λ„μ„œλͺ… 열을 인덱슀둜 μ„€μ •ν•©λ‹ˆλ‹€.
22
+ df.set_index('λ„μ„œλͺ…', inplace=True)
23
+
24
+ # 월별 열을 μΆ”μΆœν•©λ‹ˆλ‹€.
25
+ months = ['2024λ…„ 7μ›”', '2024λ…„ 8μ›”', '2024λ…„ 9μ›”', '2024λ…„ 10μ›”', '2024λ…„ 11μ›”', '2024λ…„ 12μ›”']
26
+
27
+ # Streamlit μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ˜ UI ꡬ성
28
+ st.title('λ„μ„œ λŒ€μΆœ 건수 뢄석')
29
+
30
+ # λ„μ„œλͺ…을 검색할 수 μžˆλŠ” μž…λ ₯ ν•„λ“œ 제곡
31
+ book_name = st.text_input('λ„μ„œλͺ…을 μž…λ ₯ν•˜μ„Έμš”:')
32
+
33
+ # λ„μ„œλͺ…을 μž…λ ₯ν–ˆμ„ λ•Œλ§Œ κ·Έλž˜ν”„ 생성
34
+ if book_name:
35
+ if book_name in df.index:
36
+ # λ„μ„œλ³„ κ·Έλž˜ν”„ 생성
37
+ fig, ax = plt.subplots()
38
+ ax.plot(months, df.loc[book_name, months], marker='o', label=book_name)
39
+ ax.set_title(f'{book_name} 월별 λŒ€μΆœκ±΄μˆ˜ 뢄석')
40
+ ax.set_xlabel('μ›”')
41
+ ax.set_ylabel('λŒ€μΆœκ±΄μˆ˜')
42
+ ax.set_xticklabels(months, rotation=45)
43
+ ax.legend(title='λ„μ„œλͺ…')
44
+ ax.grid(True)
45
+ plt.tight_layout() # κ·Έλž˜ν”„μ˜ λ ˆμ΄μ•„μ›ƒμ„ μ‘°μ •
46
+
47
+ # κ·Έλž˜ν”„λ₯Ό Streamlitμ—μ„œ ν‘œμ‹œν•˜κΈ° μœ„ν•΄ BytesIO둜 μ €μž₯
48
+ buf = BytesIO()
49
+ plt.savefig(buf, format='png')
50
+ buf.seek(0)
51
+ st.image(buf, use_column_width=True)
52
+
53
+ # κ·Έλž˜ν”„ νŒŒμΌμ„ μ €μž₯
54
+ plt.close(fig)
55
+ else:
56
+ st.error('ν•΄λ‹Ή λ„μ„œλͺ…을 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.')