Spaces:
Running
Running
File size: 3,659 Bytes
23f2703 7bf11dd 23f2703 7bf11dd 23f2703 7bf11dd 23f2703 7bf11dd 23f2703 7bf11dd 23f2703 7bf11dd 23f2703 7bf11dd 23f2703 7bf11dd |
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 |
import streamlit as st
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
import yfinance as yf
# Define agents for both functionalities
search_agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())
blog_agent = CodeAgent(tools=[], model=HfApiModel()) # Replace with blog-specific tools/models if needed
# Function to log agent actions
def log_agent_action(prompt, result, agent_name):
st.write(f"### Agent Activity ({agent_name}):")
st.write("**Prompt Sent to Agent:**")
st.code(prompt, language="text")
st.write("**Agent Output:**")
st.code(result, language="text")
# Function to retrieve stock data using yfinance
def get_stock_info(symbol):
try:
stock = yf.Ticker(symbol)
info = stock.info
return {
"Symbol": info.get("symbol", "N/A"),
"Name": info.get("shortName", "N/A"),
"Current Price": info.get("regularMarketPrice", "N/A"),
"Currency": info.get("currency", "N/A"),
"Previous Close": info.get("regularMarketPreviousClose", "N/A"),
"Market Cap": info.get("marketCap", "N/A"),
}
except Exception as e:
return {"Error": f"Could not retrieve stock information: {e}"}
# Streamlit app title
st.title("AI Agent Hub: Blog Writing & Stock Data Retrieval")
# Main navigation options
st.sidebar.header("Select a Feature")
selected_feature = st.sidebar.radio(
"What would you like to do?",
("Blog Writing Agent", "Stock Data Helper")
)
# Prompt input and execution logic
if selected_feature == "Blog Writing Agent":
st.header("Blog Writing Agent")
blog_prompt = st.text_area("Enter your blog topic or prompt:")
if st.button("Generate Blog Content"):
if blog_prompt:
with st.spinner("Generating blog content..."):
try:
# Run the blog agent
blog_result = blog_agent.run(blog_prompt)
# Display result and log backend activity
st.write("Generated Blog Content:")
st.write(blog_result)
log_agent_action(blog_prompt, blog_result, "Blog Writing Agent")
except Exception as e:
st.error(f"An error occurred: {e}")
else:
st.warning("Please enter a blog prompt to continue.")
elif selected_feature == "Stock Data Helper":
st.header("Stock Data Helper")
stock_prompt = st.text_area("Enter your query (e.g., company name, stock symbol):")
use_yfinance = st.checkbox("Fetch additional data using yfinance (e.g., AAPL for Apple)")
if st.button("Retrieve Stock Data"):
if stock_prompt:
with st.spinner("Retrieving stock data..."):
try:
# Run the search agent for stock data
stock_result = search_agent.run(stock_prompt)
st.write("Stock Data Result from Agent:")
st.write(stock_result)
log_agent_action(stock_prompt, stock_result, "Stock Data Helper")
# Fetch additional data using yfinance
if use_yfinance:
stock_info = get_stock_info(stock_prompt)
st.write("Additional Stock Information (yfinance):")
st.json(stock_info)
except Exception as e:
st.error(f"An error occurred: {e}")
else:
st.warning("Please enter a stock-related query to continue.")
# Footer
st.markdown("---")
st.caption("Powered by SmolAgents, Streamlit, and yfinance")
|