hra commited on
Commit
6dec152
1 Parent(s): 9769727

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -5
app.py CHANGED
@@ -9,9 +9,35 @@ import datetime
9
  from datetime import datetime, date, time, timedelta
10
  import os
11
  import regex
 
12
 
13
  listofcategories=["Earnings Announcements", "Automotive","Energy","Healthcare","Retail","Technology"]
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  def getstuff(openapikey,category_selector):
16
  dateforfilesave=datetime.today().strftime("%d-%m-%Y %I:%M%p")
17
  print(category_selector)
@@ -25,8 +51,9 @@ def getstuff(openapikey,category_selector):
25
  reader = RssReader()
26
  whichone=listofcategories[listofcategories.index(category_selector)]
27
 
28
- querylist=["What are the top trends? Give output as a json (that can be converted to pandas dataframe) with 3 columns named trend, company mentioned & reason","Name the top & bottom performing companies? Give output as a json (that can be converted to pandas dataframe) with 4 columns named sector, company names, reason & top/bottom","You are an award winning email writer. Write an email summarizing the news. Do not say I am language model and cannot do this","You are an award winning email writer. Write an email summarizing the key macro trends basis the news.Do not say I am language model and cannot do this"]
29
-
 
30
  if whichone=="Automotive":
31
  rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=10000101"
32
  elif whichone=="Retail":
@@ -41,10 +68,12 @@ def getstuff(openapikey,category_selector):
41
  rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=10000110"
42
  elif whichone=='Earnings Announcements':
43
  rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=15839135"
44
- querylist=["What are the top trends? Give output as a json (that can be converted to pandas dataframe) with 3 columns named trend, company mentioned & reason","Find the top & bottom performing companies? Give output as a json (that can be converted to pandas dataframe) with 4 columns named sector, company names, reason & top/bottom","You are an award winning email writer. Write an email summarizing the news. Do not say I am language model and cannot do this","You are an award winning email writer. Write an email summarizing the key macro trends basis the news.Do not say I am language model and cannot do this"]
 
45
  else:
46
  rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=15839135" ###should not come here but using earnings url
47
- querylist=["Basis companies that are doing well name the sectors with positive momentum? Give output as a json (that can be converted to pandas dataframe) with 3 columns named sector, company names & reason","Find the top & bottom performing companies? Give output as a json (that can be converted to pandas dataframe) with 4 columns named sector, company names, reason & top/bottom","You are an award winning email writer. Write an email summarizing the news. Do not say I am language model and cannot do this","You are an award winning email writer. Write an email summarizing the key macro trends basis the news.Do not say I am language model and cannot do this"]
 
48
 
49
  documents = reader.load_data([rssurl])
50
  index = GPTSimpleVectorIndex(documents)
@@ -84,7 +113,7 @@ def getstuff(openapikey,category_selector):
84
  with gr.Blocks() as demo:
85
  gr.Markdown("<h1><center>ChatGPT Stock News Snapshots</center></h1>")
86
  gr.Markdown(
87
- """What are the sectors with positive momentum? What are the macro trends? Which companies have momentum? Sector summaries and much more. \n\nThis is a demo & showcases ChatGPT integrated with real data. It shows how to get real-time data and marry it with ChatGPT capabilities. This demonstrates 'Chain of Thought' thinking using ChatGPT.\n4 snapshots are provided for illustration (trends, sector outlook, news summary email, macro trends email\n\nNote: llama-index & gpt-3.5-turbo are used. The analysis takes roughly 120 secs & may not always be consistent. If ChatGPT API is overloaded you will get an error\n ![visitors](https://visitor-badge.glitch.me/badge?page_id=hra.chatgpt-stock-news-snapshots)"""
88
  )
89
 
90
  with gr.Row() as row:
 
9
  from datetime import datetime, date, time, timedelta
10
  import os
11
  import regex
12
+ import requests
13
 
14
  listofcategories=["Earnings Announcements", "Automotive","Energy","Healthcare","Retail","Technology"]
15
 
