File size: 3,885 Bytes
710fd08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e162922
710fd08
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from llama_index  import GPTSimpleVectorIndex, SimpleDirectoryReader, LLMPredictor
from langchain.llms import OpenAIChat
from llama_index import download_loader
import gradio as gr
import pandas as pd
import openai

import datetime
from datetime import datetime, date, time, timedelta
import os

listofcategories=["Earnings Announcements", "Automotive", "Retail"]

def getstuff(openapikey,category_selector):
    dateforfilesave=datetime.today().strftime("%d-%m-%Y %I:%M%p")
    print(category_selector)
    print(dateforfilesave)
    os.environ['OPENAI_API_KEY'] = str(openapikey)
    
    RssReader = download_loader("RssReader")
    reader = RssReader()
    whichone=listofcategories[listofcategories.index(category_selector)]

    if whichone=="Automotive":
        rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=10000101"
        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"]
    elif whichone=="Retail":
        rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=10000116"
        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"]
    elif whicone=='Earnings Announcements':
        rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=15839135"
        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"]
    else:
        rssurl="https://search.cnbc.com/rs/search/combinedcms/view.xml?partnerId=wrss01&id=15839135" ###should not come here but using earnings url
        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"]
    
    documents = reader.load_data([rssurl])
    index = GPTSimpleVectorIndex(documents)
    llm_predictor = LLMPredictor(llm=OpenAIChat(temperature=0, model_name="gpt-3.5-turbo"))

    answerlist=[]
    for i in range(querylist):
        print(i)
        response = index.query(
        querylist[i], 
        llm_predictor=llm_predictor,
        response_mode="tree_summarize",
        similarity_top_k=len(documents)/3
        )
        answerlist.append(response.response)
    
    
    return answerlist

with gr.Blocks() as demo:
    gr.Markdown("<h1><center>ChatGPT Stock News Snapshots</center></h1>")
    gr.Markdown(
        """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)"""
        )
    
    with gr.Row() as row:
        with gr.Column():
            textboxopenapi = gr.Textbox(placeholder="Enter OpenAPI Key...", lines=1,label='OpenAPI Key')
            category_selector=gr.Dropdown(
            listofcategories, label="Sector", info="Select the snapshot you want..."
            )
        with gr.Column():
            btn = gr.Button("Generate")
        
    with gr.Row() as row:
      with gr.Column():
        outputsector = gr.Textbox(placeholder='', lines=4,label='Sector Snapshot')
      with gr.Column():
        outputtech = gr.Textbox(placeholder='', lines=4,label='Technology Snapshot')

    btn.click(getstuff, inputs=[textboxopenapi,category_selector],outputs=[outputsector,outputtech])
    
    
demo.launch(debug=True)