-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathstreamlit_app.py
118 lines (101 loc) · 4.09 KB
/
streamlit_app.py
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
# Handle SQLite for ChromaDB
try:
__import__('pysqlite3')
import sys
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
except (ImportError, KeyError):
pass
import streamlit as st
import os
from src.components.sidebar import render_sidebar
from src.components.researcher import create_researcher, create_research_task, run_research
from src.utils.output_handler import capture_output
#--------------------------------#
# Streamlit App #
#--------------------------------#
# Configure the page
st.set_page_config(
page_title="CrewAI Research Assistant",
page_icon="🕵️♂️",
layout="wide",
initial_sidebar_state="expanded"
)
# Logo
st.logo(
"https://cdn.prod.website-files.com/66cf2bfc3ed15b02da0ca770/66d07240057721394308addd_Logo%20(1).svg",
link="https://www.crewai.com/",
size="large"
)
# Main layout
col1, col2, col3 = st.columns([1, 2, 1])
with col2:
st.title("🔍 :red[CrewAI] Research Assistant", anchor=False)
# Render sidebar and get selection (provider and model)
selection = render_sidebar()
# Check if API keys are set based on provider
if selection["provider"] == "OpenAI":
if not os.environ.get("OPENAI_API_KEY"):
st.warning("⚠️ Please enter your OpenAI API key in the sidebar to get started")
st.stop()
elif selection["provider"] == "GROQ":
if not os.environ.get("GROQ_API_KEY"):
st.warning("⚠️ Please enter your GROQ API key in the sidebar to get started")
st.stop()
# Check EXA key for non-Ollama providers
if selection["provider"] != "Ollama":
if not os.environ.get("EXA_API_KEY"):
st.warning("⚠️ Please enter your EXA API key in the sidebar to get started")
st.stop()
# Add Ollama check
if selection["provider"] == "Ollama" and not selection["model"]:
st.warning("⚠️ No Ollama models found. Please make sure Ollama is running and you have models loaded.")
st.stop()
# Create two columns for the input section
input_col1, input_col2, input_col3 = st.columns([1, 3, 1])
with input_col2:
task_description = st.text_area(
"What would you like to research?",
value="Research the latest AI Agent news in February 2025 and summarize each.",
height=68
)
col1, col2, col3 = st.columns([1, 0.5, 1])
with col2:
start_research = st.button("🚀 Start Research", use_container_width=False, type="primary")
if start_research:
with st.status("🤖 Researching...", expanded=True) as status:
try:
# Create persistent container for process output with fixed height.
process_container = st.container(height=300, border=True)
output_container = process_container.container()
# Single output capture context.
with capture_output(output_container):
researcher = create_researcher(selection)
task = create_research_task(researcher, task_description)
result = run_research(researcher, task)
status.update(label="✅ Research completed!", state="complete", expanded=False)
except Exception as e:
status.update(label="❌ Error occurred", state="error")
st.error(f"An error occurred: {str(e)}")
st.stop()
# Convert CrewOutput to string for display and download
result_text = str(result)
# Display the final result
st.markdown(result_text)
# Create download buttons
st.divider()
download_col1, download_col2, download_col3 = st.columns([1, 2, 1])
with download_col2:
st.markdown("### 📥 Download Research Report")
# Download as Markdown
st.download_button(
label="Download Report",
data=result_text,
file_name="research_report.md",
mime="text/markdown",
help="Download the research report in Markdown format"
)
# Add footer
st.divider()
footer_col1, footer_col2, footer_col3 = st.columns([1, 2, 1])
with footer_col2:
st.caption("Made with ❤️ using [CrewAI](https://crewai.com), [Exa](https://exa.ai) and [Streamlit](https://streamlit.io)")