Spaces:
Sleeping
Sleeping
| #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") | |
| openrouter_api_key = st.text_input("Open Router 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 | |
| os.environ['OPENROUTER_API_KEY'] = openrouter_api_key | |
| 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() |