tbdavid2019 commited on
Commit
9c22744
·
1 Parent(s): a2bf6d0
Files changed (1) hide show
  1. app.py +35 -2
app.py CHANGED
@@ -160,6 +160,39 @@ def get_stock_items(url):
160
  logging.error(f"獲取股票項目失敗: {str(e)}")
161
  return {}
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  def predict_stock(category, stock, stock_item, period, selected_features):
164
  if not all([category, stock, stock_item]):
165
  return None, "請選擇產業類別、類股和股票"
@@ -201,7 +234,7 @@ def predict_stock(category, stock, stock_item, period, selected_features):
201
  mode='lines+markers',
202
  name=f'預測{feature}'
203
  ))
204
-
205
  fig.update_layout(
206
  title=f'{stock_item} 股價預測 (未來5天)',
207
  xaxis_title='日期',
@@ -277,4 +310,4 @@ with gr.Blocks() as demo:
277
 
278
  # 啟動應用
279
  if __name__ == "__main__":
280
- demo.launch(share=False)
 
160
  logging.error(f"獲取股票項目失敗: {str(e)}")
161
  return {}
162
 
163
+ def update_category(category):
164
+ stocks = update_stocks(category)
165
+ return {
166
+ stock_dropdown: gr.update(choices=stocks, value=None),
167
+ stock_item_dropdown: gr.update(choices=[], value=None),
168
+ stock_plot: gr.update(value=None),
169
+ status_output: gr.update(value="")
170
+ }
171
+
172
+ def update_stock(category, stock):
173
+ if not category or not stock:
174
+ return {
175
+ stock_item_dropdown: gr.update(choices=[], value=None),
176
+ stock_plot: gr.update(value=None),
177
+ status_output: gr.update(value="")
178
+ }
179
+
180
+ url = next((item['網址'] for item in category_dict.get(category, [])
181
+ if item['類股'] == stock), None)
182
+
183
+ if url:
184
+ stock_items = get_stock_items(url)
185
+ return {
186
+ stock_item_dropdown: gr.update(choices=list(stock_items.keys()), value=None),
187
+ stock_plot: gr.update(value=None),
188
+ status_output: gr.update(value="")
189
+ }
190
+ return {
191
+ stock_item_dropdown: gr.update(choices=[], value=None),
192
+ stock_plot: gr.update(value=None),
193
+ status_output: gr.update(value="")
194
+ }
195
+
196
  def predict_stock(category, stock, stock_item, period, selected_features):
197
  if not all([category, stock, stock_item]):
198
  return None, "請選擇產業類別、類股和股票"
 
234
  mode='lines+markers',
235
  name=f'預測{feature}'
236
  ))
237
+
238
  fig.update_layout(
239
  title=f'{stock_item} 股價預測 (未來5天)',
240
  xaxis_title='日期',
 
310
 
311
  # 啟動應用
312
  if __name__ == "__main__":
313
+ demo.launch(share=False)