Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,23 +7,95 @@ 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 groq
|
|
|
|
| 11 |
from dotenv import load_dotenv
|
| 12 |
import time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# Load environment variables first
|
| 15 |
load_dotenv()
|
| 16 |
|
| 17 |
-
# Check if API key exists and set it manually if needed
|
| 18 |
-
if not os.getenv("GROQ_API_KEY"):
|
| 19 |
-
st.error("GROQ_API_KEY not found in environment variables. Please add it to your .env file.")
|
| 20 |
-
st.stop()
|
| 21 |
|
| 22 |
# Set API key explicitly
|
| 23 |
groq.api_key = os.getenv("GROQ_API_KEY")
|
| 24 |
|
| 25 |
# Import agent modules after setting API key
|
| 26 |
-
|
| 27 |
|
| 28 |
# Initialize only the finance agent first
|
| 29 |
finance_agent = FinanceAgent()
|
|
|
|
| 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 |
from dotenv import load_dotenv
|
| 14 |
import time
|
| 15 |
+
from finance_agent import FinanceAgent
|
| 16 |
+
from pathlib import Path
|
| 17 |
+
# UI enhancement
|
| 18 |
+
def add_bg_from_local(image_path):
|
| 19 |
+
with open(image_path, "rb") as image_file:
|
| 20 |
+
encoded_string = base64.b64encode(image_file.read()).decode()
|
| 21 |
+
|
| 22 |
+
return f"""
|
| 23 |
+
<style>
|
| 24 |
+
.stApp {{
|
| 25 |
+
background-image: url("data:image/png;base64,{encoded_string}");
|
| 26 |
+
background-size: cover;
|
| 27 |
+
background-position: center;
|
| 28 |
+
background-repeat: no-repeat;
|
| 29 |
+
background-attachment: fixed;
|
| 30 |
+
}}
|
| 31 |
+
</style>
|
| 32 |
+
"""
|
| 33 |
+
|
| 34 |
+
def apply_custom_style():
|
| 35 |
+
# Add the background image
|
| 36 |
+
image_path = "/Users/aditya/Desktop/finance_agent/23115991-fffc-4f67-a116-581a1a9046c8.png"
|
| 37 |
+
st.markdown(add_bg_from_local(image_path), unsafe_allow_html=True)
|
| 38 |
+
|
| 39 |
+
# Add the rest of the custom styling
|
| 40 |
+
st.markdown("""
|
| 41 |
+
<style>
|
| 42 |
+
.main .block-container {
|
| 43 |
+
padding-top: 2rem;
|
| 44 |
+
max-width: 1000px;
|
| 45 |
+
background-color: rgba(255, 255, 255, 0.85);
|
| 46 |
+
border-radius: 10px;
|
| 47 |
+
padding: 20px;
|
| 48 |
+
}
|
| 49 |
+
h1 {
|
| 50 |
+
color: #2E4057;
|
| 51 |
+
text-align: center;
|
| 52 |
+
margin-bottom: 2rem;
|
| 53 |
+
padding-bottom: 1rem;
|
| 54 |
+
border-bottom: 2px solid #E3B448;
|
| 55 |
+
}
|
| 56 |
+
.stButton > button {
|
| 57 |
+
border-radius: 10px;
|
| 58 |
+
background-color: #2E4057;
|
| 59 |
+
color: white;
|
| 60 |
+
font-weight: 600;
|
| 61 |
+
width: 100%;
|
| 62 |
+
}
|
| 63 |
+
.stTextInput > div > div > input {
|
| 64 |
+
border-radius: 10px;
|
| 65 |
+
}
|
| 66 |
+
.stExpander {
|
| 67 |
+
background-color: #f8f9fa;
|
| 68 |
+
border-radius: 10px;
|
| 69 |
+
padding: 0.75rem;
|
| 70 |
+
margin-bottom: 1rem;
|
| 71 |
+
}
|
| 72 |
+
.stChart {
|
| 73 |
+
background-color: #f8f9fa;
|
| 74 |
+
border-radius: 10px;
|
| 75 |
+
padding: 1rem;
|
| 76 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 77 |
+
}
|
| 78 |
+
div[data-testid="stVerticalBlock"] div[style*="flex-direction: column;"] {
|
| 79 |
+
gap: 1rem;
|
| 80 |
+
}
|
| 81 |
+
</style>
|
| 82 |
+
""", unsafe_allow_html=True)
|
| 83 |
+
apply_custom_style()
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
# Apply the custom styling
|
| 88 |
+
apply_custom_style()
|
| 89 |
|
| 90 |
# Load environment variables first
|
| 91 |
load_dotenv()
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
|
| 94 |
# Set API key explicitly
|
| 95 |
groq.api_key = os.getenv("GROQ_API_KEY")
|
| 96 |
|
| 97 |
# Import agent modules after setting API key
|
| 98 |
+
|
| 99 |
|
| 100 |
# Initialize only the finance agent first
|
| 101 |
finance_agent = FinanceAgent()
|