Akshayram1 commited on
Commit
7bf11dd
·
verified ·
1 Parent(s): 23f2703

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -3
app.py CHANGED
@@ -1,10 +1,35 @@
1
  import streamlit as st
2
  from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
 
3
 
4
  # Define agents for both functionalities
5
  search_agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())
6
  blog_agent = CodeAgent(tools=[], model=HfApiModel()) # Replace with blog-specific tools/models if needed
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  # Streamlit app title
9
  st.title("AI Agent Hub: Blog Writing & Stock Data Retrieval")
10
 
@@ -26,8 +51,10 @@ if selected_feature == "Blog Writing Agent":
26
  try:
27
  # Run the blog agent
28
  blog_result = blog_agent.run(blog_prompt)
 
29
  st.write("Generated Blog Content:")
30
  st.write(blog_result)
 
31
  except Exception as e:
32
  st.error(f"An error occurred: {e}")
33
  else:
@@ -36,15 +63,24 @@ if selected_feature == "Blog Writing Agent":
36
  elif selected_feature == "Stock Data Helper":
37
  st.header("Stock Data Helper")
38
  stock_prompt = st.text_area("Enter your query (e.g., company name, stock symbol):")
39
-
 
40
  if st.button("Retrieve Stock Data"):
41
  if stock_prompt:
42
  with st.spinner("Retrieving stock data..."):
43
  try:
44
  # Run the search agent for stock data
45
  stock_result = search_agent.run(stock_prompt)
46
- st.write("Stock Data Result:")
47
  st.write(stock_result)
 
 
 
 
 
 
 
 
48
  except Exception as e:
49
  st.error(f"An error occurred: {e}")
50
  else:
@@ -52,4 +88,4 @@ elif selected_feature == "Stock Data Helper":
52
 
53
  # Footer
54
  st.markdown("---")
55
- st.caption("Powered by SmolAgents and Streamlit")
 
1
  import streamlit as st
2
  from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
3
+ import yfinance as yf
4
 
5
  # Define agents for both functionalities
6
  search_agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())
7
  blog_agent = CodeAgent(tools=[], model=HfApiModel()) # Replace with blog-specific tools/models if needed
8
 
9
+ # Function to log agent actions
10
+ def log_agent_action(prompt, result, agent_name):
11
+ st.write(f"### Agent Activity ({agent_name}):")
12
+ st.write("**Prompt Sent to Agent:**")
13
+ st.code(prompt, language="text")
14
+ st.write("**Agent Output:**")
15
+ st.code(result, language="text")
16
+
17
+ # Function to retrieve stock data using yfinance
18
+ def get_stock_info(symbol):
19
+ try:
20
+ stock = yf.Ticker(symbol)
21
+ info = stock.info
22
+ return {
23
+ "Symbol": info.get("symbol", "N/A"),
24
+ "Name": info.get("shortName", "N/A"),
25
+ "Current Price": info.get("regularMarketPrice", "N/A"),
26
+ "Currency": info.get("currency", "N/A"),
27
+ "Previous Close": info.get("regularMarketPreviousClose", "N/A"),
28
+ "Market Cap": info.get("marketCap", "N/A"),
29
+ }
30
+ except Exception as e:
31
+ return {"Error": f"Could not retrieve stock information: {e}"}
32
+
33
  # Streamlit app title
34
  st.title("AI Agent Hub: Blog Writing & Stock Data Retrieval")
35
 
 
51
  try:
52
  # Run the blog agent
53
  blog_result = blog_agent.run(blog_prompt)
54
+ # Display result and log backend activity
55
  st.write("Generated Blog Content:")
56
  st.write(blog_result)
57
+ log_agent_action(blog_prompt, blog_result, "Blog Writing Agent")
58
  except Exception as e:
59
  st.error(f"An error occurred: {e}")
60
  else:
 
63
  elif selected_feature == "Stock Data Helper":
64
  st.header("Stock Data Helper")
65
  stock_prompt = st.text_area("Enter your query (e.g., company name, stock symbol):")
66
+ use_yfinance = st.checkbox("Fetch additional data using yfinance (e.g., AAPL for Apple)")
67
+
68
  if st.button("Retrieve Stock Data"):
69
  if stock_prompt:
70
  with st.spinner("Retrieving stock data..."):
71
  try:
72
  # Run the search agent for stock data
73
  stock_result = search_agent.run(stock_prompt)
74
+ st.write("Stock Data Result from Agent:")
75
  st.write(stock_result)
76
+ log_agent_action(stock_prompt, stock_result, "Stock Data Helper")
77
+
78
+ # Fetch additional data using yfinance
79
+ if use_yfinance:
80
+ stock_info = get_stock_info(stock_prompt)
81
+ st.write("Additional Stock Information (yfinance):")
82
+ st.json(stock_info)
83
+
84
  except Exception as e:
85
  st.error(f"An error occurred: {e}")
86
  else:
 
88
 
89
  # Footer
90
  st.markdown("---")
91
+ st.caption("Powered by SmolAgents, Streamlit, and yfinance")