Spaces:
Runtime error
Runtime error
File size: 7,192 Bytes
79a1132 2a7d045 79a1132 2a7d045 79a1132 2a7d045 79a1132 2a7d045 79a1132 2a7d045 79a1132 2a7d045 79a1132 |
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
import writer as wf
import writer.ai
import pandas as pd
from prompts import stock_prompts, income_prompts, earnings_prompt
from stock_data import download_data, download_sp500, stock_news, _one_day_data, income_statement, earnings_calls
from charts import update_scatter_chart
# Update all data
def updates(state):
state["message"] = "% Refreshing stock data..."
earnings_calls(state)
download_sp500(state)
stock_news(state)
download_data(state)
income_statement(state)
update_scatter_chart(state)
_one_day_data(state)
_refresh_window(state)
# Refresh the window
def _refresh_window(state):
state["show_income_metrics"]["visible"] = False
state["show_bar_graph"]["visible"] = False
state["show_analysis_text"]["visible"] = False
state["show_analysis_text"]["language"] = False
state["message"] = "Writer AI insights will be generated here"
# Summarize earnings call using Palmyra-Fin model
def summarize_earnings(state):
_refresh_window(state)
state["message"] = f"% {state['symbol']} earnings call will be summarized here"
earnings_transcript = state["earnings_transcript"]
prompt = earnings_prompt.format(earnings_transcript=earnings_transcript)
submission = writer.ai.complete(prompt, config={"model": "palmyra-fin-32k", "temperature": 0.7, "max_tokens": 8192})
state["message"] = f"+ {state['symbol']} earnings call summary"
state["analysis"] = submission.strip()
state["show_analysis_text"]["visible"] = True
def prompt_parameters_words(state,payload):
state["prompt_parameters_words"] = payload
_refresh_window(state)
def prompt_parameters_lang(state,payload):
state["prompt_parameters_lang"] = payload
generate_stock_analysis(state)
def generate_stock_analysis(state):
_refresh_window(state)
if(state["prompt_parameters_lang"] == ""):
state["prompt_parameters_lang"] == "English"
state["message"] = f"% {state['symbol']} trends will be analyzed here in {state['prompt_parameters_lang']}"
stock_name = state["symbol"]
stock_data = state["main_df"][:365]
rounded_value = round(state["prompt_parameters_words"], 0)
language = state["prompt_parameters_lang"]
# Convert the rounded value to an integer
integer_value = int(rounded_value)
prompt = stock_prompts.format(language=language, stock_name=stock_name,words=integer_value,stock_data=stock_data)
submission = writer.ai.complete(prompt, config={"model": "palmyra-fin-32k", "temperature": 0.7, "max_tokens": 8192})
state["analysis"] = submission.strip()
state["message"] = f"+ {state['symbol']} trends analyzed"
state["show_analysis_text"]["visible"] = True
state["show_analysis_text"]["language"] = True
return submission
def generate_income_analysis(state):
_refresh_window(state)
state["message"] = f"% {state['symbol']} income statement will be visualized here"
stock_name = state["symbol"]
stock_data = state["main_df"][:365]
income_statement_data = state["income_statement_df"][:365]
prompt = income_prompts.format(
income_statement_data=income_statement_data,
stock_data=stock_data,
stock_name=stock_name,
)
submission = writer.ai.complete(prompt, config={"model": "palmyra-fin-32k", "temperature": 0.7, "max_tokens": 8192})
state["analysis"] = submission.strip()
state["message"] = f"+ {state['symbol']} income statement visualized"
state["show_income_metrics"]["visible"] = True
state["show_analysis_text"]["visible"] = True
state["show_bar_graph"]["visible"] = True
return submission
def stock_tags(state, payload):
state["symbol"] = payload
updates(state)
def _get_main_df(filename):
main_df = pd.read_csv(filename)
return main_df
initial_state = wf.init_state(
{
"last_24_hours_open": "168.76",
"last_24_hours_high": "169.72",
"last_24_hours_low": "167.50",
"message": None,
"main_df": _get_main_df("daily_IBM.csv"),
"main_df_subset": _get_main_df("daily_IBM.csv"),
"symbol": "AAPL",
"articles": {
"EU seeks views on Microsoft, OpenAI, Google and Samsung deals, EU's Vestager says": {
"source": "Reuters",
"published_at": "June 28, 2024 at 15:40",
"url": "https://finance.yahoo.com/news/eu-seeks-views-microsoft-openai-144044802.html",
},
"Forget the S&P 500 -- Buy This Magnificent ETF Instead": {
"source": "Motley Fool",
"published_at": "June 28, 2024 at 15:00",
"url": "https://finance.yahoo.com/m/662fcc10-7b6c-3bd1-8b7f-6cc25e8a1e61/forget-the-s%26p-500-buy.html",
},
"Microsoft Corporation (MSFT) is Attracting Investor Attention: Here is What You Should Know": {
"source": "Zacks",
"published_at": "June 28, 2024 at 14:00",
"url": "https://finance.yahoo.com/news/microsoft-corporation-msft-attracting-investor-130015018.html",
},
},
"show_analysis_text": {
"visible": False,
"language": False
},
"show_income_metrics": {
"visible": False,
},
"tab_message": "- **Performance** tab highlights stock trends using an interactive graph where time filters can be selected.<br><li>**Stock data** tab shows the stock data from Yahoo Finance. <br><li>**Income data** tab shows the income statement from Yahoo Finance. <br><li>**View 10-K** tab shows the selected stock 10-K in a PDF viewer shown via an _API integration_.",
"prompt_parameters_lang": "English",
"prompt_parameters_words": 100,
"message": "Writer AI insights will be generated here",
"show_bar_graph": {"visible": False},
"output_language": {
"English": "English",
"Arabic": "Arabic",
"Bengali": "Bengali",
"Bulgarian": "Bulgarian",
"Chinese simplified": "Chinese simplified",
"Chinese traditional": "Chinese traditional",
"Croatian": "Croatian",
"Czech": "Czech",
"Danish": "Danish",
"Dutch": "Dutch",
"Finnish": "Finnish",
"French": "French",
"German": "German",
"Greek": "Greek",
"Hebrew": "Hebrew",
"Hindi": "Hindi",
"Hungarian": "Hungarian",
"Indonesian": "Indonesian",
"Italian": "Italian",
"Japanese": "Japanese",
"Korean": "Korean",
"Lithuanian": "Lithuanian",
"Polish": "Polish",
"Portuguese": "Portuguese",
"Romanian": "Romanian",
"Russian": "Russian",
"Spanish": "Spanish",
"Swahili": "Swahili",
"Swedish": "Swedish",
"Thai": "Thai",
"Turkish": "Turkish",
"Ukrainian": "Ukrainian",
"Vietnamese": "Vietnamese",
},
}
)
updates(initial_state)
initial_state.import_stylesheet("theme", "/static/custom.css?18")
|