Spaces:
Sleeping
Sleeping
File size: 4,770 Bytes
67c90cc 99c3854 8783478 99c3854 67c90cc 99c3854 |
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 |
#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("---------")
|