{ // 获取包含Hugging Face文本的span元素 const spans = link.querySelectorAll('span.whitespace-nowrap, span.hidden.whitespace-nowrap'); spans.forEach(span => { if (span.textContent && span.textContent.trim().match(/Hugging\s*Face/i)) { span.textContent = 'AI快站'; } }); }); // 替换logo图片的alt属性 document.querySelectorAll('img[alt*="Hugging"], img[alt*="Face"]').forEach(img => { if (img.alt.match(/Hugging\s*Face/i)) { img.alt = 'AI快站 logo'; } }); } // 替换导航栏中的链接 function replaceNavigationLinks() { // 已替换标记,防止重复运行 if (window._navLinksReplaced) { return; } // 已经替换过的链接集合,防止重复替换 const replacedLinks = new Set(); // 只在导航栏区域查找和替换链接 const headerArea = document.querySelector('header') || document.querySelector('nav'); if (!headerArea) { return; } // 在导航区域内查找链接 const navLinks = headerArea.querySelectorAll('a'); navLinks.forEach(link => { // 如果已经替换过,跳过 if (replacedLinks.has(link)) return; const linkText = link.textContent.trim(); const linkHref = link.getAttribute('href') || ''; // 替换Spaces链接 - 仅替换一次 if ( (linkHref.includes('/spaces') || linkHref === '/spaces' || linkText === 'Spaces' || linkText.match(/^s*Spacess*$/i)) && linkText !== 'OCR模型免费转Markdown' && linkText !== 'OCR模型免费转Markdown' ) { link.textContent = 'OCR模型免费转Markdown'; link.href = 'https://fast360.xyz'; link.setAttribute('target', '_blank'); link.setAttribute('rel', 'noopener noreferrer'); replacedLinks.add(link); } // 删除Posts链接 else if ( (linkHref.includes('/posts') || linkHref === '/posts' || linkText === 'Posts' || linkText.match(/^s*Postss*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } // 替换Docs链接 - 仅替换一次 else if ( (linkHref.includes('/docs') || linkHref === '/docs' || linkText === 'Docs' || linkText.match(/^s*Docss*$/i)) && linkText !== '模型下载攻略' ) { link.textContent = '模型下载攻略'; link.href = '/'; replacedLinks.add(link); } // 删除Enterprise链接 else if ( (linkHref.includes('/enterprise') || linkHref === '/enterprise' || linkText === 'Enterprise' || linkText.match(/^s*Enterprises*$/i)) ) { if (link.parentNode) { link.parentNode.removeChild(link); } replacedLinks.add(link); } }); // 查找可能嵌套的Spaces和Posts文本 const textNodes = []; function findTextNodes(element) { if (element.nodeType === Node.TEXT_NODE) { const text = element.textContent.trim(); if (text === 'Spaces' || text === 'Posts' || text === 'Enterprise') { textNodes.push(element); } } else { for (const child of element.childNodes) { findTextNodes(child); } } } // 只在导航区域内查找文本节点 findTextNodes(headerArea); // 替换找到的文本节点 textNodes.forEach(node => { const text = node.textContent.trim(); if (text === 'Spaces') { node.textContent = node.textContent.replace(/Spaces/g, 'OCR模型免费转Markdown'); } else if (text === 'Posts') { // 删除Posts文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } else if (text === 'Enterprise') { // 删除Enterprise文本节点 if (node.parentNode) { node.parentNode.removeChild(node); } } }); // 标记已替换完成 window._navLinksReplaced = true; } // 替换代码区域中的域名 function replaceCodeDomains() { // 特别处理span.hljs-string和span.njs-string元素 document.querySelectorAll('span.hljs-string, span.njs-string, span[class*="hljs-string"], span[class*="njs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换hljs-string类的span中的域名(移除多余的转义符号) document.querySelectorAll('span.hljs-string, span[class*="hljs-string"]').forEach(span => { if (span.textContent && span.textContent.includes('huggingface.co')) { span.textContent = span.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 替换pre和code标签中包含git clone命令的域名 document.querySelectorAll('pre, code').forEach(element => { if (element.textContent && element.textContent.includes('git clone')) { const text = element.innerHTML; if (text.includes('huggingface.co')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 处理特定的命令行示例 document.querySelectorAll('pre, code').forEach(element => { const text = element.innerHTML; if (text.includes('huggingface.co')) { // 针对git clone命令的专门处理 if (text.includes('git clone') || text.includes('GIT_LFS_SKIP_SMUDGE=1')) { element.innerHTML = text.replace(/huggingface.co/g, 'aifasthub.com'); } } }); // 特别处理模型下载页面上的代码片段 document.querySelectorAll('.flex.border-t, .svelte_hydrator, .inline-block').forEach(container => { const content = container.innerHTML; if (content && content.includes('huggingface.co')) { container.innerHTML = content.replace(/huggingface.co/g, 'aifasthub.com'); } }); // 特别处理模型仓库克隆对话框中的代码片段 try { // 查找包含"Clone this model repository"标题的对话框 const cloneDialog = document.querySelector('.svelte_hydration_boundary, [data-target="MainHeader"]'); if (cloneDialog) { // 查找对话框中所有的代码片段和命令示例 const codeElements = cloneDialog.querySelectorAll('pre, code, span'); codeElements.forEach(element => { if (element.textContent && element.textContent.includes('huggingface.co')) { if (element.innerHTML.includes('huggingface.co')) { element.innerHTML = element.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { element.textContent = element.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); } // 更精确地定位克隆命令中的域名 document.querySelectorAll('[data-target]').forEach(container => { const codeBlocks = container.querySelectorAll('pre, code, span.hljs-string'); codeBlocks.forEach(block => { if (block.textContent && block.textContent.includes('huggingface.co')) { if (block.innerHTML.includes('huggingface.co')) { block.innerHTML = block.innerHTML.replace(/huggingface.co/g, 'aifasthub.com'); } else { block.textContent = block.textContent.replace(/huggingface.co/g, 'aifasthub.com'); } } }); }); } catch (e) { // 错误处理但不打印日志 } } // 当DOM加载完成后执行替换 if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', () => { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); }); } else { replaceHeaderBranding(); replaceNavigationLinks(); replaceCodeDomains(); // 只在必要时执行替换 - 3秒后再次检查 setTimeout(() => { if (!window._navLinksReplaced) { console.log('[Client] 3秒后重新检查导航链接'); replaceNavigationLinks(); } }, 3000); } // 增加一个MutationObserver来处理可能的动态元素加载 const observer = new MutationObserver(mutations => { // 检查是否导航区域有变化 const hasNavChanges = mutations.some(mutation => { // 检查是否存在header或nav元素变化 return Array.from(mutation.addedNodes).some(node => { if (node.nodeType === Node.ELEMENT_NODE) { // 检查是否是导航元素或其子元素 if (node.tagName === 'HEADER' || node.tagName === 'NAV' || node.querySelector('header, nav')) { return true; } // 检查是否在导航元素内部 let parent = node.parentElement; while (parent) { if (parent.tagName === 'HEADER' || parent.tagName === 'NAV') { return true; } parent = parent.parentElement; } } return false; }); }); // 只在导航区域有变化时执行替换 if (hasNavChanges) { // 重置替换状态,允许再次替换 window._navLinksReplaced = false; replaceHeaderBranding(); replaceNavigationLinks(); } }); // 开始观察document.body的变化,包括子节点 if (document.body) { observer.observe(document.body, { childList: true, subtree: true }); } else { document.addEventListener('DOMContentLoaded', () => { observer.observe(document.body, { childList: true, subtree: true }); }); } })(); '\n# error_message_ticket = '

Internal error

Ticket issued: %(ticket)s'\n\ndef __routes_doctest():\n '''\n Dummy function for doctesting routes.py.\n\n Use filter_url() to test incoming or outgoing routes;\n filter_err() for error redirection.\n\n filter_url() accepts overrides for method and remote host:\n filter_url(url, method='get', remote='0.0.0.0', out=False)\n\n filter_err() accepts overrides for application and ticket:\n filter_err(status, application='app', ticket='tkt')\n\n >>> import os\n >>> import gluon.main\n >>> from gluon.rewrite import load, filter_url, filter_err, get_effective_router\n >>> load(routes=os.path.basename(__file__))\n\n >>> filter_url('http://domain.com/abc', app=True)\n 'welcome'\n >>> filter_url('http://domain.com/welcome', app=True)\n 'welcome'\n >>> os.path.relpath(filter_url('http://domain.com/favicon.ico'))\n 'applications/welcome/static/favicon.ico'\n >>> filter_url('http://domain.com/abc')\n '/welcome/default/abc'\n >>> filter_url('http://domain.com/index/abc')\n \"/welcome/default/index ['abc']\"\n >>> filter_url('http://domain.com/default/abc.css')\n '/welcome/default/abc.css'\n >>> filter_url('http://domain.com/default/index/abc')\n \"/welcome/default/index ['abc']\"\n >>> filter_url('http://domain.com/default/index/a bc')\n \"/welcome/default/index ['a bc']\"\n >>> filter_url('http://domain.com/admin/bad!ctl')\n Traceback (most recent call last):\n ...\n HTTP: 400 BAD REQUEST [invalid controller]\n >>> filter_url('http://domain.com/admin/ctl/bad!fcn')\n Traceback (most recent call last):\n ...\n HTTP: 400 BAD REQUEST [invalid function]\n >>> filter_url('http://domain.com/admin/ctl/fcn.bad!ext')\n Traceback (most recent call last):\n ...\n HTTP: 400 BAD REQUEST [invalid extension]\n >>> filter_url('http://domain.com/admin/ctl/fcn/bad!arg')\n Traceback (most recent call last):\n ...\n HTTP: 400 BAD REQUEST [invalid arg ]\n\n >>> filter_url('https://domain.com/app/ctr/fcn', out=True)\n '/app/ctr/fcn'\n >>> filter_url('https://domain.com/welcome/ctr/fcn', out=True)\n '/ctr/fcn'\n >>> filter_url('https://domain.com/welcome/default/fcn', out=True)\n '/fcn'\n >>> filter_url('https://domain.com/welcome/default/index', out=True)\n '/'\n >>> filter_url('https://domain.com/welcome/appadmin/index', out=True)\n '/appadmin'\n >>> filter_url('http://domain.com/welcome/default/fcn?query', out=True)\n '/fcn?query'\n >>> filter_url('http://domain.com/welcome/default/fcn#anchor', out=True)\n '/fcn#anchor'\n >>> filter_url('http://domain.com/welcome/default/fcn?query#anchor', out=True)\n '/fcn?query#anchor'\n\n >>> filter_url('http://domain.com/appadmin/fcn-1')\n '/welcome/appadmin/fcn_1'\n >>> filter_url('http://domain.com/welcome/appadmin/fcn_1', out=True)\n '/appadmin/fcn-1'\n >>> filter_url('http://domain.com/examples/appadmin/fcn-1')\n '/examples/appadmin/fcn_1'\n >>> filter_url('http://domain.com/examples/appadmin/fcn_1', out=True)\n '/examples/appadmin/fcn-1'\n >>> filter_url('http://domain.com/app/static/filename-with_underscore', out=True)\n '/app/static/filename-with_underscore'\n >>> os.path.relpath(filter_url('http://domain.com/admin/static/filename-with_underscore'))\n 'applications/admin/static/filename-with_underscore'\n \n >>> filter_err(200)\n 200\n >>> filter_err(399)\n 399\n >>> filter_err(400)\n 400\n '''\n pass\n\nif __name__ == '__main__':\n import doctest\n doctest.testmod()\n"},"avg_line_length":{"kind":"number","value":42.6322869955,"string":"42.632287"},"max_line_length":{"kind":"number","value":164,"string":"164"},"alphanum_fraction":{"kind":"number","value":0.679288945,"string":"0.679289"},"count_classes":{"kind":"number","value":0,"string":"0"},"score_classes":{"kind":"number","value":0,"string":"0"},"count_generators":{"kind":"number","value":0,"string":"0"},"score_generators":{"kind":"number","value":0,"string":"0"},"count_decorators":{"kind":"number","value":0,"string":"0"},"score_decorators":{"kind":"number","value":0,"string":"0"},"count_async_functions":{"kind":"number","value":0,"string":"0"},"score_async_functions":{"kind":"number","value":0,"string":"0"},"count_documentation":{"kind":"number","value":9125,"string":"9,125"},"score_documentation":{"kind":"number","value":0.9598190806773956,"string":"0.959819"}}},{"rowIdx":962,"cells":{"hexsha":{"kind":"string","value":"6ad467fa9905c0ca84ad3c1dc298047956f35818"},"size":{"kind":"number","value":252,"string":"252"},"ext":{"kind":"string","value":"py"},"lang":{"kind":"string","value":"Python"},"max_stars_repo_path":{"kind":"string","value":"notebooks/2018.11.09 Meeting.py"},"max_stars_repo_name":{"kind":"string","value":"costrouc/uarray"},"max_stars_repo_head_hexsha":{"kind":"string","value":"c3c42147181a88265942ad5f9cf439467f746782"},"max_stars_repo_licenses":{"kind":"list like","value":["BSD-3-Clause"],"string":"[\n \"BSD-3-Clause\"\n]"},"max_stars_count":{"kind":"null"},"max_stars_repo_stars_event_min_datetime":{"kind":"null"},"max_stars_repo_stars_event_max_datetime":{"kind":"null"},"max_issues_repo_path":{"kind":"string","value":"notebooks/2018.11.09 Meeting.py"},"max_issues_repo_name":{"kind":"string","value":"costrouc/uarray"},"max_issues_repo_head_hexsha":{"kind":"string","value":"c3c42147181a88265942ad5f9cf439467f746782"},"max_issues_repo_licenses":{"kind":"list like","value":["BSD-3-Clause"],"string":"[\n \"BSD-3-Clause\"\n]"},"max_issues_count":{"kind":"null"},"max_issues_repo_issues_event_min_datetime":{"kind":"null"},"max_issues_repo_issues_event_max_datetime":{"kind":"null"},"max_forks_repo_path":{"kind":"string","value":"notebooks/2018.11.09 Meeting.py"},"max_forks_repo_name":{"kind":"string","value":"costrouc/uarray"},"max_forks_repo_head_hexsha":{"kind":"string","value":"c3c42147181a88265942ad5f9cf439467f746782"},"max_forks_repo_licenses":{"kind":"list like","value":["BSD-3-Clause"],"string":"[\n \"BSD-3-Clause\"\n]"},"max_forks_count":{"kind":"null"},"max_forks_repo_forks_event_min_datetime":{"kind":"null"},"max_forks_repo_forks_event_max_datetime":{"kind":"null"},"content":{"kind":"string","value":"#%%\nfrom uarray.core import *\n\n#%%\ns = Scalar(Int(10))\n\n#%%\n@operation\ndef Always(a: T) -> CCallableUnary[T, CContent]:\n ...\n\n\n#%%\nregister(Call(Always(w(\"a\")), w(\"idx\")), lambda a, idx: a)\n\n\n#%%\na_ten = Always(s)\n\n\n#%%\ns = Sequence(Int(10), a_ten)\n"},"avg_line_length":{"kind":"number","value":10.9565217391,"string":"10.956522"},"max_line_length":{"kind":"number","value":58,"string":"58"},"alphanum_fraction":{"kind":"number","value":0.5595238095,"string":"0.559524"},"count_classes":{"kind":"number","value":0,"string":"0"},"score_classes":{"kind":"number","value":0,"string":"0"},"count_generators":{"kind":"number","value":0,"string":"0"},"score_generators":{"kind":"number","value":0,"string":"0"},"count_decorators":{"kind":"number","value":67,"string":"67"},"score_decorators":{"kind":"number","value":0.26587301587301587,"string":"0.265873"},"count_async_functions":{"kind":"number","value":0,"string":"0"},"score_async_functions":{"kind":"number","value":0,"string":"0"},"count_documentation":{"kind":"number","value":26,"string":"26"},"score_documentation":{"kind":"number","value":0.10317460317460317,"string":"0.103175"}}},{"rowIdx":963,"cells":{"hexsha":{"kind":"string","value":"6ad4fd638f3c8440ee1f4046774d447aac8466fb"},"size":{"kind":"number","value":2540,"string":"2,540"},"ext":{"kind":"string","value":"py"},"lang":{"kind":"string","value":"Python"},"max_stars_repo_path":{"kind":"string","value":"var/spack/repos/builtin/packages/py-black/package.py"},"max_stars_repo_name":{"kind":"string","value":"dwstreetNNL/spack"},"max_stars_repo_head_hexsha":{"kind":"string","value":"8f929707147c49606d00386a10161529dad4ec56"},"max_stars_repo_licenses":{"kind":"list like","value":["ECL-2.0","Apache-2.0","MIT-0","MIT"],"string":"[\n \"ECL-2.0\",\n \"Apache-2.0\",\n \"MIT-0\",\n \"MIT\"\n]"},"max_stars_count":{"kind":"null"},"max_stars_repo_stars_event_min_datetime":{"kind":"null"},"max_stars_repo_stars_event_max_datetime":{"kind":"null"},"max_issues_repo_path":{"kind":"string","value":"var/spack/repos/builtin/packages/py-black/package.py"},"max_issues_repo_name":{"kind":"string","value":"dwstreetNNL/spack"},"max_issues_repo_head_hexsha":{"kind":"string","value":"8f929707147c49606d00386a10161529dad4ec56"},"max_issues_repo_licenses":{"kind":"list like","value":["ECL-2.0","Apache-2.0","MIT-0","MIT"],"string":"[\n \"ECL-2.0\",\n \"Apache-2.0\",\n \"MIT-0\",\n \"MIT\"\n]"},"max_issues_count":{"kind":"null"},"max_issues_repo_issues_event_min_datetime":{"kind":"null"},"max_issues_repo_issues_event_max_datetime":{"kind":"null"},"max_forks_repo_path":{"kind":"string","value":"var/spack/repos/builtin/packages/py-black/package.py"},"max_forks_repo_name":{"kind":"string","value":"dwstreetNNL/spack"},"max_forks_repo_head_hexsha":{"kind":"string","value":"8f929707147c49606d00386a10161529dad4ec56"},"max_forks_repo_licenses":{"kind":"list like","value":["ECL-2.0","Apache-2.0","MIT-0","MIT"],"string":"[\n \"ECL-2.0\",\n \"Apache-2.0\",\n \"MIT-0\",\n \"MIT\"\n]"},"max_forks_count":{"kind":"null"},"max_forks_repo_forks_event_min_datetime":{"kind":"null"},"max_forks_repo_forks_event_max_datetime":{"kind":"null"},"content":{"kind":"string","value":"# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other\n# Spack Project Developers. See the top-level COPYRIGHT file for details.\n#\n# SPDX-License-Identifier: (Apache-2.0 OR MIT)\n\nfrom spack import *\n\n\nclass PyBlack(PythonPackage):\n \"\"\"Black is the uncompromising Python code formatter. By using it, you agree to\n cede control over minutiae of hand-formatting. In return, Black gives you\n speed, determinism, and freedom from pycodestyle nagging about formatting.\n \"\"\"\n\n homepage = \"https://github.com/psf/black\"\n url = \"https://pypi.io/packages/source/b/black/black-20.8b1.tar.gz\"\n\n version('20.8b1', sha256='1c02557aa099101b9d21496f8a914e9ed2222ef70336404eeeac8edba836fbea')\n version('19.3b0', sha256='68950ffd4d9169716bcb8719a56c07a2f4485354fec061cdd5910aa07369731c')\n version('18.9b0', sha256='e030a9a28f542debc08acceb273f228ac422798e5215ba2a791a6ddeaaca22a5')\n\n variant('d', default=False, description='enable blackd HTTP server')\n\n depends_on('python@3.6.0:')\n # Needs setuptools at runtime so that `import pkg_resources` succeeds\n # See #8843 and #8689 for examples of setuptools added as a runtime dep\n depends_on('py-setuptools', type=('build', 'run'))\n # Translated from black's setup.py:\n # https://github.com/ambv/black/blob/master/setup.py\n depends_on('py-click@6.5:', type=('build', 'run'))\n depends_on('py-click@7.1.2:', when='@20.8b1:', type=('build', 'run'))\n depends_on('py-attrs@18.1.0:', when='@:20.8b0', type=('build', 'run'))\n depends_on('py-appdirs', type=('build', 'run'))\n depends_on('py-toml@0.9.4:', type=('build', 'run'))\n depends_on('py-toml@0.10.1:', when='@20.8b1:', type=('build', 'run'))\n depends_on('py-typed-ast@1.4.0:', when='@19.10b0:', type=('build', 'run'))\n depends_on('py-regex@2020.1.8:', when='@20.8b0:', type=('build', 'run'))\n depends_on('py-pathspec@0.6:0.999', when='@19.10b0:', type=('build', 'run'))\n depends_on('py-dataclasses@0.6:', when='@20.8b0:^python@:3.6', type=('build', 'run'))\n depends_on('py-typing-extensions@3.7.4:', when='@20.8b0:', type=('build', 'run'))\n depends_on('py-mypy-extensions@0.4.3:', when='@20.8b0:', type=('build', 'run'))\n depends_on('py-aiohttp@3.3.2:', when='+d', type=('build', 'run'))\n depends_on('py-aiohttp-cors', when='+d', type=('build', 'run'))\n\n @property\n def import_modules(self):\n modules = ['blib2to3', 'blib2to3.pgen2', 'black']\n\n if '+d' in self.spec:\n modules.append('blackd')\n\n return modules\n"},"avg_line_length":{"kind":"number","value":47.9245283019,"string":"47.924528"},"max_line_length":{"kind":"number","value":96,"string":"96"},"alphanum_fraction":{"kind":"number","value":0.6633858268,"string":"0.663386"},"count_classes":{"kind":"number","value":2319,"string":"2,319"},"score_classes":{"kind":"number","value":0.912992125984252,"string":"0.912992"},"count_generators":{"kind":"number","value":0,"string":"0"},"score_generators":{"kind":"number","value":0,"string":"0"},"count_decorators":{"kind":"number","value":189,"string":"189"},"score_decorators":{"kind":"number","value":0.07440944881889763,"string":"0.074409"},"count_async_functions":{"kind":"number","value":0,"string":"0"},"score_async_functions":{"kind":"number","value":0,"string":"0"},"count_documentation":{"kind":"number","value":1646,"string":"1,646"},"score_documentation":{"kind":"number","value":0.6480314960629922,"string":"0.648031"}}},{"rowIdx":964,"cells":{"hexsha":{"kind":"string","value":"6ad54c23aea43b34f6b32a39f371e9919e5e2f64"},"size":{"kind":"number","value":3772,"string":"3,772"},"ext":{"kind":"string","value":"py"},"lang":{"kind":"string","value":"Python"},"max_stars_repo_path":{"kind":"string","value":"store/adminshop/templatetags/admin_extras.py"},"max_stars_repo_name":{"kind":"string","value":"vallemrv/my_store_test"},"max_stars_repo_head_hexsha":{"kind":"string","value":"2da624fd02c5f1784464f15b751b488f3dd2bae6"},"max_stars_repo_licenses":{"kind":"list like","value":["Apache-2.0"],"string":"[\n \"Apache-2.0\"\n]"},"max_stars_count":{"kind":"null"},"max_stars_repo_stars_event_min_datetime":{"kind":"null"},"max_stars_repo_stars_event_max_datetime":{"kind":"null"},"max_issues_repo_path":{"kind":"string","value":"store/adminshop/templatetags/admin_extras.py"},"max_issues_repo_name":{"kind":"string","value":"vallemrv/my_store_test"},"max_issues_repo_head_hexsha":{"kind":"string","value":"2da624fd02c5f1784464f15b751b488f3dd2bae6"},"max_issues_repo_licenses":{"kind":"list like","value":["Apache-2.0"],"string":"[\n \"Apache-2.0\"\n]"},"max_issues_count":{"kind":"null"},"max_issues_repo_issues_event_min_datetime":{"kind":"null"},"max_issues_repo_issues_event_max_datetime":{"kind":"null"},"max_forks_repo_path":{"kind":"string","value":"store/adminshop/templatetags/admin_extras.py"},"max_forks_repo_name":{"kind":"string","value":"vallemrv/my_store_test"},"max_forks_repo_head_hexsha":{"kind":"string","value":"2da624fd02c5f1784464f15b751b488f3dd2bae6"},"max_forks_repo_licenses":{"kind":"list like","value":["Apache-2.0"],"string":"[\n \"Apache-2.0\"\n]"},"max_forks_count":{"kind":"null"},"max_forks_repo_forks_event_min_datetime":{"kind":"null"},"max_forks_repo_forks_event_max_datetime":{"kind":"null"},"content":{"kind":"string","value":"# -*- coding: utf-8 -*-\n\n# @Author: Manuel Rodriguez \n# @Date: 27-Aug-2017\n# @Email: valle.mrv@gmail.com\n# @Filename: admin_extras.py\n# @Last modified by: valle\n# @Last modified time: 02-Feb-2018\n# @License: Apache license vesion 2.0\n\nfrom django import template\nfrom django.db.models import Q\ntry:\n from django.core.urlresolvers import reverse\nexcept ImportError:\n from django.urls import reverse\n\nfrom adminshop.models import Testeo, Compras, Presupuesto\nimport json\nimport sys\nregister = template.Library()\n\n\n@register.filter(name='get_nombre_cliente')\ndef get_nombre_cliente(f):\n return f.get_nombre_cliente()\n\n@register.filter(name='enviado')\ndef enviado(f):\n return \"No\" if not f.enviado else \"Si\"\n\n\n@register.filter(name='get_user')\ndef get_user(f):\n return f.get_user()\n\n@register.filter(name='get_ns_imei')\ndef get_ns_imei(f):\n return f.get_ns_imei()\n\n@register.filter(name='get_producto_pk')\ndef get_producto_pk(f):\n return f.get_producto_pk()\n\n\n@register.filter(name='addcss')\ndef addcss(field, css):\n return field.as_widget(attrs={\"class\":css})\n\n@register.filter(name='reparacion')\ndef reparacion(p):\n try:\n pres = Presupuesto.objects.filter(producto__pk=p.id)[0]\n return pres.notas_cliente\n except:\n return \"\"\n\n@register.filter(name='num_pres')\ndef num_pres(p):\n try:\n pres = Presupuesto.objects.filter(producto__pk=p.id)[0]\n return pres.pk\n except:\n return -1\n\n@register.filter(name='precio_venta')\ndef precio_venta(p):\n precio = 0 if p.precio_venta == None else p.precio_venta\n return \"{0:.2f} €\".format(precio)\n\n@register.filter(name='precio_usado')\ndef precio_usado(p):\n return \"{0:.2f} €\".format(p.modelo.precio_usado * p.tipo.incremento)\n\n@register.filter(name='document_show')\ndef document_show(p):\n compras = Compras.objects.filter(producto__id=p.pk)\n if len(compras) > 0:\n compra = compras[0]\n else:\n compra = Compras()\n return p.estado in [\"ST\", \"VD\", \"OL\", \"VT\"]\n\n@register.filter(name='document_href')\ndef document_href(p):\n if p.estado in [\"ST\", \"VT\", \"OL\"]:\n return reverse(\"get_document_by_id\", args=[p.pk])\n elif p.estado in [\"RP\", \"OK\", \"PD\"]:\n return reverse(\"get_presupuesto_pdf\", args=[p.pk])\n elif p.estado == \"VD\":\n return reverse(\"get_all_document\", args=[p.pk])\n else:\n return \"#\"\n\n@register.filter(name='have_sign')\ndef have_sign(p):\n compras = Compras.objects.filter(producto__id=p.pk)\n compra = Compras()\n if len(compras) > 0:\n compra = compras[0]\n return p.estado in [\"ST\", \"VD\", \"OL\", \"VT\"] and compra.firma == \"\"\n\n@register.filter(name='editable')\ndef editable(p):\n return p.estado in [\"ST\", \"OL\", \"VT\"]\n\n\n@register.simple_tag(name='get_estado_value')\ndef get_estado_value(test_id, p_id, estado):\n testeos = Testeo.objects.filter(Q(descripcion__pk=test_id) &\n Q(producto__pk=p_id))\n send = \"\"\n if len(testeos) > 0 and testeos[0].estado == estado:\n send = \"selected\"\n\n return send\n\n@register.filter(name='addattrs')\ndef addattrs(field, args):\n attr = {}\n try:\n args_parse = args.replace(\"'\", '\"')\n attr = json.loads(args_parse)\n except Exception as error:\n print(error)\n return field.as_widget(attrs=attr)\n\n@register.filter('klass')\ndef klass(ob):\n return ob.field.widget.__class__.__name__\n\n\n@register.filter('display')\ndef display(form, value):\n return dict(form.field.choices)[value]\n\n@register.filter('modelo')\ndef modelo(p):\n if p.modelo != None:\n return str(p.modelo)\n else:\n return p.detalle\n\n\n@register.filter('marca')\ndef marca(p):\n if p.modelo != None:\n return str(p.modelo.marca)\n else:\n return \"\"\n"},"avg_line_length":{"kind":"number","value":24.9801324503,"string":"24.980132"},"max_line_length":{"kind":"number","value":72,"string":"72"},"alphanum_fraction":{"kind":"number","value":0.6569459173,"string":"0.656946"},"count_classes":{"kind":"number","value":0,"string":"0"},"score_classes":{"kind":"number","value":0,"string":"0"},"count_generators":{"kind":"number","value":0,"string":"0"},"score_generators":{"kind":"number","value":0,"string":"0"},"count_decorators":{"kind":"number","value":3202,"string":"3,202"},"score_decorators":{"kind":"number","value":0.8479872881355932,"string":"0.847987"},"count_async_functions":{"kind":"number","value":0,"string":"0"},"score_async_functions":{"kind":"number","value":0,"string":"0"},"count_documentation":{"kind":"number","value":673,"string":"673"},"score_documentation":{"kind":"number","value":0.17823093220338984,"string":"0.178231"}}},{"rowIdx":965,"cells":{"hexsha":{"kind":"string","value":"6ad59b00bcc766f57088e62e448110d102b95431"},"size":{"kind":"number","value":17165,"string":"17,165"},"ext":{"kind":"string","value":"py"},"lang":{"kind":"string","value":"Python"},"max_stars_repo_path":{"kind":"string","value":"doc/tutorial/using_gpu_solution_1.py"},"max_stars_repo_name":{"kind":"string","value":"abdalazizrashid/Theano-PyMC"},"max_stars_repo_head_hexsha":{"kind":"string","value":"90fa750461e91fb6281d494ae86404e2153fd7eb"},"max_stars_repo_licenses":{"kind":"list like","value":["BSD-3-Clause"],"string":"[\n \"BSD-3-Clause\"\n]"},"max_stars_count":{"kind":"null"},"max_stars_repo_stars_event_min_datetime":{"kind":"null"},"max_stars_repo_stars_event_max_datetime":{"kind":"null"},"max_issues_repo_path":{"kind":"string","value":"doc/tutorial/using_gpu_solution_1.py"},"max_issues_repo_name":{"kind":"string","value":"abdalazizrashid/Theano-PyMC"},"max_issues_repo_head_hexsha":{"kind":"string","value":"90fa750461e91fb6281d494ae86404e2153fd7eb"},"max_issues_repo_licenses":{"kind":"list like","value":["BSD-3-Clause"],"string":"[\n \"BSD-3-Clause\"\n]"},"max_issues_count":{"kind":"null"},"max_issues_repo_issues_event_min_datetime":{"kind":"null"},"max_issues_repo_issues_event_max_datetime":{"kind":"null"},"max_forks_repo_path":{"kind":"string","value":"doc/tutorial/using_gpu_solution_1.py"},"max_forks_repo_name":{"kind":"string","value":"abdalazizrashid/Theano-PyMC"},"max_forks_repo_head_hexsha":{"kind":"string","value":"90fa750461e91fb6281d494ae86404e2153fd7eb"},"max_forks_repo_licenses":{"kind":"list like","value":["BSD-3-Clause"],"string":"[\n \"BSD-3-Clause\"\n]"},"max_forks_count":{"kind":"null"},"max_forks_repo_forks_event_min_datetime":{"kind":"null"},"max_forks_repo_forks_event_max_datetime":{"kind":"null"},"content":{"kind":"string","value":"#!/usr/bin/env python\n# Aesara tutorial\n# Solution to Exercise in section 'Using the GPU'\n\n\n# 1. Raw results\n\n\nimport numpy as np\n\nimport aesara\nimport aesara.tensor as tt\n\n\naesara.config.floatX = \"float32\"\n\nrng = np.random\n\nN = 400\nfeats = 784\nD = (\n rng.randn(N, feats).astype(aesara.config.floatX),\n rng.randint(size=N, low=0, high=2).astype(aesara.config.floatX),\n)\ntraining_steps = 10000\n\n# Declare Aesara symbolic variables\nx = aesara.shared(D[0], name=\"x\")\ny = aesara.shared(D[1], name=\"y\")\nw = aesara.shared(rng.randn(feats).astype(aesara.config.floatX), name=\"w\")\nb = aesara.shared(np.asarray(0.0, dtype=aesara.config.floatX), name=\"b\")\nx.tag.test_value = D[0]\ny.tag.test_value = D[1]\n# print \"Initial model:\"\n# print w.get_value(), b.get_value()\n\n# Construct Aesara expression graph\np_1 = 1 / (1 + tt.exp(-tt.dot(x, w) - b)) # Probability of having a one\nprediction = p_1 > 0.5 # The prediction that is done: 0 or 1\nxent = -y * tt.log(p_1) - (1 - y) * tt.log(1 - p_1) # Cross-entropy\ncost = tt.cast(xent.mean(), \"float32\") + 0.01 * (w ** 2).sum() # The cost to optimize\ngw, gb = tt.grad(cost, [w, b])\n\n# Compile expressions to functions\ntrain = aesara.function(\n inputs=[],\n outputs=[prediction, xent],\n updates=[(w, w - 0.01 * gw), (b, b - 0.01 * gb)],\n name=\"train\",\n)\npredict = aesara.function(inputs=[], outputs=prediction, name=\"predict\")\n\nif any(\n [\n n.op.__class__.__name__ in [\"Gemv\", \"CGemv\", \"Gemm\", \"CGemm\"]\n for n in train.maker.fgraph.toposort()\n ]\n):\n print(\"Used the cpu\")\nelif any(\n [\n n.op.__class__.__name__ in [\"GpuGemm\", \"GpuGemv\"]\n for n in train.maker.fgraph.toposort()\n ]\n):\n print(\"Used the gpu\")\nelse:\n print(\"ERROR, not able to tell if aesara used the cpu or the gpu\")\n print(train.maker.fgraph.toposort())\n\nfor i in range(training_steps):\n pred, err = train()\n# print \"Final model:\"\n# print w.get_value(), b.get_value()\n\nprint(\"target values for D\")\nprint(D[1])\n\nprint(\"prediction on D\")\nprint(predict())\n\n\"\"\"\n\n# 2. Profiling\n\n\n# 2.1 Profiling for CPU computations\n\n# In your terminal, type:\n$ THEANO_FLAGS=profile=True,device=cpu python using_gpu_solution_1.py\n\n# You'll see first the output of the script:\nUsed the cpu\ntarget values for D\nprediction on D\n\n# Followed by the output of profiling.. You'll see profiling results for each function\n# in the script, followed by a summary for all functions.\n# We'll show here only the summary:\n\nResults were produced using an Intel(R) Core(TM) i7-5930K CPU @ 3.50GHz\n\nFunction profiling\n==================\n Message: Sum of all(2) printed profiles at exit excluding Scan op profile.\n Time in 10001 calls to Function.__call__: 1.300452e+00s\n Time in Function.fn.__call__: 1.215823e+00s (93.492%)\n Time in thunks: 1.157602e+00s (89.015%)\n Total compile time: 8.922548e-01s\n Number of Apply nodes: 17\n Aesara Optimizer time: 6.270301e-01s\n Aesara validate time: 5.993605e-03s\n Aesara Linker time (includes C, CUDA code generation/compiling): 2.949309e-02s\n Import time 3.543139e-03s\n\nTime in all call to aesara.grad() 1.848292e-02s\nTime since aesara import 2.864s\nClass\n---\n<% time>