dev2607 commited on
Commit
bfa896c
Β·
verified Β·
1 Parent(s): 4f9f923

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -53
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="wide"
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
- # Sidebar Configuration
127
- st.sidebar.header("πŸ” Stock Analysis")
128
 
129
- # Stock Symbol Input
130
- stock_symbol = st.sidebar.text_input(
131
- "Enter Stock Symbol",
132
- value="NVDA",
133
- help="Enter a valid stock ticker (e.g., AAPL, GOOGL)"
134
- )
 
135
 
136
- # Analysis Type Selection
137
- query_type = st.sidebar.selectbox(
138
- "Select Analysis Type",
139
- [
140
- "Comprehensive Analysis",
141
- "Analyst Recommendations",
142
- "Latest News Analysis"
143
- ]
144
- )
145
 
146
- # Generate Analysis Button
147
- if st.sidebar.button("Generate Analysis"):
148
- with st.spinner("Fetching and analyzing stock data..."):
149
- try:
150
- # Fetch Stock Information
151
- stock_info = get_stock_info(stock_symbol)
152
-
153
- if stock_info:
154
- # Display Stock Information
155
- st.subheader(f"Financial Snapshot: {stock_symbol}")
156
- info_df = pd.DataFrame.from_dict(stock_info, orient='index', columns=['Value'])
157
- st.table(info_df)
158
-
159
- # Fetch News via DuckDuckGo
160
- real_time_news = get_duckduckgo_news(stock_symbol)
161
-
162
- # Display News
163
- st.subheader("πŸ“° Latest News")
164
- for news in real_time_news:
165
- st.markdown(f"**{news['title']}**")
166
- st.markdown(f"*Source: {news['publisher']}*")
167
- st.markdown(f"[Read more]({news['link']})")
168
- st.markdown("---")
169
-
170
- # Generate AI Analysis
171
- ai_analysis = generate_ai_analysis(stock_info, real_time_news, query_type)
172
-
173
- # Display AI Analysis
174
- st.subheader("πŸ€– AI-Powered Insights")
175
- st.write(ai_analysis)
176
-
177
- except Exception as e:
178
- st.error(f"An error occurred: {e}")
179
 
180
  # Disclaimer
181
- st.sidebar.markdown("---")
182
- st.sidebar.warning(
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__":