File size: 6,963 Bytes
67c90cc
 
99c3854
8783478
99c3854
 
1cc5a1d
 
67c90cc
99c3854
 
 
1cc5a1d
99c3854
1cc5a1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f328415
1cc5a1d
f328415
 
 
 
 
 
 
 
 
 
 
1cc5a1d
 
 
 
99c3854
1cc5a1d
 
 
 
 
f328415
1cc5a1d
 
 
 
 
e954dc8
1cc5a1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3e23d4a
1cc5a1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99c3854
1cc5a1d
 
 
99c3854
1cc5a1d
 
 
 
 
 
 
 
 
 
e954dc8
1cc5a1d
 
 
99c3854
1cc5a1d
 
 
 
 
 
 
 
 
 
 
99c3854
1cc5a1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99c3854
1cc5a1d
 
e954dc8
1cc5a1d
 
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
#gui/app.py
import sys
import streamlit as st
from src.research_agent.crew import MarketUseCaseCrew
import streamlit as st
import os
from dotenv import load_dotenv
load_dotenv()
sys.path.append('..')



class MarketUseCaseGen:

    def generation(self, name, link):
        inputs = {"company": name, "company_link": link}
        return MarketUseCaseCrew().crew().kickoff(inputs=inputs)
    
    def use_case_generation(self):
        if st.session_state.generation:
            with st.spinner(f"Researching and generating uses cases about AI..."):
            # Set progress to 50%
                progress_bar = st.progress(50)
                st.session_state.article_text = self.generation(
                    st.session_state.name, st.session_state.link
                )
                progress_bar.progress(100)
                # Display the generated article
                st.subheader("Generated Article:")
                
        if st.session_state.article_text and st.session_state.article_text != "":

            # Convert the article text to a string if it's not already
            if isinstance(st.session_state.article_text, str):
                article_text = st.session_state.article_text
            
            elif isinstance(st.session_state.article_text, dict) and 'article' in st.session_state.article_text:
                article_text = st.session_state.article_text['article']
            
            else:
                article_text = str(st.session_state.article_text) 
            
            with st.container():
            # Display the article text
                st.markdown(st.session_state.article_text)
                col1, col2, col3 = st.columns(3)

                # Download button for the article
                with col1:
                    if st.session_state.article_text:
                        st.download_button(
                            label="Download Article",
                            data=article_text,
                            file_name=f"{st.session_state.name.replace(' ', '_').lower()}_market_and_use_case_analysis.txt",
                            mime="text/plain"
                        )
                    else:
                        st.write("Article not generated yet.")

                # Download button for ideas
                with col2:
                    if st.session_state.article_text:
                        with open("output/ideas.md", "rb") as fp:
                            st.download_button(
                                label="Download Ideas",
                                data=fp,
                                file_name=f"{st.session_state.name.replace(' ', '_').lower()}_ideas.txt",
                                mime="text/plain"
                            )
                    else:
                        st.wrtie("Ideas are ideating")
                # Download button for resources
                with col3:
                    if st.session_state.article_text: 
                        with open("output/researched_data.md", "rb") as fp:
                            st.download_button(
                                label="Download Resources",
                                data=fp,
                                file_name=f"{st.session_state.name.replace(' ', '_').lower()}_resources.txt",
                                mime="text/plain"
                            )
                    else:
                        st.write("Resources are being researched")
                st.markdown("---------")
            st.session_state.generation=False
    
    def sidebar(self):
        with st.sidebar:
            st.title("πŸ“Š API Configuration")
            st.markdown("Enter your API keys below:")

            # Input fields for API keys
            serper_api_key = st.text_input("Serper API Key", type="password")
            gemini_api_key = st.text_input("Gemini Flash API Key", type="password")

            # Button to save API keys
            if st.button("Save API Keys"):
                # Check if both API keys are provided
                if serper_api_key and gemini_api_key:
                    # Set environment variables for API keys
                    os.environ['SERPER_API_KEY'] = serper_api_key # Installed the SERPER_API_KEY in the environment
                    os.environ['GOOGLE_API_KEY'] = gemini_api_key # Installed the gemini_api_key in the environment
                    st.success("API keys saved successfully!")
                else:
                    st.error("Please enter both API keys.")

            # Input fields for company name and website
            name = st.text_input("Enter Name of the company:", key='name',placeholder="e.g., Google, Apple, Nike")
            link = st.text_input("Enter the company's link:", key='link',placeholder="e.g., https://www.google.com, https://www.apple.com, https://www.nike.com")

            if st.button("Generate Article"):
                # Check if API keys are provided
                if not serper_api_key or not gemini_api_key:
                    st.error("Please enter both API keys in the sidebar before generating.")
                     # Check if company name and website are provided
                elif not name and link:
                    st.warning("Please enter the company name and website")
                else:
                    # Create a progress bar
                    progress_bar = st.progress(0)
                    st.session_state.generation=True

    def render(self):
        st.set_page_config(page_title="CrewAI Article Generator", page_icon="πŸ“", layout="wide")
        # Main content section
        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)
        if "article_text" not in st.session_state:
            st.session_state.article_text = ""
        if "generation" not in st.session_state:
            st.session_state.generation = False
        if "name" not in st.session_state:
            st.session_state.website = ""
        if "link" not in st.session_state:
            st.session_state.link = ""

        self.sidebar()
        self.use_case_generation()

if __name__ == "__main__":
    MarketUseCaseGen().render()