import React, { useState, useCallback, useEffect } from 'react' import { X, Zap, TrendingUp, Brain, AlertTriangle, CheckCircle } from 'lucide-react' /** * MLInsightsPanel — Interactive ML features panel. * - Sector classification: type a description → get predicted sector * - Growth predictions: view top startups ranked by growth potential * - MLOps health: live model status and drift alerts */ export default function MLInsightsPanel({ onClose, onEntityClick }) { const [activeTab, setActiveTab] = useState('growth') return (
{/* Header */}
ML Insights LIVE
{/* Tabs */}
{[ { id: 'growth', label: 'Growth Predictions', icon: TrendingUp }, { id: 'classify', label: 'Sector Classifier', icon: Brain }, { id: 'health', label: 'Model Health', icon: Zap }, ].map(tab => ( ))}
{/* Content */}
{activeTab === 'growth' && } {activeTab === 'classify' && } {activeTab === 'health' && }
) } // ─── Growth Predictions Tab ───────────────────────────────────────────────── function GrowthTab({ onEntityClick }) { const [predictions, setPredictions] = useState([]) const [loading, setLoading] = useState(false) const [filters, setFilters] = useState({ sector: '', state: '' }) const fetchPredictions = useCallback(async () => { setLoading(true) try { const params = new URLSearchParams({ limit: '15' }) if (filters.sector) params.set('sector', filters.sector) if (filters.state) params.set('state', filters.state) const resp = await fetch(`/api/ml/predict/growth?${params}`) const data = await resp.json() setPredictions(data.predictions || []) } catch (err) { console.error('Growth prediction failed:', err) } setLoading(false) }, [filters]) useEffect(() => { fetchPredictions() }, [fetchPredictions]) return (
{/* Filters */}
{/* Results */} {loading ? (
) : (
{predictions.map((p, i) => (
p.slug && onEntityClick?.(p.slug)} className="flex items-center gap-3 p-3 rounded-xl bg-atlas-surface/50 border border-atlas-border hover:border-brand-500/30 cursor-pointer transition-all" >
{(p.growth_score * 100).toFixed(0)}

{p.entity_name}

📍 {p.city}, {p.state} {p.top_factor && ⭐ {p.top_factor.factor.replace('_', ' ')}}

{p.growth_label.toUpperCase()}
))} {predictions.length === 0 && !loading && (

No predictions available for these filters.

)}
)}
) } // ─── Sector Classifier Tab ────────────────────────────────────────────────── function ClassifyTab() { const [description, setDescription] = useState('') const [result, setResult] = useState(null) const [loading, setLoading] = useState(false) const classify = useCallback(async () => { if (description.length < 10) return setLoading(true) try { const resp = await fetch(`/api/ml/classify/sector?description=${encodeURIComponent(description)}&top_k=5`) const data = await resp.json() setResult(data) } catch (err) { console.error('Classification failed:', err) } setLoading(false) }, [description]) const exampleDescriptions = [ "AI-powered fraud detection platform for digital banking and UPI payments", "Online marketplace connecting farmers directly with urban consumers", "SaaS platform for hospital management and telemedicine consultations", "Electric vehicle charging network for tier-2 cities in India", "Gamified coding education platform for school students", ] return (