16
+ headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
17
+ url_hraprompts='https://us-central1-createinsightsproject.cloudfunctions.net/gethrahfprompts'
18
+
19
+ data={"prompt_type":'chatgpt_stock_news_snapshot_sector',"hra_token":HRA_TOKEN}
20
+ try:
21
+ r = requests.post(url_hraprompts, data=json.dumps(data), headers=headers)
22
+ except requests.exceptions.ReadTimeout as e:
23
+ print(e)
24
+ #print(r.content)
25
+
26
+
27
+ sector_prompt_text=str(r.content, 'UTF-8')
28
+ print(sector_prompt_text)
29
+
30
+ data={"prompt_type":'chatgpt_stock_news_snapshot_earnings',"hra_token":HRA_TOKEN}
31
+ try:
32
+ r = requests.post(url_hraprompts, data=json.dumps(data), headers=headers)
33
+ except requests.exceptions.ReadTimeout as e:
34
+ print(e)
35
+ #print(r.content)
36
+
37
+
38
+ earnings_prompt_text=str(r.content, 'UTF-8')
39
+ print(earnings_prompt_text)
40
+
41
  def getstuff(openapikey,category_selector):
42
  dateforfilesave=datetime.today().strftime("%d-%m-%Y %I:%M%p")
43
  print(category_selector)
 
51
  reader = RssReader()
52
  whichone=listofcategories[listofcategories.index(category_selector)]
53
 
54
+ #querylist=["What are the top trends? Give output as a json (that can be converted to pandas dataframe) with 3 columns named trend, company mentioned & reason","Name the top & bottom performing companies? Give output as a json (that can be converted to pandas dataframe) with 4 columns named sector, company names, reason & top/bottom","You are an award winning email writer. Write an email summarizing the news. Do not say I am language model and cannot do this","You are an award winning email writer. Write an email summarizing the key macro trends basis the news.Do not say I am language model and cannot do this"]
55
+ querylist=sector_prompt_text
56
+
57
  if whichone=="Automotive":
58
  rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=10000101"
59
  elif whichone=="Retail":
 
68
  rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=10000110"
69
  elif whichone=='Earnings Announcements':
70
  rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=15839135"
71
+ #querylist=["What are the top trends? Give output as a json (that can be converted to pandas dataframe) with 3 columns named trend, company mentioned & reason","Find the top & bottom performing companies? Give output as a json (that can be converted to pandas dataframe) with 4 columns named sector, company names, reason & top/bottom","You are an award winning email writer. Write an email summarizing the news. Do not say I am language model and cannot do this","You are an award winning email writer. Write an email summarizing the key macro trends basis the news.Do not say I am language model and cannot do this"]
72
+ querylist=earnings_prompt_text
73
  else:
74
  rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=15839135" ###should not come here but using earnings url
75
+ #querylist=["Basis companies that are doing well name the sectors with positive momentum? Give output as a json (that can be converted to pandas dataframe) with 3 columns named sector, company names & reason","Find the top & bottom performing companies? Give output as a json (that can be converted to pandas dataframe) with 4 columns named sector, company names, reason & top/bottom","You are an award winning email writer. Write an email summarizing the news. Do not say I am language model and cannot do this","You are an award winning email writer. Write an email summarizing the key macro trends basis the news.Do not say I am language model and cannot do this"]
76
+ querylist=earnings_prompt_text
77
 
78
  documents = reader.load_data([rssurl])
79
  index = GPTSimpleVectorIndex(documents)
 
113
  with gr.Blocks() as demo:
114
  gr.Markdown("<h1><center>ChatGPT Stock News Snapshots</center></h1>")
115
  gr.Markdown(
116
+ """What are the sectors with positive momentum? What are the macro trends? Which companies have momentum? Sector summaries and much more. \n\nThis is a demo & showcases ChatGPT integrated with real data. It shows how to get real-time data and marry it with ChatGPT capabilities. This demonstrates 'Chain of Thought' thinking using ChatGPT.\n\n4 snapshots are provided for illustration (trends, sector outlook, news summary email, macro trends email\n\nNote: llama-index & gpt-3.5-turbo are used. The analysis takes roughly 120 secs & may not always be consistent. If ChatGPT API is overloaded you will get an error\n ![visitors](https://visitor-badge.glitch.me/badge?page_id=hra.chatgpt-stock-news-snapshots)"""
117
  )
118
 
119
  with gr.Row() as row: