Rooobert commited on
Commit
8e357ef
·
verified ·
1 Parent(s): d9cca3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -3
app.py CHANGED
@@ -211,11 +211,32 @@ def main():
211
  # 分隔線
212
  st.markdown("---")
213
 
214
- # 讀取數據
215
- df = read_google_sheet(sheet_id, gid)
216
 
217
- if df is not None:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  analyzer = SurveyAnalyzer()
 
 
 
219
 
220
  # 新增場域和月份篩選器
221
  st.sidebar.header("🔍 數據篩選")
 
211
  # 分隔線
212
  st.markdown("---")
213
 
214
+ # 上傳 CSV 檔案
215
+ uploaded_file = st.file_uploader("上傳 CSV 檔案", type=['csv'])
216
 
217
+ if uploaded_file is not None:
218
+ # 讀取上傳的 CSV 檔案
219
+ try:
220
+ df = pd.read_csv(uploaded_file, encoding='utf-8')
221
+
222
+ # 儲存到 session state,以便在其他函數中使用
223
+ st.session_state['uploaded_file'] = uploaded_file
224
+
225
+ # 創建分析器
226
+ analyzer = SurveyAnalyzer()
227
+
228
+ elif st.button('使用預設範例數據'):
229
+ # 如果沒有上傳檔案,提供預設數據讀取
230
+ df = read_google_sheet(sheet_id, gid)
231
+
232
+ if df is None:
233
+ st.error("無法讀取預設數據,請上傳 CSV 檔案")
234
+ return
235
+
236
  analyzer = SurveyAnalyzer()
237
+ else:
238
+ st.info("請上傳 CSV 檔案或使用預設範例數據")
239
+ return
240
 
241
  # 新增場域和月份篩選器
242
  st.sidebar.header("🔍 數據篩選")