mukhtar commited on
Commit
5d461d1
·
1 Parent(s): d84e925

cleaning up

Browse files
Files changed (2) hide show
  1. pag/monitor.py +13 -4
  2. requirements.txt +2 -1
pag/monitor.py CHANGED
@@ -17,7 +17,13 @@ import grpc
17
  import pb.timesfm_pb2_grpc
18
  import pb.timesfm_pb2
19
  from openai import OpenAI
 
20
  import time
 
 
 
 
 
21
 
22
  def check_authentication():
23
  if not check_password():
@@ -30,8 +36,8 @@ config.instance_id = '352670fb-2edf-4abd-90c8-437485a2403e'
30
  config.sh_client_id = 'ca95f10f-443c-4c60-9a36-98950292bb9b'
31
  config.sh_client_secret = 'rNFGRxGNiNFrXJfGyHIkVRyGOrdWNsfI'
32
  config.sh_timesfm_IP = "34.121.141.161"
33
- client = OpenAI(api_key= os.environ['OPENAI_KEY'])
34
- print(os.environ)
35
 
36
  def select_field(gdf):
37
  st.markdown("""
@@ -309,6 +315,7 @@ def monitor_fields():
309
  st.write(f"Press the button below to predict {metric} for the next 10 weeks")
310
  subcol1, subcol2, subcol3 = st.columns(3)
311
  if subcol2.button(f'Predict & Recommend'):
 
312
  start_date = '2024-01-01'
313
  today = datetime.today()
314
  end_date = today.strftime('%Y-%m-%d')
@@ -328,6 +335,7 @@ def monitor_fields():
328
  counter = counter + 100/(len(dates))
329
  my_bar.progress(round(counter), text=f"Downloading Data for the last {len(dates)//4} months: {round(counter)}%")
330
 
 
331
  # chart_data = pd.DataFrame(
332
  # {
333
  # "date": [metric[0] for metric in downloaded_prev_metrics],
@@ -379,6 +387,7 @@ def monitor_fields():
379
 
380
  st.area_chart(prediction_chart_data, x="date", y=[f"history_{metric}_values", f"predicted_{metric}_values"])
381
 
 
382
  crop = "Wheat"
383
 
384
  try:
@@ -397,9 +406,9 @@ def monitor_fields():
397
  frequency_penalty=0,
398
  presence_penalty=0
399
  )
400
- st.write(response.choices[0].message.content)
401
  except:
402
- st.write("Server Error: Could't generate recommendation!")
403
 
404
 
405
 
 
17
  import pb.timesfm_pb2_grpc
18
  import pb.timesfm_pb2
19
  from openai import OpenAI
20
+ from dotenv import load_dotenv
21
  import time
22
+ import dotenv
23
+
24
+
25
+ load_dotenv()
26
+
27
 
28
  def check_authentication():
29
  if not check_password():
 
36
  config.sh_client_id = 'ca95f10f-443c-4c60-9a36-98950292bb9b'
37
  config.sh_client_secret = 'rNFGRxGNiNFrXJfGyHIkVRyGOrdWNsfI'
38
  config.sh_timesfm_IP = "34.121.141.161"
39
+ OpenAI_key = os.getenv('OPENAI_KEY')
40
+ client = OpenAI(api_key= OpenAI_key)
41
 
42
  def select_field(gdf):
43
  st.markdown("""
 
315
  st.write(f"Press the button below to predict {metric} for the next 10 weeks")
316
  subcol1, subcol2, subcol3 = st.columns(3)
317
  if subcol2.button(f'Predict & Recommend'):
318
+
319
  start_date = '2024-01-01'
320
  today = datetime.today()
321
  end_date = today.strftime('%Y-%m-%d')
 
335
  counter = counter + 100/(len(dates))
336
  my_bar.progress(round(counter), text=f"Downloading Data for the last {len(dates)//4} months: {round(counter)}%")
337
 
338
+ st.subheader('Predictions:')
339
  # chart_data = pd.DataFrame(
340
  # {
341
  # "date": [metric[0] for metric in downloaded_prev_metrics],
 
387
 
388
  st.area_chart(prediction_chart_data, x="date", y=[f"history_{metric}_values", f"predicted_{metric}_values"])
389
 
390
+ st.subheader('Recommendation:')
391
  crop = "Wheat"
392
 
393
  try:
 
406
  frequency_penalty=0,
407
  presence_penalty=0
408
  )
409
+ st.caption(response.choices[0].message.content)
410
  except:
411
+ st.code("Server Error: Could't generate recommendation!")
412
 
413
 
414
 
requirements.txt CHANGED
@@ -12,4 +12,5 @@ streamlit==1.29.0
12
  geopy==2.4.1
13
  grpcio
14
  grpcio-tools
15
- openai
 
 
12
  geopy==2.4.1
13
  grpcio
14
  grpcio-tools
15
+ openai
16
+ python-dotenv