Roberta2024 commited on
Commit
237f2f6
·
verified ·
1 Parent(s): 5f8f576

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -7,6 +7,7 @@ import time
7
  import matplotlib.pyplot as plt
8
  import matplotlib.font_manager as fm
9
  import matplotlib as mpl
 
10
 
11
  # Set up Streamlit app
12
  st.title("PCHOME 商品價格爬蟲分析")
@@ -45,15 +46,19 @@ if st.button("開始爬取"):
45
  st.write(f'Min price: {df["price"].min()}')
46
 
47
  # Download and set custom font
48
- !wget -O TaipeiSansTCBeta-Regular.ttf https://drive.google.com/uc?id=1eGAsTN1HBpJAkeVM57_C7ccp7hbgSz3_&export=download
49
- fm.fontManager.addfont('TaipeiSansTCBeta-Regular.ttf')
 
 
 
 
50
  mpl.rc('font', family='Taipei Sans TC Beta')
51
 
52
  # Visualization
53
  st.subheader("價格分布圖")
54
  fig, ax = plt.subplots(figsize=(15, 8))
55
  df['price'][:70].plot(ax=ax, subplots=False, color='skyblue', linewidth=2, marker='o', markersize=8)
56
- ax.set_title('PCHOME 電商網站上售價', fontsize=20, fontweight='bold')
57
  ax.axhline(y=10016, color='red', linestyle='--', linewidth=2, label='Threshold Price: 10016')
58
  ax.set_xlabel('Store ID', fontsize=14)
59
  ax.set_ylabel('Price', fontsize=14)
 
7
  import matplotlib.pyplot as plt
8
  import matplotlib.font_manager as fm
9
  import matplotlib as mpl
10
+ from io import BytesIO
11
 
12
  # Set up Streamlit app
13
  st.title("PCHOME 商品價格爬蟲分析")
 
46
  st.write(f'Min price: {df["price"].min()}')
47
 
48
  # Download and set custom font
49
+ font_url = "https://drive.google.com/uc?id=1eGAsTN1HBpJAkeVM57_C7ccp7hbgSz3_&export=download"
50
+ font_response = requests.get(font_url)
51
+ font_path = BytesIO(font_response.content)
52
+ with open("TaipeiSansTCBeta-Regular.ttf", "wb") as font_file:
53
+ font_file.write(font_response.content)
54
+ fm.fontManager.addfont("TaipeiSansTCBeta-Regular.ttf")
55
  mpl.rc('font', family='Taipei Sans TC Beta')
56
 
57
  # Visualization
58
  st.subheader("價格分布圖")
59
  fig, ax = plt.subplots(figsize=(15, 8))
60
  df['price'][:70].plot(ax=ax, subplots=False, color='skyblue', linewidth=2, marker='o', markersize=8)
61
+ ax.set_title('PCHOME 電商網站上商品售價', fontsize=20, fontweight='bold')
62
  ax.axhline(y=10016, color='red', linestyle='--', linewidth=2, label='Threshold Price: 10016')
63
  ax.set_xlabel('Store ID', fontsize=14)
64
  ax.set_ylabel('Price', fontsize=14)