import React, { useState, useEffect } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { X, Rocket, Copy, CheckCheck, Code2, Globe, Server, Loader2, ArrowRight } from 'lucide-react'; import { useUserStore } from '@/store/userStore'; import apiService, { api } from '@/services/api'; interface DeployModalProps { isOpen: boolean; onClose: () => void; modelName: string; taskType: string; } const DeployModal: React.FC = ({ isOpen, onClose, modelName, taskType }) => { const isDark = useUserStore((state) => state.isDark); const [status, setStatus] = useState<'idle' | 'deploying' | 'success' | 'error'>('idle'); const [deployment, setDeployment] = useState(null); const [errorMsg, setErrorMsg] = useState(''); const [copied, setCopied] = useState(false); const [copiedKey, setCopiedKey] = useState(false); const [deployTarget, setDeployTarget] = useState<'datavision' | 'aws' | 'azure' | 'huggingface'>('datavision'); // Reset when opened useEffect(() => { if (isOpen) { setStatus('idle'); setDeployment(null); setErrorMsg(''); setDeployTarget('datavision'); } }, [isOpen]); const handleDeploy = async () => { setStatus('deploying'); try { const userId = useUserStore.getState().user?.id || 'default'; const res = await api.post('/api/v1/mlops/deploy', { name: modelName || "Deployed Model", champion_traffic: 100, challenger_traffic: 0 }); setDeployment(res.data.deployment); // Artificial delay to simulate cloud provisioning if not datavision if (deployTarget !== 'datavision') { await new Promise(resolve => setTimeout(resolve, 2500)); } setStatus('success'); } catch (err: any) { console.error('Deploy error:', err); setErrorMsg(err.response?.data?.detail || err.message || 'Failed to deploy model'); setStatus('error'); } }; const host = window.location.origin; const handleCopyCode = () => { if (!deployment) return; const code = `import requests # API Endpoint url = "${host}${deployment.endpoint}" # Authentication Key headers = { "X-API-Key": "${deployment.api_key}", "Content-Type": "application/json" } # Example Payload payload = { "deployment_id": "${deployment.deploy_id}", "features": { # Replace these with your actual dataset columns and values "feature_1": 0.5, "feature_2": 1.2 } } # Make Prediction response = requests.post(url, json=payload, headers=headers) print(response.json())`; navigator.clipboard.writeText(code); setCopied(true); setTimeout(() => setCopied(false), 2000); }; const handleCopyKey = () => { if (!deployment) return; navigator.clipboard.writeText(deployment.api_key); setCopiedKey(true); setTimeout(() => setCopiedKey(false), 2000); }; if (!isOpen) return null; const targets = [ { id: 'datavision', name: 'DataVision Cloud', icon: , desc: 'Instant local deployment' } ]; return (
{/* Header */}

Deploy to Production

Generate a live API endpoint for {modelName}

{/* Content */}
{status === 'idle' && (

Select Deployment Target

{targets.map(t => ( ))}

We will package your trained {modelName} model and deploy it to {targets.find(t => t.id === deployTarget)?.name}.

)} {status === 'deploying' && (

Provisioning API Endpoint...

Packaging {modelName} for scalable inference

)} {status === 'error' && (

Deployment Failed

{errorMsg}

)} {status === 'success' && deployment && (

Deployment Successful

Your model is now live and accepting predictions.

{host}{deployment.endpoint}
{deployment.api_key}
                                            "${host}${deployment.endpoint}"\n\nheaders = {\n    "X-API-Key": "${deployment.api_key}",\n    "Content-Type": "application/json"\n}\n\npayload = {\n    "data": {\n        # Add your features here\n    }\n}\n\nresponse = requests.post(url, json=payload, headers=headers)\nprint(response.json())` }} />
                                        
)}
{/* Footer */} {status === 'success' && (
)}
); }; export default DeployModal;