Spaces:
Sleeping
Sleeping
muzammil-eds
commited on
Commit
•
e14dd7a
1
Parent(s):
893a788
Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,42 @@
|
|
1 |
-
import os
|
2 |
import streamlit as st
|
3 |
import yfinance as yf
|
4 |
import pandas as pd
|
5 |
from langchain.agents import create_csv_agent, AgentType
|
6 |
-
from langchain.chat_models import ChatOpenAI
|
7 |
from htmlTemplates import css, user_template, bot_template
|
8 |
|
9 |
-
|
10 |
-
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
model='gpt-3.5-turbo',
|
15 |
-
max_tokens=500,
|
16 |
-
temperature=0.7,
|
17 |
)
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
def init_ses_states():
|
20 |
st.session_state.setdefault('chat_history', [])
|
21 |
|
|
|
22 |
def relative_returns(df):
|
23 |
rel = df.pct_change()
|
24 |
cumret = ((1 + rel).cumprod() - 1).fillna(0)
|
25 |
return cumret
|
26 |
|
|
|
27 |
def display_convo():
|
28 |
with st.container():
|
29 |
for i, message in enumerate(reversed(st.session_state.chat_history)):
|
30 |
if i % 2 == 0:
|
31 |
-
|
32 |
else:
|
33 |
st.markdown(user_template.replace("{{MSG}}", message), unsafe_allow_html=True)
|
34 |
|
|
|
35 |
def main():
|
36 |
st.set_page_config(page_title="Stock Price AI Bot", page_icon=":chart:")
|
37 |
st.write(css, unsafe_allow_html=True)
|
@@ -40,7 +45,9 @@ def main():
|
|
40 |
st.caption("Visualizations and OpenAI Chatbot for Multiple Stocks Over A Specified Period")
|
41 |
|
42 |
with st.sidebar:
|
43 |
-
asset_tickers = sorted(
|
|
|
|
|
44 |
asset_dropdown = st.multiselect('Pick Assets:', asset_tickers)
|
45 |
metric_tickers = ['Adj. Close', 'Relative Returns']
|
46 |
metric_dropdown = st.selectbox("Metric", metric_tickers)
|
@@ -60,7 +67,7 @@ def main():
|
|
60 |
if "Area Chart" in viz_dropdown:
|
61 |
st.area_chart(df)
|
62 |
|
63 |
-
st.header("Chat with your Data")
|
64 |
query = st.text_input("Enter a query:")
|
65 |
chat_prompt = f'''
|
66 |
You are an AI ChatBot intended to help with user stock data.
|
@@ -90,5 +97,6 @@ def main():
|
|
90 |
except Exception as e:
|
91 |
st.error(f"An error occurred: {str(e)}")
|
92 |
|
|
|
93 |
if __name__ == '__main__':
|
94 |
main()
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import yfinance as yf
|
3 |
import pandas as pd
|
4 |
from langchain.agents import create_csv_agent, AgentType
|
|
|
5 |
from htmlTemplates import css, user_template, bot_template
|
6 |
|
7 |
+
from langchain.llms import GPT4All
|
8 |
+
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
9 |
|
10 |
+
local_path = (
|
11 |
+
"tinyllama-1.1b-chat-v0.3.Q2_K.gguf" # replace with your desired local file path
|
|
|
|
|
|
|
12 |
)
|
13 |
|
14 |
+
# Callbacks support token-wise streaming
|
15 |
+
callbacks = [StreamingStdOutCallbackHandler()]
|
16 |
+
|
17 |
+
# Verbose is required to pass to the callback manager
|
18 |
+
llm = GPT4All(model=local_path, callbacks=callbacks, verbose=True)
|
19 |
+
|
20 |
+
|
21 |
def init_ses_states():
|
22 |
st.session_state.setdefault('chat_history', [])
|
23 |
|
24 |
+
|
25 |
def relative_returns(df):
|
26 |
rel = df.pct_change()
|
27 |
cumret = ((1 + rel).cumprod() - 1).fillna(0)
|
28 |
return cumret
|
29 |
|
30 |
+
|
31 |
def display_convo():
|
32 |
with st.container():
|
33 |
for i, message in enumerate(reversed(st.session_state.chat_history)):
|
34 |
if i % 2 == 0:
|
35 |
+
st.markdown(bot_template.replace("{{MSG}}", message), unsafe_allow_html=True)
|
36 |
else:
|
37 |
st.markdown(user_template.replace("{{MSG}}", message), unsafe_allow_html=True)
|
38 |
|
39 |
+
|
40 |
def main():
|
41 |
st.set_page_config(page_title="Stock Price AI Bot", page_icon=":chart:")
|
42 |
st.write(css, unsafe_allow_html=True)
|
|
|
45 |
st.caption("Visualizations and OpenAI Chatbot for Multiple Stocks Over A Specified Period")
|
46 |
|
47 |
with st.sidebar:
|
48 |
+
asset_tickers = sorted(
|
49 |
+
['DOW', 'NVDA', 'TSL', 'GOOGL', 'AMZN', 'AI', 'NIO', 'LCID', 'F', 'LYFY', 'AAPL', 'MSFT', 'BTC-USD',
|
50 |
+
'ETH-USD'])
|
51 |
asset_dropdown = st.multiselect('Pick Assets:', asset_tickers)
|
52 |
metric_tickers = ['Adj. Close', 'Relative Returns']
|
53 |
metric_dropdown = st.selectbox("Metric", metric_tickers)
|
|
|
67 |
if "Area Chart" in viz_dropdown:
|
68 |
st.area_chart(df)
|
69 |
|
70 |
+
st.header("Chat with your Data")
|
71 |
query = st.text_input("Enter a query:")
|
72 |
chat_prompt = f'''
|
73 |
You are an AI ChatBot intended to help with user stock data.
|
|
|
97 |
except Exception as e:
|
98 |
st.error(f"An error occurred: {str(e)}")
|
99 |
|
100 |
+
|
101 |
if __name__ == '__main__':
|
102 |
main()
|