Spaces:
Sleeping
Sleeping
Update app.py
Browse filesInstalled both serper and groq api keys in to the .env file
app.py
CHANGED
@@ -1,90 +1,93 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from crewai import Crew, Process
|
3 |
-
from pydantic import BaseModel
|
4 |
-
from agents import News_Researcher, News_Writer
|
5 |
-
from tasks import Research_task, Write_task
|
6 |
-
from tools import tool
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
color:
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
st.sidebar.
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
st.
|
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 |
-
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from crewai import Crew, Process
|
3 |
+
from pydantic import BaseModel
|
4 |
+
from agents import News_Researcher, News_Writer
|
5 |
+
from tasks import Research_task, Write_task
|
6 |
+
from tools import tool
|
7 |
+
import os
|
8 |
+
|
9 |
+
st.set_page_config(page_title="CrewAI Article Generator", page_icon="π", layout="wide")
|
10 |
+
|
11 |
+
st.markdown("""
|
12 |
+
<style>
|
13 |
+
.reportview-container {
|
14 |
+
background: #f0f2f6
|
15 |
+
}
|
16 |
+
.main {
|
17 |
+
background: #00000;
|
18 |
+
padding: 3rem;
|
19 |
+
border-radius: 10px;
|
20 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
21 |
+
}
|
22 |
+
.stButton>button {
|
23 |
+
background-color: #0000;
|
24 |
+
color: white;
|
25 |
+
border-radius: 5px;
|
26 |
+
}
|
27 |
+
.stTextInput>div>div>input {
|
28 |
+
border-radius: 5px;
|
29 |
+
}
|
30 |
+
.sidebar .sidebar-content {
|
31 |
+
background-color: #f8f9fa;
|
32 |
+
}
|
33 |
+
</style>
|
34 |
+
""", unsafe_allow_html=True)
|
35 |
+
|
36 |
+
st.sidebar.title("π API Configuration")
|
37 |
+
st.sidebar.markdown("Enter your API keys below:")
|
38 |
+
|
39 |
+
serper_api_key = st.sidebar.text_input("Serper API Key", type="password")
|
40 |
+
groq_api_key = st.sidebar.text_input("Groq API Key", type="password")
|
41 |
+
|
42 |
+
if st.sidebar.button("Save API Keys"):
|
43 |
+
if serper_api_key and groq_api_key:
|
44 |
+
os.environ['SERPER_API_KEY'] = serper_api_key # Installed the SERPER_API_KEY in the environment
|
45 |
+
os.environ['GROQ_API_KEY'] = groq_api_key # Installed the GROQ_API_KEY in the environment
|
46 |
+
st.sidebar.success("API keys saved successfully!")
|
47 |
+
else:
|
48 |
+
st.sidebar.error("Please enter both API keys.")
|
49 |
+
|
50 |
+
st.title("π Culprit ")
|
51 |
+
st.markdown("This is an Agent which can write articles for your blog on any Topic - Have a Try")
|
52 |
+
|
53 |
+
topic = st.text_input("Enter a topic for your article:", placeholder="e.g., Space exploration, Climate change, Artificial intelligence")
|
54 |
+
|
55 |
+
if st.button("Generate Article"):
|
56 |
+
if not serper_api_key or not groq_api_key:
|
57 |
+
st.error("Please enter both API keys in the sidebar before generating an article.")
|
58 |
+
elif not topic:
|
59 |
+
st.warning("Please enter a topic before generating the article.")
|
60 |
+
else:
|
61 |
+
progress_bar = st.progress(0)
|
62 |
+
crew = Crew(
|
63 |
+
agents=[News_Researcher, News_Writer],
|
64 |
+
tasks=[Research_task, Write_task],
|
65 |
+
process=Process.sequential,
|
66 |
+
)
|
67 |
+
|
68 |
+
with st.spinner(f"Researching and writing the article about '{topic}'..."):
|
69 |
+
progress_bar.progress(50)
|
70 |
+
result = crew.kickoff(inputs={'topic': topic})
|
71 |
+
|
72 |
+
progress_bar.progress(100)
|
73 |
+
|
74 |
+
st.subheader("Generated Article:")
|
75 |
+
|
76 |
+
if isinstance(result, str):
|
77 |
+
article_text = result
|
78 |
+
elif isinstance(result, dict) and 'article' in result:
|
79 |
+
article_text = result['article']
|
80 |
+
else:
|
81 |
+
article_text = str(result)
|
82 |
+
|
83 |
+
st.markdown(article_text)
|
84 |
+
|
85 |
+
st.download_button(
|
86 |
+
label="Download Article",
|
87 |
+
data=article_text,
|
88 |
+
file_name=f"{topic.replace(' ', '_').lower()}_article.txt",
|
89 |
+
mime="text/plain"
|
90 |
+
)
|
91 |
+
|
92 |
+
st.markdown("---------")
|
93 |
+
st.markdown("Created using CrewAI with β€οΈ by BLJP ")
|