AmirTrader commited on
Commit
b0ac0e1
·
verified ·
1 Parent(s): 239ed0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -16
app.py CHANGED
@@ -24,35 +24,26 @@ from utils import load_hf_dataset # ,upload_to_hf_dataset, download_from_hf_dat
24
  # Get the Hugging Face API token from the environment; either set in .env file or in the environment directly in GitHub
25
  HF_TOKEN = os.getenv("HF_TOKEN")
26
 
27
- # Get the name of the dataset for TradingView, GuruFocus to read from
28
- dataset_name_TradingView_input = os.getenv("dataset_name_TradingView_input")
29
  dataset_name_GuruFocus_input = os.getenv("dataset_name_GuruFocus_input")
30
 
31
-
32
- @pn.cache()
33
- def get_tradingview(current_datetime):
34
- # Load lastest TradingView DataSet from HuggingFace Dataset which is always america.csv
35
- # download_from_hf_dataset("america.csv", dataset_name_TradingView_input, HF_TOKEN)
36
- return load_hf_dataset("america.csv", HF_TOKEN, dataset_name_TradingView_input)
37
-
38
-
39
  @pn.cache()
40
  def get_gurufocus(current_datetime):
41
  # Load lastest GuruFocus DataSet from HuggingFace Dataset which is always GuruFocus_merged.csv
42
  # daily_gurufocus_DF = load_dataset(dataset_name_GuruFocus_output , data_files="GuruFocus_merged.csv", split="train" , token=HF_TOKEN ).to_pandas()
43
  return load_hf_dataset(
44
- "GuruFocus_merged.csv", HF_TOKEN, dataset_name_GuruFocus_input
45
  )
46
 
47
-
48
  todaydate = pn.widgets.DatePicker(
49
  name="End Date", # value=datetime(2000, 1, 1),
 
50
  description="Select a Date",
51
  end=date.today(), # date(2023, 9, 1)
52
  )
53
 
54
- todaydate2 = datetime.today().strftime("%Y-%m-%d")
55
- df = get_gurufocus(todaydate2)
56
  selectedcol = pn.widgets.Select(
57
  name="Select Ratio", value="PEG Ratio", options=list(df.columns)
58
  )
@@ -72,7 +63,6 @@ ticker.value = "AAPL"
72
  selectedhover = "Ticker"
73
  hv.extension("bokeh")
74
 
75
-
76
  def create_plot(selectedcol, selecteditem, todaydate, selectedmethod, ticker):
77
  df = get_gurufocus(todaydate)
78
  if selectedmethod == "Mean":
@@ -105,7 +95,6 @@ def create_alert(selectedcol):
105
  text = f"### {selectedcol} \n {DescriptionDict[selectedcol]}"
106
  return pn.pane.Alert(text, alert_type="warning")
107
 
108
-
109
  bound_plot = pn.bind(
110
  create_plot,
111
  selectedcol=selectedcol,
@@ -114,6 +103,7 @@ bound_plot = pn.bind(
114
  selectedmethod=selectedmethod,
115
  ticker=ticker,
116
  )
 
117
  bound_alert = pn.bind(create_alert, selectedcol=selectedcol)
118
  pn.Column(
119
  pn.Row(selectedcol, selecteditem, todaydate, selectedmethod, ticker),
 
24
  # Get the Hugging Face API token from the environment; either set in .env file or in the environment directly in GitHub
25
  HF_TOKEN = os.getenv("HF_TOKEN")
26
 
27
+ # Get the name of the dataset for GuruFocus to read from
 
28
  dataset_name_GuruFocus_input = os.getenv("dataset_name_GuruFocus_input")
29
 
 
 
 
 
 
 
 
 
30
  @pn.cache()
31
  def get_gurufocus(current_datetime):
32
  # Load lastest GuruFocus DataSet from HuggingFace Dataset which is always GuruFocus_merged.csv
33
  # daily_gurufocus_DF = load_dataset(dataset_name_GuruFocus_output , data_files="GuruFocus_merged.csv", split="train" , token=HF_TOKEN ).to_pandas()
34
  return load_hf_dataset(
35
+ f"GuruFocus_merged_{current_datetime}.csv", HF_TOKEN, dataset_name_GuruFocus_input
36
  )
37
 
 
38
  todaydate = pn.widgets.DatePicker(
39
  name="End Date", # value=datetime(2000, 1, 1),
40
+ value=date.today() - timedelta(days=1),
41
  description="Select a Date",
42
  end=date.today(), # date(2023, 9, 1)
43
  )
44
 
45
+ todaydate_readcols = datetime.today().strftime("%Y-%m-%d")
46
+ df = get_gurufocus(todaydate_readcols)
47
  selectedcol = pn.widgets.Select(
48
  name="Select Ratio", value="PEG Ratio", options=list(df.columns)
49
  )
 
63
  selectedhover = "Ticker"
64
  hv.extension("bokeh")
65
 
 
66
  def create_plot(selectedcol, selecteditem, todaydate, selectedmethod, ticker):
67
  df = get_gurufocus(todaydate)
68
  if selectedmethod == "Mean":
 
95
  text = f"### {selectedcol} \n {DescriptionDict[selectedcol]}"
96
  return pn.pane.Alert(text, alert_type="warning")
97
 
 
98
  bound_plot = pn.bind(
99
  create_plot,
100
  selectedcol=selectedcol,
 
103
  selectedmethod=selectedmethod,
104
  ticker=ticker,
105
  )
106
+
107
  bound_alert = pn.bind(create_alert, selectedcol=selectedcol)
108
  pn.Column(
109
  pn.Row(selectedcol, selecteditem, todaydate, selectedmethod, ticker),