autodeploy apps
Browse filesFiles changed (4)
819 unmodified lines820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875819 unmodified lines }) yield f"data: {completion_data}\n\n" # Auto-deploy after code generation (if authenticated) auth = get_auth_from_header(authorization) if auth.is_authenticated() and not (auth.token and auth.token.startswith("dev_token_")): try: # Send deploying status deploying_data = json.dumps({ "type": "deploying", "message": "๐ Deploying your app to HuggingFace Spaces..." }) yield f"data: {deploying_data}\n\n" # Import deployment function from backend_deploy import deploy_to_huggingface_space # Convert history to the format expected by deploy function history_list = [[msg.get('role', ''), msg.get('content', '')] for msg in (request.history or [])] # Deploy the code success, message, space_url = deploy_to_huggingface_space( code=generated_code, language=language, token=auth.token, username=auth.username, history=history_list ) if success and space_url: # Send deployment success deploy_success_data = json.dumps({ "type": "deployed", "message": message, "space_url": space_url }) yield f"data: {deploy_success_data}\n\n" else: # Send deployment error (non-blocking - code generation still succeeded) deploy_error_data = json.dumps({ "type": "deploy_error", "message": f"โ ๏ธ Deployment failed: {message}" }) yield f"data: {deploy_error_data}\n\n" except Exception as deploy_error: # Log deployment error but don't fail the generation print(f"[Auto-Deploy] Error: {deploy_error}") deploy_error_data = json.dumps({ "type": "deploy_error", "message": f"โ ๏ธ Deployment error: {str(deploy_error)}" }) yield f"data: {deploy_error_data}\n\n" except Exception as e: # Handle rate limiting and other API errors error_message = str(e)337 unmodified lines338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392491 unmodified lines884885886838887888889337 unmodified lines }; return newMessages; }); }, // onDeploying (message: string) => { console.log('[Deploy] Deployment started:', message); // Update message to show deployment in progress setMessages((prev) => { const newMessages = [...prev]; newMessages[newMessages.length - 1] = { ...assistantMessage, content: `โ
Code generated successfully!\n\n${message}`, }; return newMessages; }); }, // onDeployed (message: string, spaceUrl: string) => { console.log('[Deploy] Deployment successful:', spaceUrl); // Extract repo_id from space URL const match = spaceUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/); if (match) { setCurrentRepoId(match[1]); } // Update message with deployment success and URL setMessages((prev) => { const newMessages = [...prev]; newMessages[newMessages.length - 1] = { ...assistantMessage, content: `โ
Code generated and deployed!\n\n๐ **View your app:** [${spaceUrl}](${spaceUrl})`, }; return newMessages; }); // Open the space URL in a new tab window.open(spaceUrl, '_blank'); }, // onDeployError (message: string) => { console.log('[Deploy] Deployment error:', message); // Update message to show deployment failed (but code generation succeeded) setMessages((prev) => { const newMessages = [...prev]; newMessages[newMessages.length - 1] = { ...assistantMessage, content: `โ
Code generated successfully!\n\n${message}\n\nYou can still use the "Publish" button to deploy manually.`, }; return newMessages; }); } ); } catch (error) {491 unmodified lines selectedModel={selectedModel} onLanguageChange={setSelectedLanguage} onModelChange={setSelectedModel} onDeploy={handleDeploy} onClear={handleClear} onImport={handleImport} isGenerating={isGenerating}8 unmodified lines91011121213144 unmodified lines19202123222324242 unmodified lines2672682692722732742752762772782702712728 unmodified lines selectedModel: string; onLanguageChange: (language: Language) => void; onModelChange: (modelId: string) => void; onDeploy: () => void; onClear: () => void; onImport?: (code: string, language: Language, importUrl?: string) => void; isGenerating: boolean;4 unmodified lines selectedModel, onLanguageChange, onModelChange, onDeploy, onClear, onImport, isGenerating,242 unmodified lines > Import Project </button> <button onClick={onDeploy} disabled={isGenerating} className="w-full px-3 py-2.5 bg-white text-black text-sm rounded-full hover:bg-[#f5f5f7] disabled:opacity-30 disabled:cursor-not-allowed transition-all font-medium flex items-center justify-center active:scale-95" > Publish </button> <button onClick={onClear} disabled={isGenerating}273 unmodified lines27427527627727727827928028128228372 unmodified lines356357358356359360361362363364365366367368369370371372373374375376377273 unmodified lines request: CodeGenerationRequest, onChunk: (content: string) => void, onComplete: (code: string) => void, onError: (error: string) => void onError: (error: string) => void, onDeploying?: (message: string) => void, onDeployed?: (message: string, spaceUrl: string) => void, onDeployError?: (message: string) => void ): () => void { // Build the URL correctly whether we have a base URL or not const baseUrl = API_URL || window.location.origin;72 unmodified lines // Use the complete code from the message if available, otherwise use accumulated const finalCode = data.code || accumulatedCode; onComplete(finalCode); return; // Exit the processing loop // Don't return yet - might have deployment events coming } else if (data.type === 'deploying') { console.log('[Stream] Deployment started:', data.message); if (onDeploying) { onDeploying(data.message || 'Deploying...'); } } else if (data.type === 'deployed') { console.log('[Stream] Deployment successful:', data.space_url); if (onDeployed) { onDeployed(data.message || 'Deployed!', data.space_url); } } else if (data.type === 'deploy_error') { console.log('[Stream] Deployment error:', data.message); if (onDeployError) { onDeployError(data.message || 'Deployment failed'); } } else if (data.type === 'error') { console.error('[Stream] Error:', data.message); onError(data.message || 'Unknown error occurred');backend_api.py+50
frontend/src/app/page.tsx+49-1
frontend/src/components/ControlPanel.tsx-9
frontend/src/lib/api.ts+20-2