File size: 1,946 Bytes
b8a570e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96240e1
b8a570e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import font_manager
import streamlit as st
from io import BytesIO

# μ‚¬μš©μž μ§€μ • 폰트 파일 경둜
font_path = r"H2GTRM.TTF"

# μ‚¬μš©μž μ§€μ • 폰트λ₯Ό matplotlib에 μΆ”κ°€
font_prop = font_manager.FontProperties(fname=font_path)
font_manager.fontManager.addfont(font_path)

# matplotlib의 κΈ°λ³Έ 폰트λ₯Ό μ‚¬μš©μž μ§€μ • 폰트둜 μ„€μ •
plt.rcParams['font.family'] = font_prop.get_name()

# μ—‘μ…€ νŒŒμΌμ„ μ½μ–΄μ˜΅λ‹ˆλ‹€.
file_path = r"book_analysis_predictions_summary.xlsx"
df = pd.read_excel(file_path)

# λ„μ„œλͺ… 열을 인덱슀둜 μ„€μ •ν•©λ‹ˆλ‹€.
df.set_index('λ„μ„œλͺ…', inplace=True)

# 월별 열을 μΆ”μΆœν•©λ‹ˆλ‹€.
months = ['2024λ…„ 7μ›”', '2024λ…„ 8μ›”', '2024λ…„ 9μ›”', '2024λ…„ 10μ›”', '2024λ…„ 11μ›”', '2024λ…„ 12μ›”']

# Streamlit μ• ν”Œλ¦¬μΌ€μ΄μ…˜μ˜ UI ꡬ성
st.title('랜덀포레슀트 기반 λ„μ„œ λŒ€μΆœκ±΄μˆ˜ 예츑')

# λ„μ„œλͺ…을 검색할 수 μžˆλŠ” μž…λ ₯ ν•„λ“œ 제곡
book_name = st.text_input('λ„μ„œλͺ…을 μž…λ ₯ν•˜μ„Έμš”:')

# λ„μ„œλͺ…을 μž…λ ₯ν–ˆμ„ λ•Œλ§Œ κ·Έλž˜ν”„ 생성
if book_name:
    if book_name in df.index:
        # λ„μ„œλ³„ κ·Έλž˜ν”„ 생성
        fig, ax = plt.subplots()
        ax.plot(months, df.loc[book_name, months], marker='o', label=book_name)
        ax.set_title(f'{book_name} 월별 λŒ€μΆœκ±΄μˆ˜ 뢄석')
        ax.set_xlabel('μ›”')
        ax.set_ylabel('λŒ€μΆœκ±΄μˆ˜')
        ax.set_xticklabels(months, rotation=45)
        ax.legend(title='λ„μ„œλͺ…')
        ax.grid(True)
        plt.tight_layout()  # κ·Έλž˜ν”„μ˜ λ ˆμ΄μ•„μ›ƒμ„ μ‘°μ •

        # κ·Έλž˜ν”„λ₯Ό Streamlitμ—μ„œ ν‘œμ‹œν•˜κΈ° μœ„ν•΄ BytesIO둜 μ €μž₯
        buf = BytesIO()
        plt.savefig(buf, format='png')
        buf.seek(0)
        st.image(buf, use_column_width=True)

        # κ·Έλž˜ν”„ νŒŒμΌμ„ μ €μž₯
        plt.close(fig)
    else:
        st.error('ν•΄λ‹Ή λ„μ„œλͺ…을 찾을 수 μ—†μŠ΅λ‹ˆλ‹€.')