dev2607 commited on
Commit
c317182
·
verified ·
1 Parent(s): 786031a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +121 -0
app.py ADDED
@@ -0,0 +1,121 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from phi.agent import Agent
3
+ from phi.model.groq import Groq
4
+ from phi.tools.duckduckgo import DuckDuckGo
5
+ from phi.tools.yfinance import YFinanceTools
6
+ import os
7
+
8
+ # Streamlit App Configuration
9
+ st.set_page_config(
10
+ page_title="Financial Analysis AI Agent",
11
+ page_icon="💹",
12
+ layout="wide"
13
+ )
14
+
15
+ # Web Search Agent
16
+ def create_web_search_agent():
17
+ return Agent(
18
+ name="Web Search Agent",
19
+ role="Search the web for information",
20
+ model=Groq(id="llama-3.2-3b-preview"),
21
+ tools=[DuckDuckGo()],
22
+ instructions=["Always include sources"],
23
+ show_tools_call=True,
24
+ markdown=True,
25
+ )
26
+
27
+ # Financial Agent
28
+ def create_financial_agent():
29
+ return Agent(
30
+ name="Finance AI Agent",
31
+ role="Analyze financial data and provide insights",
32
+ model=Groq(id="llama-3.2-3b-preview"),
33
+ tools=[
34
+ YFinanceTools(
35
+ stock_price=True,
36
+ analyst_recommendations=True,
37
+ stock_fundamentals=True,
38
+ company_news=True
39
+ )
40
+ ],
41
+ instructions=["Use tables to display the data"],
42
+ show_tools_call=True,
43
+ markdown=True,
44
+ )
45
+
46
+ # Create Multi-Agent
47
+ multi_ai_agent = Agent(
48
+ team=[create_web_search_agent(), create_financial_agent()],
49
+ instructions=[
50
+ "Always include sources",
51
+ "Use tables to display the data"
52
+ ],
53
+ show_tools_call=True,
54
+ markdown=True,
55
+ )
56
+
57
+ # Streamlit App
58
+ def main():
59
+ st.title("🤖 Financial Analysis AI Agent")
60
+ st.write("Get comprehensive financial insights using AI-powered web search and analysis!")
61
+
62
+ # Sidebar for configuration
63
+ st.sidebar.header("🔧 Query Configuration")
64
+
65
+ # Stock Symbol Input
66
+ stock_symbol = st.sidebar.text_input(
67
+ "Enter Stock Symbol",
68
+ value="NVDA",
69
+ help="Enter a valid stock ticker symbol"
70
+ )
71
+
72
+ # Query Type Selection
73
+ query_type = st.sidebar.selectbox(
74
+ "Select Analysis Type",
75
+ [
76
+ "Analyst Recommendations",
77
+ "Latest Company News",
78
+ "Stock Fundamentals",
79
+ "Comprehensive Financial Overview"
80
+ ]
81
+ )
82
+
83
+ # Generate Query
84
+ if query_type == "Analyst Recommendations":
85
+ query = f"Summarize analyst recommendations for {stock_symbol}"
86
+ elif query_type == "Latest Company News":
87
+ query = f"Provide the latest news for {stock_symbol}"
88
+ elif query_type == "Stock Fundamentals":
89
+ query = f"Analyze stock fundamentals for {stock_symbol}"
90
+ else:
91
+ query = f"Provide a comprehensive financial overview for {stock_symbol}"
92
+
93
+ # Submit Button
94
+ if st.sidebar.button("Generate Analysis"):
95
+ with st.spinner("Analyzing financial data..."):
96
+ # Capture the response
97
+ response_container = st.container()
98
+ with response_container:
99
+ try:
100
+ # Stream the response
101
+ full_response = ""
102
+ response_placeholder = st.empty()
103
+ for chunk in multi_ai_agent.respond(query, stream=True):
104
+ full_response += chunk
105
+ response_placeholder.markdown(full_response)
106
+
107
+ # Final display
108
+ st.success("Analysis Complete!")
109
+ except Exception as e:
110
+ st.error(f"An error occurred: {e}")
111
+
112
+ # Footer
113
+ st.sidebar.markdown("---")
114
+ st.sidebar.info(
115
+ "💡 Tip: Use this tool to get quick financial insights. "
116
+ "Always verify important financial decisions independently."
117
+ )
118
+
119
+ # Run the Streamlit app
120
+ if __name__ == "__main__":
121
+ main()