Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,29 +2,8 @@ import streamlit as st
|
|
2 |
from langchain_groq import ChatGroq
|
3 |
import yfinance as yf
|
4 |
|
5 |
-
# Initialize the ChatGroq model
|
6 |
-
llm = ChatGroq(model_name="Llama3-8b-8192", api_key=st.secrets['groq_api_key'])
|
7 |
-
|
8 |
-
# Custom CSS for dark blue theme
|
9 |
-
st.markdown(
|
10 |
-
"""
|
11 |
-
<style>
|
12 |
-
.stApp {
|
13 |
-
background-color: #1e1e2f;
|
14 |
-
color: white;
|
15 |
-
}
|
16 |
-
.stTextInput>div>input {
|
17 |
-
background-color: #2e2e3e;
|
18 |
-
color: white;
|
19 |
-
}
|
20 |
-
.stButton>button {
|
21 |
-
background-color: #007bff;
|
22 |
-
color: white;
|
23 |
-
}
|
24 |
-
</style>
|
25 |
-
""",
|
26 |
-
unsafe_allow_html=True,
|
27 |
-
)
|
28 |
|
29 |
# Initialize chat history in session state
|
30 |
if "messages" not in st.session_state:
|
@@ -58,6 +37,12 @@ if prompt := st.chat_input("Ask me about stocks..."):
|
|
58 |
response += f"Market Cap: {stock_data.get('marketCap', 'N/A')}\n"
|
59 |
response += f"PE Ratio: {stock_data.get('trailingPE', 'N/A')}\n"
|
60 |
response += f"Dividend Yield: {stock_data.get('dividendYield', 'N/A')}\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
else:
|
62 |
response = f"Sorry, I couldn't find data for {company_name}. Please check the ticker symbol."
|
63 |
|
@@ -70,9 +55,9 @@ if prompt := st.chat_input("Ask me about stocks..."):
|
|
70 |
except Exception as e:
|
71 |
response = f"An error occurred while processing your request: {str(e)}"
|
72 |
|
73 |
-
# Display assistant response in chat message container
|
74 |
with st.chat_message("assistant"):
|
75 |
-
st.write(response)
|
76 |
|
77 |
# Add assistant response to chat history
|
78 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
|
|
2 |
from langchain_groq import ChatGroq
|
3 |
import yfinance as yf
|
4 |
|
5 |
+
# Initialize the ChatGroq model using the secret API key
|
6 |
+
llm = ChatGroq(model_name="Llama3-8b-8192", api_key=st.secrets['groq_api_key'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
# Initialize chat history in session state
|
9 |
if "messages" not in st.session_state:
|
|
|
37 |
response += f"Market Cap: {stock_data.get('marketCap', 'N/A')}\n"
|
38 |
response += f"PE Ratio: {stock_data.get('trailingPE', 'N/A')}\n"
|
39 |
response += f"Dividend Yield: {stock_data.get('dividendYield', 'N/A')}\n"
|
40 |
+
|
41 |
+
# Simple investment recommendation logic (this can be improved)
|
42 |
+
if stock_data.get('trailingPE', 0) < 20: # Example condition for recommendation
|
43 |
+
response += "\n**Recommendation:** Yes, consider investing!"
|
44 |
+
else:
|
45 |
+
response += "\n**Recommendation:** No, it might not be a good time to invest."
|
46 |
else:
|
47 |
response = f"Sorry, I couldn't find data for {company_name}. Please check the ticker symbol."
|
48 |
|
|
|
55 |
except Exception as e:
|
56 |
response = f"An error occurred while processing your request: {str(e)}"
|
57 |
|
58 |
+
# Display assistant response in chat message container with line breaks for readability
|
59 |
with st.chat_message("assistant"):
|
60 |
+
st.write(response.replace("\n", "<br>"), unsafe_allow_html=True)
|
61 |
|
62 |
# Add assistant response to chat history
|
63 |
st.session_state.messages.append({"role": "assistant", "content": response})
|