-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
300 lines (246 loc) Β· 10.1 KB
/
Copy pathstreamlit_app.py
File metadata and controls
300 lines (246 loc) Β· 10.1 KB
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
"""
Streamlit UI for AI Competitor Intelligence Multi-Agent System
Beautiful, interactive interface for competitor analysis
"""
import streamlit as st
import sys
import os
from datetime import datetime
# Add parent directory to path
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
from main import run_competitor_analysis
# Page configuration
st.set_page_config(
page_title="AI Competitor Intelligence",
page_icon="π€",
layout="wide",
initial_sidebar_state="expanded"
)
# Custom CSS
st.markdown("""
<style>
.main-header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
padding: 2rem;
border-radius: 10px;
color: white;
margin-bottom: 2rem;
}
.agent-status {
padding: 1rem;
border-radius: 8px;
margin: 0.5rem 0;
border-left: 4px solid;
}
.agent-working {
background-color: #fef3c7;
border-color: #f59e0b;
}
.agent-complete {
background-color: #d1fae5;
border-color: #10b981;
}
.competitor-card {
border: 2px solid #e5e7eb;
padding: 1.5rem;
border-radius: 10px;
margin: 1rem 0;
transition: all 0.3s;
}
.competitor-card:hover {
border-color: #8b5cf6;
box-shadow: 0 4px 12px rgba(139, 92, 246, 0.15);
}
</style>
""", unsafe_allow_html=True)
# Header
st.markdown("""
<div class="main-header">
<h1>π€ AI Competitor Intelligence Agent Team</h1>
<p style="font-size: 1.2rem; margin-top: 0.5rem;">
Multi-Agent System with LangChain & LangGraph
</p>
</div>
""", unsafe_allow_html=True)
# Sidebar
with st.sidebar:
st.header("βοΈ Configuration")
# Check API keys
anthropic_key = os.getenv("ANTHROPIC_API_KEY")
tavily_key = os.getenv("TAVILY_API_KEY")
if anthropic_key and tavily_key:
st.success("β
API Keys Configured")
else:
st.error("β Missing API Keys")
st.info("Set ANTHROPIC_API_KEY and TAVILY_API_KEY in .env file")
st.divider()
st.header("π Agent Architecture")
st.markdown("""
**π·οΈ Firecrawl Agent**
- Discovers competitors
- Web crawling & extraction
**π§ Analysis Agent**
- Market analysis
- Strategic insights
**βοΈ Comparison Agent**
- Feature matrix
- Recommendations
""")
st.divider()
st.markdown("### π Resources")
st.markdown("[LangChain Docs](https://python.langchain.com)")
st.markdown("[Anthropic API](https://console.anthropic.com)")
# Main content
col1, col2 = st.columns([2, 1])
with col1:
st.header("π Input")
# Mode selection
analysis_mode = st.radio(
"Analysis Mode",
["Business Description", "Company URL"],
horizontal=True
)
mode = "description" if analysis_mode == "Business Description" else "url"
# Input field
if mode == "description":
user_input = st.text_area(
"Describe Your Business",
placeholder="e.g., AI-powered project management tool for remote teams with real-time collaboration, automated workflows, and intelligent task prioritization...",
height=150
)
else:
user_input = st.text_input(
"Company URL",
placeholder="https://yourcompany.com"
)
with col2:
st.header("βΉοΈ About")
st.info("""
This tool uses a **multi-agent AI system** to analyze your competitors.
**What you'll get:**
- Competitor discovery
- Market analysis
- Feature comparison
- Strategic recommendations
**Powered by:**
- Claude Sonnet 4
- LangGraph
- Tavily Search
""")
# Analyze button
if st.button("π Deploy Multi-Agent System", type="primary", use_container_width=True):
if not user_input:
st.error("Please provide input before analyzing")
elif not (anthropic_key and tavily_key):
st.error("Please configure API keys in .env file")
else:
# Create status containers
status_container = st.container()
results_container = st.container()
with status_container:
st.header("π Agent Activity")
# Agent status placeholders
firecrawl_status = st.empty()
analysis_status = st.empty()
comparison_status = st.empty()
# Show initial status
firecrawl_status.markdown('<div class="agent-status agent-working">π·οΈ <b>Firecrawl Agent:</b> Starting...</div>', unsafe_allow_html=True)
# Run analysis
with st.spinner("Multi-agent system working..."):
try:
# Execute the analysis
results = run_competitor_analysis(user_input, mode)
# Update statuses
firecrawl_status.markdown('<div class="agent-status agent-complete">π·οΈ <b>Firecrawl Agent:</b> Complete β</div>', unsafe_allow_html=True)
analysis_status.markdown('<div class="agent-status agent-complete">π§ <b>Analysis Agent:</b> Complete β</div>', unsafe_allow_html=True)
comparison_status.markdown('<div class="agent-status agent-complete">βοΈ <b>Comparison Agent:</b> Complete β</div>', unsafe_allow_html=True)
st.success("β
Analysis Complete!")
except Exception as e:
st.error(f"β Error: {str(e)}")
st.stop()
# Display results
with results_container:
st.divider()
st.header("π Analysis Results")
# Tabs for different sections
tab1, tab2, tab3, tab4 = st.tabs([
"π― Competitors",
"π Analysis",
"βοΈ Comparison",
"π‘ Recommendations"
])
# Tab 1: Competitors
with tab1:
st.subheader(f"Discovered {len(results['competitors'])} Competitors")
for i, comp in enumerate(results['competitors'], 1):
st.markdown(f"""
<div class="competitor-card">
<h3>{i}. {comp.get('name', 'Unknown')}</h3>
<p><strong>URL:</strong> <a href="https://{comp.get('url', '')}" target="_blank">{comp.get('url', 'N/A')}</a></p>
<p><strong>Description:</strong> {comp.get('description', 'N/A')}</p>
<p><strong>Category:</strong> {comp.get('category', 'N/A')}</p>
<p><strong>Market Position:</strong> {comp.get('marketPosition', 'N/A')}</p>
<p><strong>Relevance Score:</strong> {comp.get('relevanceScore', 'N/A')}/10</p>
<p><em>{comp.get('relevanceReason', '')}</em></p>
</div>
""", unsafe_allow_html=True)
# Tab 2: Analysis
with tab2:
st.markdown(results['competitive_analysis'])
with st.expander("π Market Gaps"):
for gap in results['market_gaps']:
st.write(f"β’ {gap}")
with st.expander("β οΈ Competitor Weaknesses"):
for weakness in results['competitor_weaknesses']:
st.write(f"β’ {weakness}")
# Tab 3: Comparison
with tab3:
features = results['feature_comparison'].get('features', [])
if features:
st.subheader(f"Feature Comparison Matrix ({len(features)} features)")
for feature in features:
with st.expander(f"πΉ {feature.get('name')}"):
col1, col2 = st.columns(2)
with col1:
st.write("**Your Opportunity:**", feature.get('yourOpportunity', 'N/A'))
st.write("**Complexity:**", feature.get('implementationComplexity', 'N/A'))
with col2:
st.write("**Strategic Value:**")
st.info(feature.get('strategicValue', 'N/A'))
st.write("**Competitor Status:**")
competitors_data = feature.get('competitors', {})
for comp_name, status in competitors_data.items():
color = "π’" if status == "Yes" else "π΄" if status == "No" else "π‘"
st.write(f"{color} {comp_name}: {status}")
else:
st.warning("No feature comparison available")
# Tab 4: Recommendations
with tab4:
st.markdown(results['strategic_recommendations'])
# Download button for full report
st.divider()
report = f"""
# Competitor Intelligence Report
Generated: {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}
Business: {user_input}
## Discovered Competitors
{chr(10).join([f"{i}. {c['name']} - {c['url']}" for i, c in enumerate(results['competitors'], 1)])}
## Competitive Analysis
{results['competitive_analysis']}
## Strategic Recommendations
{results['strategic_recommendations']}
"""
st.download_button(
label="π₯ Download Full Report",
data=report,
file_name=f"competitor_analysis_{datetime.now().strftime('%Y%m%d_%H%M%S')}.md",
mime="text/markdown"
)
# Footer
st.divider()
st.markdown("""
<div style="text-align: center; color: #6b7280; padding: 2rem;">
<p>Powered by Claude Sonnet 4, LangChain & LangGraph</p>
<p>Multi-Agent Architecture with Blackboard Pattern</p>
</div>
""", unsafe_allow_html=True)