Spaces:
Build error
Build error
| import streamlit as st | |
| from phi.agent import Agent | |
| from phi.model.groq import Groq | |
| from phi.tools.duckduckgo import DuckDuckGo | |
| from phi.tools.yfinance import YFinanceTools | |
| import os | |
| # Streamlit App Configuration | |
| st.set_page_config( | |
| page_title="Financial Analysis AI Agent", | |
| page_icon="💹", | |
| layout="wide" | |
| ) | |
| # Web Search Agent | |
| def create_web_search_agent(): | |
| return Agent( | |
| name="Web Search Agent", | |
| role="Search the web for information", | |
| model=Groq(id="llama-3.2-3b-preview"), | |
| tools=[DuckDuckGo()], | |
| instructions=["Always include sources"], | |
| show_tools_call=True, | |
| markdown=True, | |
| ) | |
| # Financial Agent | |
| def create_financial_agent(): | |
| return Agent( | |
| name="Finance AI Agent", | |
| role="Analyze financial data and provide insights", | |
| model=Groq(id="llama-3.2-3b-preview"), | |
| tools=[ | |
| YFinanceTools( | |
| stock_price=True, | |
| analyst_recommendations=True, | |
| stock_fundamentals=True, | |
| company_news=True | |
| ) | |
| ], | |
| instructions=["Use tables to display the data"], | |
| show_tools_call=True, | |
| markdown=True, | |
| ) | |
| # Create Multi-Agent | |
| multi_ai_agent = Agent( | |
| team=[create_web_search_agent(), create_financial_agent()], | |
| instructions=[ | |
| "Always include sources", | |
| "Use tables to display the data" | |
| ], | |
| show_tools_call=True, | |
| markdown=True, | |
| ) | |
| # Streamlit App | |
| def main(): | |
| st.title("🤖 Financial Analysis AI Agent") | |
| st.write("Get comprehensive financial insights using AI-powered web search and analysis!") | |
| # Sidebar for configuration | |
| st.sidebar.header("🔧 Query Configuration") | |
| # Stock Symbol Input | |
| stock_symbol = st.sidebar.text_input( | |
| "Enter Stock Symbol", | |
| value="NVDA", | |
| help="Enter a valid stock ticker symbol" | |
| ) | |
| # Query Type Selection | |
| query_type = st.sidebar.selectbox( | |
| "Select Analysis Type", | |
| [ | |
| "Analyst Recommendations", | |
| "Latest Company News", | |
| "Stock Fundamentals", | |
| "Comprehensive Financial Overview" | |
| ] | |
| ) | |
| # Generate Query | |
| if query_type == "Analyst Recommendations": | |
| query = f"Summarize analyst recommendations for {stock_symbol}" | |
| elif query_type == "Latest Company News": | |
| query = f"Provide the latest news for {stock_symbol}" | |
| elif query_type == "Stock Fundamentals": | |
| query = f"Analyze stock fundamentals for {stock_symbol}" | |
| else: | |
| query = f"Provide a comprehensive financial overview for {stock_symbol}" | |
| # Submit Button | |
| if st.sidebar.button("Generate Analysis"): | |
| with st.spinner("Analyzing financial data..."): | |
| # Capture the response | |
| response_container = st.container() | |
| with response_container: | |
| try: | |
| # Stream the response | |
| full_response = "" | |
| response_placeholder = st.empty() | |
| for chunk in multi_ai_agent.respond(query, stream=True): | |
| full_response += chunk | |
| response_placeholder.markdown(full_response) | |
| # Final display | |
| st.success("Analysis Complete!") | |
| except Exception as e: | |
| st.error(f"An error occurred: {e}") | |
| # Footer | |
| st.sidebar.markdown("---") | |
| st.sidebar.info( | |
| "💡 Tip: Use this tool to get quick financial insights. " | |
| "Always verify important financial decisions independently." | |
| ) | |
| # Run the Streamlit app | |
| if __name__ == "__main__": | |
| main() |