File size: 3,070 Bytes
6fd87f5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
from crewai import Crew, Process
from pydantic import BaseModel
from agents import News_Researcher, News_Writer
from tasks import Research_task, Write_task
from tools import tool
import os

st.set_page_config(page_title="CrewAI Article Generator", page_icon="πŸ“", layout="wide")

st.markdown("""
<style>
    .reportview-container {
        background: #f0f2f6
    }
    .main {
        background: #00000;
        padding: 3rem;
        border-radius: 10px;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    }
    .stButton>button {
        background-color: #0000;
        color: white;
        border-radius: 5px;
    }
    .stTextInput>div>div>input {
        border-radius: 5px;
    }
    .sidebar .sidebar-content {
        background-color: #f8f9fa;
    }
</style>
""", unsafe_allow_html=True)

st.sidebar.title("πŸ“Š API Configuration")
st.sidebar.markdown("Enter your API keys below:")

serper_api_key = st.sidebar.text_input("Serper API Key", type="password")
groq_api_key = st.sidebar.text_input("Groq API Key", type="password")

if st.sidebar.button("Save API Keys"):
    if serper_api_key and groq_api_key:
        os.environ['SERPER_API_KEY'] = serper_api_key # Installed the SERPER_API_KEY in the environment
        os.environ['GROQ_API_KEY'] = groq_api_key # Installed the GROQ_API_KEY in the environment
        st.sidebar.success("API keys saved successfully!")
    else:
        st.sidebar.error("Please enter both API keys.")

st.title("πŸ“ Culprit ")
st.markdown("This is an Agent which can write articles for your blog on any Topic - Have a Try")

topic = st.text_input("Enter a topic for your article:", placeholder="e.g., Space exploration, Climate change, Artificial intelligence")

if st.button("Generate Article"):
    if not serper_api_key or not groq_api_key:
        st.error("Please enter both API keys in the sidebar before generating an article.")
    elif not topic:
        st.warning("Please enter a topic before generating the article.")
    else:
        progress_bar = st.progress(0)
        crew = Crew(
            agents=[News_Researcher, News_Writer],
            tasks=[Research_task, Write_task],
            process=Process.sequential,
        )

        with st.spinner(f"Researching and writing the article about '{topic}'..."):
            progress_bar.progress(50)
            result = crew.kickoff(inputs={'topic': topic})
        
        progress_bar.progress(100)

        st.subheader("Generated Article:")
        
        if isinstance(result, str):
            article_text = result
        elif isinstance(result, dict) and 'article' in result:
            article_text = result['article']
        else:
            article_text = str(result)  
        
        st.markdown(article_text)

        st.download_button(
            label="Download Article",
            data=article_text,
            file_name=f"{topic.replace(' ', '_').lower()}_article.txt",
            mime="text/plain"
        )

st.markdown("---------")
st.markdown("Created using CrewAI with ❀️ by BLJP ")