fix deploy
Browse files540 unmodified lines5415425435445455465475485494 unmodified lines55455555655755855956056156256356456556656756856957057112 unmodified lines584585586587588589590540 unmodified linesprint(f"[Deploy] language: {language}")print(f"[Deploy] ============================================")# For Gradio space updates (import/redesign), only update .py filesif is_update and language == "gradio":print(f"[Deploy] Gradio space update - will only update .py files")# Parse the code to get all filesfiles = parse_multi_file_python_output(code)4 unmodified linescleaned_code = remove_code_block(code)files['app.py'] = cleaned_code# Filter to only .py filespy_files = {fname: content for fname, content in files.items() if fname.endswith('.py')}if not py_files:return False, "Error: No Python files found in generated code", Noneprint(f"[Deploy] Updating {len(py_files)} Python file(s): {list(py_files.keys())}")# Update each Python file individuallyupdated_files = []for file_path, content in py_files.items():print(f"[Deploy] Updating {file_path} ({len(content)} chars)")success, msg = update_space_file(repo_id=existing_repo_id,file_path=file_path,12 unmodified linesfiles_list = ", ".join(updated_files)return True, f"✅ Updated {len(updated_files)} file(s): {files_list}! View at: {space_url}", space_urlelse:return False, "Failed to update any Python files", Noneif is_update:# Use existing repo540 unmodified lines5415425435445455465475485494 unmodified lines55455555655755855956056156256356456556656756856957057112 unmodified lines584585586587588589590540 unmodified linesprint(f"[Deploy] language: {language}")print(f"[Deploy] ============================================")# For Gradio space updates (import/redesign), update .py files and upload all new filesif is_update and language == "gradio":print(f"[Deploy] Gradio space update - updating .py files and uploading any new files")# Parse the code to get all filesfiles = parse_multi_file_python_output(code)4 unmodified linescleaned_code = remove_code_block(code)files['app.py'] = cleaned_codeif not files:return False, "Error: No files found in generated code", Noneprint(f"[Deploy] Generated {len(files)} file(s): {list(files.keys())}")# Upload all generated files (the LLM is instructed to only output .py files,# but if it creates new assets/data files, we should upload those too)# This approach updates .py files and adds any new files without touching# existing non-.py files that weren't generatedupdated_files = []for file_path, content in files.items():print(f"[Deploy] Uploading {file_path} ({len(content)} chars)")success, msg = update_space_file(repo_id=existing_repo_id,file_path=file_path,12 unmodified linesfiles_list = ", ".join(updated_files)return True, f"✅ Updated {len(updated_files)} file(s): {files_list}! View at: {space_url}", space_urlelse:return False, "Failed to update any files", Noneif is_update:# Use existing repo
backend_deploy.py+12-12