Spaces:
Sleeping
Sleeping
| 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('ν΄λΉ λμλͺ μ μ°Ύμ μ μμ΅λλ€.') | |