Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
import streamlit as st
|
2 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
3 |
-
import yfinance as yf
|
4 |
|
5 |
-
# Define
|
6 |
-
|
7 |
-
|
|
|
|
|
8 |
|
9 |
# Function to log agent actions
|
10 |
def log_agent_action(prompt, result, agent_name):
|
@@ -14,78 +15,33 @@ def log_agent_action(prompt, result, agent_name):
|
|
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
|
35 |
-
|
36 |
-
#
|
37 |
-
st.
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
if
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
st.error(f"An error occurred: {e}")
|
60 |
-
else:
|
61 |
-
st.warning("Please enter a blog prompt to continue.")
|
62 |
-
|
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:
|
87 |
-
st.warning("Please enter a stock-related query to continue.")
|
88 |
|
89 |
# Footer
|
90 |
st.markdown("---")
|
91 |
-
st.caption("Powered by SmolAgents,
|
|
|
1 |
import streamlit as st
|
2 |
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
|
|
|
3 |
|
4 |
+
# Define the blog-writing agent with DuckDuckGo tool
|
5 |
+
blog_agent = CodeAgent(
|
6 |
+
tools=[DuckDuckGoSearchTool()],
|
7 |
+
model=HfApiModel()
|
8 |
+
)
|
9 |
|
10 |
# Function to log agent actions
|
11 |
def log_agent_action(prompt, result, agent_name):
|
|
|
15 |
st.write("**Agent Output:**")
|
16 |
st.code(result, language="text")
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Streamlit app title
|
19 |
+
st.title("AI Blog Writing Agent with Real-Time Insights")
|
20 |
+
|
21 |
+
# App description
|
22 |
+
st.write("Generate creative blogs enriched with real-time insights using the AI Blog Writing Agent powered by SmolAgents and DuckDuckGo.")
|
23 |
+
|
24 |
+
# Input blog topic or prompt
|
25 |
+
blog_prompt = st.text_area("Enter your blog topic or prompt:", placeholder="E.g., The Future of AI in Healthcare")
|
26 |
+
|
27 |
+
# Button to generate blog content
|
28 |
+
if st.button("Generate Blog Content"):
|
29 |
+
if blog_prompt:
|
30 |
+
with st.spinner("Generating blog content with real-time insights..."):
|
31 |
+
try:
|
32 |
+
# Run the blog agent with the given prompt
|
33 |
+
blog_result = blog_agent.run(blog_prompt)
|
34 |
+
# Display the generated blog content
|
35 |
+
st.subheader("Generated Blog Content:")
|
36 |
+
st.write(blog_result)
|
37 |
+
|
38 |
+
# Log backend activity
|
39 |
+
log_agent_action(blog_prompt, blog_result, "Blog Writing Agent with DuckDuckGo")
|
40 |
+
except Exception as e:
|
41 |
+
st.error(f"An error occurred: {e}")
|
42 |
+
else:
|
43 |
+
st.warning("Please enter a blog topic or prompt to proceed.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
# Footer
|
46 |
st.markdown("---")
|
47 |
+
st.caption("Powered by SmolAgents, DuckDuckGo, and Streamlit")
|