update
Browse filesFiles changed (2)
566 unmodified lines56756856957057157212 unmodified lines5855865875885895907 unmodified lines59859960060160260360460560616 unmodified lines623624625626627628629566 unmodified linesraise HTTPException(status_code=401, detail="No HuggingFace token available. Please sign in first.")print(f"[Deploy] Attempting deployment with token (first 10 chars): {user_token[:10]}...")# Check for existing deployed space in this sessionexisting_repo_id = request.existing_repo_id12 unmodified linesbreak# Use the standalone deployment functionsuccess, message, space_url = deploy_to_huggingface_space(code=request.code,language=request.language,7 unmodified lines)if success:# Track deployed space in session for follow-up updatesif session_token and session_token in user_sessions:repo_id = space_url.split("/spaces/")[-1] if space_url else Noneif repo_id:session = user_sessions[session_token]deployed_spaces = session.get("deployed_spaces", [])16 unmodified lines"success": True,"space_url": space_url,"message": message,"repo_id": repo_id if 'repo_id' in locals() else None}else:# Provide user-friendly error message based on the error566 unmodified lines56756856957057157257312 unmodified lines5865875885895905915927 unmodified lines60060160260360460560660760860961061116 unmodified lines628629630631632633634566 unmodified linesraise HTTPException(status_code=401, detail="No HuggingFace token available. Please sign in first.")print(f"[Deploy] Attempting deployment with token (first 10 chars): {user_token[:10]}...")print(f"[Deploy] Request parameters - language: {request.language}, space_name: {request.space_name}, existing_repo_id: {request.existing_repo_id}")# Check for existing deployed space in this sessionexisting_repo_id = request.existing_repo_id12 unmodified linesbreak# Use the standalone deployment functionprint(f"[Deploy] Calling deploy_to_huggingface_space with existing_repo_id: {existing_repo_id}")success, message, space_url = deploy_to_huggingface_space(code=request.code,language=request.language,7 unmodified lines)if success:# Extract repo_id from space_urlrepo_id = space_url.split("/spaces/")[-1] if space_url else Noneprint(f"[Deploy] Success! Repo ID: {repo_id}")# Track deployed space in session for follow-up updatesif session_token and session_token in user_sessions:if repo_id:session = user_sessions[session_token]deployed_spaces = session.get("deployed_spaces", [])16 unmodified lines"success": True,"space_url": space_url,"message": message,"repo_id": repo_id}else:# Provide user-friendly error message based on the error
192 unmodified lines1931941951961971985 unmodified lines20420520620720820921033 unmodified lines244245246247248249250251252253254255256257258259260261262263264265266267192 unmodified lines}try {const response = await apiClient.deploy({code: generatedCode,space_name: spaceName,5 unmodified linesif (response.success) {// Update current repo ID if we got one backif (response.repo_id) {setCurrentRepoId(response.repo_id);}// Add deployment message to chat33 unmodified lines};const handleImport = (code: string, language: Language, importUrl?: string) => {setGeneratedCode(code);setSelectedLanguage(language);// Extract repo_id from import URL if providedif (importUrl) {const spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);if (spaceMatch) {const importedRepoId = spaceMatch[1];// Only set as current repo if user owns itif (username && importedRepoId.startsWith(`${username}/`)) {setCurrentRepoId(importedRepoId);console.log('[Import] Set current repo to:', importedRepoId);} else {// User doesn't own the imported space, clear current reposetCurrentRepoId(null);console.log('[Import] User does not own imported space:', importedRepoId);}}}// Add messages that include the imported code so LLM can see it192 unmodified lines1931941951961971981992002012022032042052062075 unmodified lines21321421521621721821922022122222322422522622733 unmodified lines261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291192 unmodified lines}try {console.log('[Deploy] Deploying with params:', {language: selectedLanguage,space_name: spaceName,existing_repo_id: existingRepoId,currentRepoId: currentRepoId,username: username,code_length: generatedCode.length});const response = await apiClient.deploy({code: generatedCode,space_name: spaceName,5 unmodified linesif (response.success) {// Update current repo ID if we got one backif (response.repo_id) {console.log('[Deploy] Setting currentRepoId to:', response.repo_id);setCurrentRepoId(response.repo_id);} else if (response.space_url) {// Extract repo_id from space_url as fallbackconst match = response.space_url.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);if (match) {console.log('[Deploy] Extracted repo_id from URL:', match[1]);setCurrentRepoId(match[1]);}}// Add deployment message to chat33 unmodified lines};const handleImport = (code: string, language: Language, importUrl?: string) => {console.log('[Import] Importing project:', { language, importUrl, username });setGeneratedCode(code);setSelectedLanguage(language);// Extract repo_id from import URL if providedif (importUrl) {const spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);console.log('[Import] Regex match result:', spaceMatch);if (spaceMatch) {const importedRepoId = spaceMatch[1];console.log('[Import] Extracted repo_id:', importedRepoId, 'Username:', username);// Only set as current repo if user owns itif (username && importedRepoId.startsWith(`${username}/`)) {setCurrentRepoId(importedRepoId);console.log('[Import] ✅ Set current repo to:', importedRepoId);} else {// User doesn't own the imported space, clear current reposetCurrentRepoId(null);console.log('[Import] ⚠️ User does not own imported space:', importedRepoId, '(username:', username, ')');}} else {console.log('[Import] ⚠️ Could not extract repo_id from URL:', importUrl);}} else {console.log('[Import] No import URL provided');}// Add messages that include the imported code so LLM can see it
backend_api.py+7-2
frontend/src/app/page.tsx+26-2