Ashkchamp commited on
Commit
78aa669
·
verified ·
1 Parent(s): 01b2f3e

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +138 -0
  2. requirements.txt +13 -0
app.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import pandas as pd
4
+ import yfinance as yf
5
+ import matplotlib.pyplot as plt
6
+ from agno.agent import Agent
7
+ from agno.models.groq import Groq
8
+ from agno.tools.yfinance import YFinanceTools
9
+ from agno.tools.duckduckgo import DuckDuckGoTools
10
+ import base64
11
+ import groq
12
+ from functools import wraps
13
+ # UI enhancement
14
+ def add_bg_from_local(image_path):
15
+ with open(image_path, "rb") as image_file:
16
+ encoded_string = base64.b64encode(image_file.read()).decode()
17
+
18
+ return f"""
19
+ <style>
20
+ .stApp {{
21
+ background-image: url("data:image/png;base64,{encoded_string}");
22
+ background-size: cover;
23
+ background-position: center;
24
+ background-repeat: no-repeat;
25
+ background-attachment: fixed;
26
+ }}
27
+ </style>
28
+ """
29
+
30
+ def apply_custom_style():
31
+ # Add the background image
32
+ image_path = "/Users/aditya/Desktop/finance_agent/23115991-fffc-4f67-a116-581a1a9046c8.png"
33
+ st.markdown(add_bg_from_local(image_path), unsafe_allow_html=True)
34
+
35
+ # Add the rest of the custom styling
36
+ st.markdown("""
37
+ <style>
38
+ .main .block-container {
39
+ padding-top: 2rem;
40
+ max-width: 1000px;
41
+ background-color: rgba(255, 255, 255, 0.85);
42
+ border-radius: 10px;
43
+ padding: 20px;
44
+ }
45
+ h1 {
46
+ color: #2E4057;
47
+ text-align: center;
48
+ margin-bottom: 2rem;
49
+ padding-bottom: 1rem;
50
+ border-bottom: 2px solid #E3B448;
51
+ }
52
+ .stButton > button {
53
+ border-radius: 10px;
54
+ background-color: #2E4057;
55
+ color: white;
56
+ font-weight: 600;
57
+ width: 100%;
58
+ }
59
+ .stTextInput > div > div > input {
60
+ border-radius: 10px;
61
+ }
62
+ .stExpander {
63
+ background-color: #f8f9fa;
64
+ border-radius: 10px;
65
+ padding: 0.75rem;
66
+ margin-bottom: 1rem;
67
+ }
68
+ .stChart {
69
+ background-color: #f8f9fa;
70
+ border-radius: 10px;
71
+ padding: 1rem;
72
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
73
+ }
74
+ div[data-testid="stVerticalBlock"] div[style*="flex-direction: column;"] {
75
+ gap: 1rem;
76
+ }
77
+ </style>
78
+ """, unsafe_allow_html=True)
79
+ apply_custom_style()
80
+ from dotenv import load_dotenv
81
+ import time
82
+
83
+
84
+ # Apply the custom styling
85
+ apply_custom_style()
86
+
87
+ # Load environment variables first
88
+ load_dotenv()
89
+
90
+
91
+ # Set API key explicitly
92
+ groq.api_key = os.getenv("GROQ_API_KEY")
93
+
94
+ # Import agent modules after setting API key
95
+ from agents.finance_agent import FinanceAgent
96
+ from pathlib import Path
97
+
98
+ # Initialize only the finance agent first
99
+ finance_agent = FinanceAgent()
100
+
101
+ # Streamlit app title
102
+ st.title("Finance Agent App")
103
+
104
+ # User input for stock ticker
105
+ ticker_symbol = st.text_input("Enter Stock Ticker Symbol (e.g., TSLA):", "TSLA")
106
+
107
+ if st.button("Get Financial Insights"):
108
+ if ticker_symbol:
109
+ try:
110
+ # First display a comprehensive report
111
+ with st.spinner(f"Generating comprehensive financial report for {ticker_symbol}..."):
112
+ st.subheader(f"📊 Comprehensive Financial Report for {ticker_symbol}")
113
+ comprehensive_report = finance_agent.generate_comprehensive_report(ticker_symbol)
114
+ st.markdown(comprehensive_report.content)
115
+
116
+ # Then show historical price chart
117
+ with st.spinner(f"Retrieving historical price data for {ticker_symbol}..."):
118
+ st.subheader(f"📈 Historical Stock Price Data for {ticker_symbol}")
119
+ historical_data = finance_agent.get_historical_price_data(ticker_symbol)
120
+ st.line_chart(historical_data['Close'])
121
+
122
+ # Add a divider
123
+ st.markdown("---")
124
+
125
+ # Include expand sections for detailed information
126
+ with st.expander(f"Detailed Stock Fundamentals for {ticker_symbol}"):
127
+ fundamentals_response = finance_agent.get_stock_fundamentals(ticker_symbol)
128
+ st.markdown(fundamentals_response.content)
129
+
130
+ with st.expander(f"Analyst Recommendations for {ticker_symbol}"):
131
+ analyst_response = finance_agent.get_analyst_recommendations_and_news(ticker_symbol)
132
+ st.markdown(analyst_response.content)
133
+
134
+ except Exception as e:
135
+ st.error(f"An error occurred: {str(e)}")
136
+ st.info("Try again or use a different ticker symbol")
137
+ else:
138
+ st.error("Please enter a valid stock ticker symbol.")
requirements.txt ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ yfinance
3
+ transformers
4
+ pandas
5
+ matplotlib
6
+ python-dotenv
7
+ textblob
8
+ rapidfuzz
9
+ scikit-learn
10
+ newspaper4k
11
+ duckduckgo-search
12
+ groq
13
+ agno