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