Spaces:
Sleeping
Sleeping
#gui/app.py | |
import sys | |
import streamlit as st | |
from src.research_agent.crew import MarketUseCaseCrew | |
import streamlit as st | |
from crewai import Crew, Process | |
import os | |
sys.path.append('..') | |
# Configure the Streamlit page | |
st.set_page_config(page_title="CrewAI Article Generator", page_icon="π", layout="wide") | |
# Custom CSS for styling the page | |
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) | |
# Sidebar for API key input | |
st.sidebar.title("π API Configuration") | |
st.sidebar.markdown("Enter your API keys below:") | |
# Input fields for API keys | |
serper_api_key = st.sidebar.text_input("Serper API Key", type="password") | |
gemini_api_key = st.sidebar.text_input("Gemini Flash API Key", type="password") | |
# Button to save API keys | |
if st.sidebar.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.sidebar.success("API keys saved successfully!") | |
else: | |
st.sidebar.error("Please enter both API keys.") | |
# Main content section | |
st.title("π Market and Research Analysis ") | |
st.markdown("This is an Agent which can do Market Analysis and Generate Use Cases in the AI space for you") | |
# Input fields for company name and website | |
name = st.text_input("Enter Name of the company:", placeholder="e.g., Google, Apple, Nike") | |
link = st.text_input("Enter the company's link:", placeholder="e.g., https://www.google.com, https://www.apple.com, https://www.nike.com") | |
# Button to generate article | |
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) | |
# Input data for the article generation | |
inputs = { | |
'company': name, | |
'company_link': link | |
} | |
# Use the MarketUseCaseCrew class to generate the article | |
with st.spinner(f"Researching and generating uses cases about AI for '{name}'..."): | |
# Set progress to 50% | |
progress_bar.progress(50) | |
# Call the kickoff method to generate the article | |
result = MarketUseCaseCrew().crew().kickoff(inputs=inputs) | |
# Set progress to 100% | |
progress_bar.progress(100) | |
# Display the generated article | |
st.subheader("Generated Article:") | |
# Extract the article text from the result | |
if isinstance(result, str): | |
article_text = result | |
elif isinstance(result, dict) and 'article' in result: | |
article_text = result['article'] | |
else: | |
article_text = str(result) | |
# Display the article text | |
st.markdown(article_text) | |
# Create three columns for download buttons | |
col1, col2, col3 = st.columns(3) | |
# Download button for the article | |
with col1: | |
st.download_button( | |
label="Download Article", | |
data=article_text, | |
file_name=f"{name.replace(' ', '_').lower()}_market_and_use_case_analysis.txt", | |
mime="text/plain" | |
) | |
# Download button for ideas | |
with col2: | |
with open("output/ideas.md", "rb") as fp: | |
st.download_button( | |
label="Download Ideas", | |
data=fp, | |
file_name=f"{name.replace(' ', '_').lower()}_ideas.txt", | |
mime="text/plain" | |
) | |
# Download button for resources | |
with col3: | |
with open("output/resouce.md", "rb") as fp: | |
st.download_button( | |
label="Download Ideas", | |
data=fp, | |
file_name=f"{name.replace(' ', '_').lower()}_ideas.txt", | |
mime="image/txt" | |
) | |
st.markdown("---------") | |