-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathapp.py
More file actions
164 lines (142 loc) · 4.4 KB
/
app.py
File metadata and controls
164 lines (142 loc) · 4.4 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import streamlit as st
import random
from main import NewsletterGenerator
from agno.storage.sqlite import SqliteStorage
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Set page config
st.set_page_config(
page_title="AI Newsletter Generator",
page_icon="📰",
layout="wide"
)
# Custom CSS
st.markdown("""
<style>
.main {
padding: 2rem;
}
.stButton>button {
width: 100%;
}
.newsletter-content {
background-color: #f8f9fa;
padding: 2rem;
border-radius: 10px;
margin-top: 2rem;
}
.topic-input {
margin-bottom: 2rem;
}
</style>
""", unsafe_allow_html=True)
# Title and description
st.title("📰 AI Newsletter Generator with Firecrawl 🔥")
st.markdown("""
Generate professional newsletters on any topic using Nebius AI, Agno, and Firecrawl.
""")
# Example topics
example_topics = [
"What happened in the world of AI this week?",
"What are the latest trends in AI?",
"Tell the Recent Model Releases",
"Recap of Google I/O 2025",
]
# Sidebar for API keys and settings
with st.sidebar:
st.header("🔑 API Keys")
firecrawl_api_key = st.text_input(
"Firecrawl API Key",
value=os.getenv("FIRECRAWL_API_KEY", ""),
type="password",
help="Get your API key from https://firecrawl.dev"
)
nebius_api_key = st.text_input(
"Nebius API Key",
value=os.getenv("NEBIUS_API_KEY", ""),
type="password",
help="Your Nebius API key"
)
# Update environment variables with user input
if firecrawl_api_key:
os.environ["FIRECRAWL_API_KEY"] = firecrawl_api_key
if nebius_api_key:
os.environ["NEBIUS_API_KEY"] = nebius_api_key
st.markdown("---")
st.markdown("### 📚 Example Topics")
for topic in example_topics:
if st.button(topic, key=topic):
st.session_state.topic = topic
# Main content area
# st.markdown("### 🎯 Enter Your Topic")
topic = st.text_input(
"What would you like to generate a newsletter about?",
value=st.session_state.get("topic", ""),
placeholder="Enter a topic or select from examples",
key="topic_input"
)
col1, col2 = st.columns(2)
with col1:
search_limit = st.number_input(
"Number of Articles",
min_value=1,
max_value=10,
value=5,
help="Maximum number of articles to search and analyze"
)
with col2:
time_range = st.selectbox(
"Time Range",
options=[
("Past hour", "qdr:h"),
("Past 24 hours", "qdr:d"),
("Past week", "qdr:w"),
("Past month", "qdr:m"),
("Past year", "qdr:y")
],
format_func=lambda x: x[0],
index=2, # Default to "Past week"
help="Time range for article search"
)
# Generate button
def generate_newsletter():
if not topic:
st.error("Please enter a topic or select one from the examples.")
return
elif not firecrawl_api_key or not nebius_api_key:
st.error("Please provide both API keys in the sidebar.")
return
with st.spinner("Generating your newsletter..."):
try:
# Convert the topic to a URL-safe string for use in session_id
url_safe_topic = topic.lower().replace(" ", "-")
# Initialize the newsletter generator
# Generate the newsletter using main function
response = NewsletterGenerator(
topic=topic,
search_limit=search_limit,
time_range=time_range[1] # Get the tbs value from the tuple
)
# Display the complete newsletter
st.markdown("### 📝 Generated Newsletter")
st.markdown(response.content)
# Add download button
st.download_button(
label="📥 Download Newsletter",
data=response.content,
file_name=f"newsletter-{url_safe_topic}.md",
mime="text/markdown"
)
except Exception as e:
st.error(f"An error occurred while generating the newsletter: {str(e)}")
# Footer
st.markdown("---")
st.markdown("""
<div style='text-align: center'>
<p>Built with ❤️ using Streamlit and Nebius AI</p>
</div>
""", unsafe_allow_html=True)
if st.button("Generate Newsletter", type="primary"):
generate_newsletter()