Spaces:
Running
Running
Download frontend/src/components/PyTorchCode.tsx from philippyt/ablation-lab: direct link, hf CLI and curl.
- Browser
- Download file 1.45 kB
-
https://huggingface.co/spaces/philippyt/ablation-lab/resolve/main/frontend/src/components/PyTorchCode.tsx
- Command line
-
hf download hf://spaces/philippyt/ablation-lab/frontend/src/components/PyTorchCode.tsx
-
curl -L -o PyTorchCode.tsx https://huggingface.co/spaces/philippyt/ablation-lab/resolve/main/frontend/src/components/PyTorchCode.tsx
1.45 kB
| import { useState } from "preact/hooks"; | |
| import { signal } from "@preact/signals"; | |
| import { config } from "../state"; | |
| import { composeCode, highlightPython } from "../content/code"; | |
| export const codeModalOpen = signal<boolean>(false); | |
| export function PyTorchCodeModal() { | |
| if (!codeModalOpen.value) return null; | |
| const cfg = config.value; | |
| const code = composeCode(cfg); | |
| const html = highlightPython(code); | |
| const [copied, setCopied] = useState(false); | |
| async function copy() { | |
| try { | |
| await navigator.clipboard.writeText(code); | |
| setCopied(true); | |
| setTimeout(() => setCopied(false), 1200); | |
| } catch { | |
| setCopied(false); | |
| } | |
| } | |
| return ( | |
| <div class="modal-backdrop" onClick={() => (codeModalOpen.value = false)}> | |
| <div class="modal pytorch-modal" onClick={(e) => e.stopPropagation()}> | |
| <div class="modal-head"> | |
| <div> | |
| <div class="meta">pytorch</div> | |
| <h3>Architecture in code</h3> | |
| <p class="short">Your configured architecture as a self-contained PyTorch script.</p> | |
| </div> | |
| <div class="modal-actions"> | |
| <button class="ghost" onClick={copy}>{copied ? "copied" : "copy"}</button> | |
| <button class="close" onClick={() => (codeModalOpen.value = false)}>×</button> | |
| </div> | |
| </div> | |
| <pre class="code"><code dangerouslySetInnerHTML={{ __html: html }} /></pre> | |
| </div> | |
| </div> | |
| ); | |
| } | |