Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from llama_index import GPTSimpleVectorIndex, SimpleDirectoryReader, LLMPredictor
|
2 |
+
from langchain.llms import OpenAIChat
|
3 |
+
from IPython.display import Markdown, display
|
4 |
+
from llama_index import download_loader
|
5 |
+
import gradio as gr
|
6 |
+
import pandas as pd
|
7 |
+
import openai
|
8 |
+
|
9 |
+
import datetime
|
10 |
+
from datetime import datetime, date, time, timedelta
|
11 |
+
import os
|
12 |
+
|
13 |
+
listofcategories=["Earnings Announcements", "Automotive", "Retail"]
|
14 |
+
llm_predictor = LLMPredictor(llm=OpenAIChat(temperature=0, model_name="gpt-3.5-turbo"))
|
15 |
+
|
16 |
+
def getstuff(openapikey,category_selector):
|
17 |
+
dateforfilesave=datetime.today().strftime("%d-%m-%Y %I:%M%p")
|
18 |
+
print(category_selector)
|
19 |
+
print(dateforfilesave)
|
20 |
+
os.environ['OPENAI_API_KEY'] = str(openapikey)
|
21 |
+
|
22 |
+
RssReader = download_loader("RssReader")
|
23 |
+
reader = RssReader()
|
24 |
+
whichone=listofcategories[listofcategories.index(category_selector)]
|
25 |
+
|
26 |
+
if whichone=="Automotive":
|
27 |
+
rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=10000101"
|
28 |
+
querylist=["What are the top trends? Give output as a table with 3 columns named trend, company mentioned & reason","Write an email summarizing the news"]
|
29 |
+
elif whichone=="Retail":
|
30 |
+
rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=10000116"
|
31 |
+
querylist=["What are the top trends? Give output as a table with 3 columns named trend, company mentioned & reason","Write an email summarizing the news"]
|
32 |
+
elif whicone=='Earnings Announcements':
|
33 |
+
rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=15839135"
|
34 |
+
querylist=["Basis companies that are doing well name the sectors with positive momentum? Give output as a table with 3 columns named sector, company names & reason","Write an email summarizing the news"]
|
35 |
+
else:
|
36 |
+
rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=15839135" ###should not come here but using earnings url
|
37 |
+
querylist=["Basis companies that are doing well name the sectors with positive momentum? Give output as a table with 3 columns named sector, company names & reason","Write an email summarizing the news"]
|
38 |
+
|
39 |
+
documents = reader.load_data([rssurl])
|
40 |
+
index = GPTSimpleVectorIndex(documents)
|
41 |
+
|
42 |
+
answerlist=[]
|
43 |
+
for i in range(querylist):
|
44 |
+
print(i)
|
45 |
+
response = index.query(
|
46 |
+
querylist[i],
|
47 |
+
llm_predictor=llm_predictor,
|
48 |
+
response_mode="tree_summarize",
|
49 |
+
similarity_top_k=len(documents)/3
|
50 |
+
)
|
51 |
+
answerlist.append(response.response)
|
52 |
+
|
53 |
+
|
54 |
+
return answerlist
|
55 |
+
|
56 |
+
with gr.Blocks() as demo:
|
57 |
+
gr.Markdown("<h1><center>ChatGPT Stock News Snapshots</center></h1>")
|
58 |
+
gr.Markdown(
|
59 |
+
"""What are the sectors with positive momentum? What are the top technologies? Which companies have momentum? And much more. \n\nShowcases 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.\nLangChain & GPT-Index are both used.\n ![visitors](https://visitor-badge.glitch.me/badge?page_id=hra.ChatGPT-Tech-Radar)"""
|
60 |
+
)
|
61 |
+
|
62 |
+
with gr.Row() as row:
|
63 |
+
with gr.Column():
|
64 |
+
textboxopenapi = gr.Textbox(placeholder="Enter OpenAPI Key...", lines=1,label='OpenAPI Key')
|
65 |
+
category_selector=gr.Dropdown(
|
66 |
+
listofcategories, label="Sector", info="Select the snapshot you want..."
|
67 |
+
)
|
68 |
+
with gr.Column():
|
69 |
+
btn = gr.Button("Generate")
|
70 |
+
|
71 |
+
with gr.Row() as row:
|
72 |
+
with gr.Column():
|
73 |
+
outputsector = gr.Textbox(placeholder='', lines=4,label='Sector Snapshot')
|
74 |
+
with gr.Column():
|
75 |
+
outputtech = gr.Textbox(placeholder='', lines=4,label='Technology Snapshot')
|
76 |
+
|
77 |
+
btn.click(getstuff, inputs=[textboxopenapi,category_selector],outputs=[outputsector,outputtech])
|
78 |
+
|
79 |
+
|
80 |
+
demo.launch(debug=True)
|