BLJohnPrabhasith commited on
Commit
6fd87f5
Β·
verified Β·
1 Parent(s): d3b6ca9

Update app.py

Browse files

Installed both serper and groq api keys in to the .env file

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