Update quickstarts [ci skip]

This commit is contained in:
Ines Montani 2020-10-05 21:05:41 +02:00
parent be99f1e4de
commit 9aa07ad001
3 changed files with 62 additions and 18 deletions

View File

@ -38,7 +38,7 @@
cursor: pointer cursor: pointer
display: inline-block display: inline-block
padding: 0.35rem 0.5rem 0.25rem 0 padding: 0.35rem 0.5rem 0.25rem 0
margin: 0 1rem 0.75rem 0 margin: 0 1rem 0.5rem 0
font-size: var(--font-size-xs) font-size: var(--font-size-xs)
font-weight: bold font-weight: bold
@ -73,16 +73,19 @@
background: var(--color-theme) background: var(--color-theme)
.checkbox + &:before .checkbox + &:before
$size: 18px
content: "" content: ""
display: inline-block display: inline-block
width: 20px width: $size
height: 20px height: $size
border: 1px solid var(--color-subtle) border: 1px solid var(--color-subtle)
vertical-align: middle vertical-align: middle
margin-right: 0.5rem margin-right: 0.5rem
cursor: pointer cursor: pointer
border-radius: var(--border-radius) border-radius: $size / 4
background: var(--color-back) background: var(--color-back)
position: relative
top: -1px
.checkbox:checked + &:before .checkbox:checked + &:before
// Embed "check" icon here for simplicity // Embed "check" icon here for simplicity

View File

@ -4,6 +4,8 @@ import { StaticQuery, graphql } from 'gatsby'
import { Quickstart, QS } from '../components/quickstart' import { Quickstart, QS } from '../components/quickstart'
import { repo } from '../components/util' import { repo } from '../components/util'
const DEFAULT_MODELS = ['en']
const DEFAULT_OPT = 'efficiency'
const DEFAULT_HARDWARE = 'cpu' const DEFAULT_HARDWARE = 'cpu'
const DEFAULT_CUDA = 'cuda100' const DEFAULT_CUDA = 'cuda100'
const CUDA = { const CUDA = {
@ -68,9 +70,13 @@ const QuickstartInstall = ({ id, title }) => {
const [train, setTrain] = useState(false) const [train, setTrain] = useState(false)
const [hardware, setHardware] = useState(DEFAULT_HARDWARE) const [hardware, setHardware] = useState(DEFAULT_HARDWARE)
const [cuda, setCuda] = useState(DEFAULT_CUDA) const [cuda, setCuda] = useState(DEFAULT_CUDA)
const [selectedModels, setModels] = useState(DEFAULT_MODELS)
const [efficiency, setEfficiency] = useState(DEFAULT_OPT === 'efficiency')
const setters = { const setters = {
hardware: v => (Array.isArray(v) ? setHardware(v[0]) : setCuda(v)), hardware: v => (Array.isArray(v) ? setHardware(v[0]) : setCuda(v)),
config: v => setTrain(v.includes('train')), config: v => setTrain(v.includes('train')),
models: setModels,
optimize: v => setEfficiency(v.includes('efficiency')),
} }
const showDropdown = { const showDropdown = {
hardware: () => hardware === 'gpu', hardware: () => hardware === 'gpu',
@ -89,13 +95,37 @@ const QuickstartInstall = ({ id, title }) => {
...DATA, ...DATA,
{ {
id: 'models', id: 'models',
title: 'Trained Pipelines', title: 'Trained pipelines',
multiple: true, multiple: true,
options: models options: models
.sort((a, b) => a.name.localeCompare(b.name)) .sort((a, b) => a.name.localeCompare(b.name))
.map(({ code, name }) => ({ id: code, title: name })), .map(({ code, name }) => ({
id: code,
title: name,
checked: DEFAULT_MODELS.includes(code),
})),
}, },
] ]
if (selectedModels.length) {
data.push({
id: 'optimize',
title: 'Select pipeline for',
options: [
{
id: 'efficiency',
title: 'efficiency',
checked: DEFAULT_OPT === 'efficiency',
help: 'Faster and smaller pipeline, but less accurate',
},
{
id: 'accuracy',
title: 'accuracy',
checked: DEFAULT_OPT === 'accuracy',
help: 'Larger and slower pipeline, but more accurate',
},
],
})
}
return ( return (
<Quickstart <Quickstart
data={data} data={data}
@ -149,11 +179,14 @@ const QuickstartInstall = ({ id, title }) => {
conda install -c conda-forge spacy-lookups-data conda install -c conda-forge spacy-lookups-data
</QS> </QS>
{models.map(({ code, models: modelOptions }) => ( {models.map(({ code, models: modelOptions }) => {
const pkg = modelOptions[efficiency ? 0 : modelOptions.length - 1]
return (
<QS models={code} key={code}> <QS models={code} key={code}>
python -m spacy download {modelOptions[0]} python -m spacy download {pkg}
</QS> </QS>
))} )
})}
</Quickstart> </Quickstart>
) )
}} }}

View File

@ -31,25 +31,33 @@ const data = [
}, },
{ {
id: 'optimize', id: 'optimize',
title: 'Optimize for', title: 'Select for',
help:
'Optimize for efficiency (faster & smaller model) or higher accuracy (larger & slower model)',
options: [ options: [
{ id: 'efficiency', title: 'efficiency', checked: DEFAULT_OPT === 'efficiency' }, {
{ id: 'accuracy', title: 'accuracy', checked: DEFAULT_OPT === 'accuracy' }, id: 'efficiency',
title: 'efficiency',
checked: DEFAULT_OPT === 'efficiency',
help: 'Faster and smaller pipeline, but less accurate',
},
{
id: 'accuracy',
title: 'accuracy',
checked: DEFAULT_OPT === 'accuracy',
help: 'Larger and slower pipeline, but more accurate',
},
], ],
}, },
{ {
id: 'config', id: 'config',
title: 'Options', title: 'Options',
multiple: true, multiple: true,
options: [{ id: 'example', title: 'Show usage example' }], options: [{ id: 'example', title: 'Show text example' }],
}, },
] ]
const QuickstartInstall = ({ id, title, description, children }) => { const QuickstartInstall = ({ id, title, description, children }) => {
const [lang, setLang] = useState(DEFAULT_LANG) const [lang, setLang] = useState(DEFAULT_LANG)
const [efficiency, setEfficiency] = useState(DEFAULT_OPT) const [efficiency, setEfficiency] = useState(DEFAULT_OPT === 'efficiency')
const setters = { const setters = {
lang: setLang, lang: setLang,
optimize: v => setEfficiency(v.includes('efficiency')), optimize: v => setEfficiency(v.includes('efficiency')),