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