Spaces:
Running
Running
File size: 1,749 Bytes
23f2703 c9f0eeb 23f2703 7bf11dd 23f2703 c9f0eeb 23f2703 c9f0eeb |
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 |
import streamlit as st
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel
# Define the blog-writing agent with DuckDuckGo tool
blog_agent = CodeAgent(
tools=[DuckDuckGoSearchTool()],
model=HfApiModel()
)
# 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")
# Streamlit app title
st.title("AI Blog Writing Agent with Real-Time Insights")
# App description
st.write("Generate creative blogs enriched with real-time insights using the AI Blog Writing Agent powered by SmolAgents and DuckDuckGo.")
# Input blog topic or prompt
blog_prompt = st.text_area("Enter your blog topic or prompt:", placeholder="E.g., The Future of AI in Healthcare")
# Button to generate blog content
if st.button("Generate Blog Content"):
if blog_prompt:
with st.spinner("Generating blog content with real-time insights..."):
try:
# Run the blog agent with the given prompt
blog_result = blog_agent.run(blog_prompt)
# Display the generated blog content
st.subheader("Generated Blog Content:")
st.write(blog_result)
# Log backend activity
log_agent_action(blog_prompt, blog_result, "Blog Writing Agent with DuckDuckGo")
except Exception as e:
st.error(f"An error occurred: {e}")
else:
st.warning("Please enter a blog topic or prompt to proceed.")
# Footer
st.markdown("---")
st.caption("Powered by SmolAgents, DuckDuckGo, and Streamlit")
|