aiqtech commited on
Commit
486a745
ยท
verified ยท
1 Parent(s): 1fb9abf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -15,6 +15,7 @@ def download_data(ticker, start_date='2010-01-01'):
15
  if 'Adj Close' in data.columns:
16
  data = data[['Date', 'Adj Close']].copy()
17
  data.rename(columns={'Date': 'ds', 'Adj Close': 'y'}, inplace=True)
 
18
  else:
19
  raise ValueError("Expected 'Adj Close' in columns")
20
  return data
@@ -31,19 +32,18 @@ def predict_future_prices(ticker, periods=1825):
31
  forecast = model.predict(future)
32
 
33
  # ์˜ˆ์ธก ๊ฒฐ๊ณผ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
34
- forecast['ds'] = pd.to_datetime(forecast['ds']) # Ensure 'ds' is datetime type
35
  fig_main = go.Figure()
36
- fig_main.add_trace(go.Scatter(x=forecast['ds'], y=forecast['yhat'], mode='lines', name='Forecast (Blue)'))
37
  fig_main.add_trace(go.Scatter(x=data['ds'], y=data['y'], mode='lines', name='Actual (Black)', line=dict(color='black')))
 
38
 
39
  # ์—ฐ๊ฐ„ ๋ฐ ์ฃผ๊ฐ„ ๊ณ„์ ˆ์„ฑ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
40
- forecast['ds'] = forecast['ds'].dt.strftime('%Y-%m-%d') # Formatting for display
41
  fig_seasonal = model.plot_components(forecast)
42
- forecast['ds'] = pd.to_datetime(forecast['ds']) # Revert to datetime type for proper handling in Prophet components
43
-
44
- fig_yearly = px.line(x=pd.to_datetime(fig_seasonal[0]['ds']), y=fig_seasonal[0]['yearly'], labels={'x': 'Date', 'y': 'Yearly Trend'})
45
- fig_weekly = px.line(x=fig_seasonal[1]['day'], y=fig_seasonal[1]['weekly'], labels={'x': 'Day of Week', 'y': 'Weekly Trend'})
46
 
 
 
 
47
  return fig_main, forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']], fig_yearly, fig_weekly
48
 
49
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ • ๋ฐ ์‹คํ–‰
 
15
  if 'Adj Close' in data.columns:
16
  data = data[['Date', 'Adj Close']].copy()
17
  data.rename(columns={'Date': 'ds', 'Adj Close': 'y'}, inplace=True)
18
+ data['ds'] = pd.to_datetime(data['ds']) # Ensure 'ds' is datetime type
19
  else:
20
  raise ValueError("Expected 'Adj Close' in columns")
21
  return data
 
32
  forecast = model.predict(future)
33
 
34
  # ์˜ˆ์ธก ๊ฒฐ๊ณผ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
 
35
  fig_main = go.Figure()
 
36
  fig_main.add_trace(go.Scatter(x=data['ds'], y=data['y'], mode='lines', name='Actual (Black)', line=dict(color='black')))
37
+ fig_main.add_trace(go.Scatter(x=forecast['ds'], y=forecast['yhat'], mode='lines', name='Forecast (Blue)'))
38
 
39
  # ์—ฐ๊ฐ„ ๋ฐ ์ฃผ๊ฐ„ ๊ณ„์ ˆ์„ฑ ๊ทธ๋ž˜ํ”„ ์ƒ์„ฑ
40
+ # ์ž„์‹œ๋กœ matplotlib ํ”Œ๋กฏ ๋ฐ˜ํ™˜์„ ๋น„ํ™œ์„ฑํ™”ํ•˜๊ณ  ๊ฒฐ๊ณผ๋งŒ ๋ฐ˜ํ™˜
41
  fig_seasonal = model.plot_components(forecast)
42
+ forecast['ds'] = pd.to_datetime(forecast['ds']) # Revert to datetime type to avoid AttributeError
 
 
 
43
 
44
+ fig_yearly = px.line(x=pd.to_datetime(forecast['ds']), y=forecast['yearly'], labels={'x': 'Date', 'y': 'Yearly Trend'})
45
+ fig_weekly = px.line(x=pd.to_datetime(forecast['ds']), y=forecast['weekly'], labels={'x': 'Date', 'y': 'Weekly Trend'})
46
+
47
  return fig_main, forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']], fig_yearly, fig_weekly
48
 
49
  # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ • ๋ฐ ์‹คํ–‰