Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,9 +10,24 @@ from duckduckgo_search import DDGS
|
|
| 10 |
st.set_page_config(
|
| 11 |
page_title="Financial Analysis AI Agent",
|
| 12 |
page_icon="πΉ",
|
| 13 |
-
layout="
|
| 14 |
)
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
# Initialize Groq Client
|
| 17 |
def get_groq_client():
|
| 18 |
try:
|
|
@@ -123,66 +138,68 @@ def main():
|
|
| 123 |
st.title("π Advanced Financial Insight AI")
|
| 124 |
st.markdown("Comprehensive stock analysis with DuckDuckGo news search")
|
| 125 |
|
| 126 |
-
#
|
| 127 |
-
st.
|
| 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 |
-
|
| 179 |
|
| 180 |
# Disclaimer
|
| 181 |
-
st.
|
| 182 |
-
st.
|
| 183 |
"π¨ Disclaimer: This is an AI-generated analysis. "
|
| 184 |
"Always consult with a financial advisor before making investment decisions."
|
| 185 |
)
|
|
|
|
| 186 |
|
| 187 |
# Run the Streamlit app
|
| 188 |
if __name__ == "__main__":
|
|
|
|
| 10 |
st.set_page_config(
|
| 11 |
page_title="Financial Analysis AI Agent",
|
| 12 |
page_icon="πΉ",
|
| 13 |
+
layout="centered"
|
| 14 |
)
|
| 15 |
|
| 16 |
+
# Custom CSS for center alignment
|
| 17 |
+
st.markdown("""
|
| 18 |
+
<style>
|
| 19 |
+
.reportview-container .main .block-container {
|
| 20 |
+
text-align: center;
|
| 21 |
+
}
|
| 22 |
+
.stTextInput > div > div > input {
|
| 23 |
+
text-align: center;
|
| 24 |
+
}
|
| 25 |
+
.stSelectbox > div > div > div {
|
| 26 |
+
text-align: center;
|
| 27 |
+
}
|
| 28 |
+
</style>
|
| 29 |
+
""", unsafe_allow_html=True)
|
| 30 |
+
|
| 31 |
# Initialize Groq Client
|
| 32 |
def get_groq_client():
|
| 33 |
try:
|
|
|
|
| 138 |
st.title("π Advanced Financial Insight AI")
|
| 139 |
st.markdown("Comprehensive stock analysis with DuckDuckGo news search")
|
| 140 |
|
| 141 |
+
# Center columns for inputs
|
| 142 |
+
col1, col2, col3 = st.columns([1,2,1])
|
| 143 |
|
| 144 |
+
with col2:
|
| 145 |
+
# Stock Symbol Input
|
| 146 |
+
stock_symbol = st.text_input(
|
| 147 |
+
"Enter Stock Symbol",
|
| 148 |
+
value="NVDA",
|
| 149 |
+
help="Enter a valid stock ticker (e.g., AAPL, GOOGL)"
|
| 150 |
+
)
|
| 151 |
|
| 152 |
+
# Analysis Type Selection
|
| 153 |
+
query_type = st.selectbox(
|
| 154 |
+
"Select Analysis Type",
|
| 155 |
+
[
|
| 156 |
+
"Comprehensive Analysis",
|
| 157 |
+
"Analyst Recommendations",
|
| 158 |
+
"Latest News Analysis"
|
| 159 |
+
]
|
| 160 |
+
)
|
| 161 |
|
| 162 |
+
# Generate Analysis Button
|
| 163 |
+
if st.button("Generate Analysis"):
|
| 164 |
+
with st.spinner("Fetching and analyzing stock data..."):
|
| 165 |
+
try:
|
| 166 |
+
# Fetch Stock Information
|
| 167 |
+
stock_info = get_stock_info(stock_symbol)
|
| 168 |
+
|
| 169 |
+
if stock_info:
|
| 170 |
+
# Display Stock Information
|
| 171 |
+
st.subheader(f"Financial Snapshot: {stock_symbol}")
|
| 172 |
+
info_df = pd.DataFrame.from_dict(stock_info, orient='index', columns=['Value'])
|
| 173 |
+
st.table(info_df)
|
| 174 |
+
|
| 175 |
+
# Fetch News via DuckDuckGo
|
| 176 |
+
real_time_news = get_duckduckgo_news(stock_symbol)
|
| 177 |
+
|
| 178 |
+
# Display News
|
| 179 |
+
st.subheader("π° Latest News")
|
| 180 |
+
for news in real_time_news:
|
| 181 |
+
st.markdown(f"**{news['title']}**")
|
| 182 |
+
st.markdown(f"*Source: {news['publisher']}*")
|
| 183 |
+
st.markdown(f"[Read more]({news['link']})")
|
| 184 |
+
st.markdown("---")
|
| 185 |
+
|
| 186 |
+
# Generate AI Analysis
|
| 187 |
+
ai_analysis = generate_ai_analysis(stock_info, real_time_news, query_type)
|
| 188 |
+
|
| 189 |
+
# Display AI Analysis
|
| 190 |
+
st.subheader("π€ AI-Powered Insights")
|
| 191 |
+
st.write(ai_analysis)
|
| 192 |
+
|
| 193 |
+
except Exception as e:
|
| 194 |
+
st.error(f"An error occurred: {e}")
|
| 195 |
|
| 196 |
# Disclaimer
|
| 197 |
+
st.markdown("<div style='text-align: center; margin-top: 20px;'>", unsafe_allow_html=True)
|
| 198 |
+
st.warning(
|
| 199 |
"π¨ Disclaimer: This is an AI-generated analysis. "
|
| 200 |
"Always consult with a financial advisor before making investment decisions."
|
| 201 |
)
|
| 202 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
| 203 |
|
| 204 |
# Run the Streamlit app
|
| 205 |
if __name__ == "__main__":
|