NERDDISCO commited on
Commit
5786921
β€’
1 Parent(s): 82bf191

feat: added getting-started, huggingface summarization, boxes

Browse files
README.md CHANGED
@@ -1,25 +1,23 @@
1
  ---
2
- title: Next.js Docker Starter
3
  emoji: "\U0001F433\U0001F918"
4
- colorFrom: purple
5
- colorTo: blue
6
  sdk: docker
7
  pinned: false
8
  license: agpl-3.0
9
  app_port: 3000
10
  ---
11
-
12
- # nextjs-docker-starter
13
 
14
  This starter can be used to run [Next.js](https://nextjs.org/) using [Docker](https://huggingface.co/docs/hub/spaces-sdks-docker) in πŸ€— [Spaces](https://huggingface.co/spaces).
15
 
16
  <!-- toc -->
17
 
18
- - [nextjs-docker-starter](#nextjs-docker-starter)
19
- - [Development](#development)
20
- - [Use the Docker container locally](#use-the-docker-container-locally)
21
- - [Dockerize an existing project](#dockerize-an-existing-project)
22
- - [Manage your Space via GitHub](#manage-your-space-via-github)
23
 
24
  <!-- tocstop -->
25
 
@@ -71,3 +69,4 @@ If you want to use all the features for collaborative development on GitHub, but
71
  This should force push changes in the **main** branch from GitHub into your πŸ€— space.
72
 
73
  For further information, you can check out the [guide on Hugging Face](https://huggingface.co/docs/hub/spaces-github-actions).
 
 
1
  ---
2
+ title: Next.js on πŸ€— Spaces
3
  emoji: "\U0001F433\U0001F918"
4
+ colorFrom: blue
5
+ colorTo: yellow
6
  sdk: docker
7
  pinned: false
8
  license: agpl-3.0
9
  app_port: 3000
10
  ---
11
+ <h1 align="center">nextjs-docker-starter</h1>
 
12
 
13
  This starter can be used to run [Next.js](https://nextjs.org/) using [Docker](https://huggingface.co/docs/hub/spaces-sdks-docker) in πŸ€— [Spaces](https://huggingface.co/spaces).
14
 
15
  <!-- toc -->
16
 
17
+ - [Development](#development)
18
+ - [Use the Docker container locally](#use-the-docker-container-locally)
19
+ - [Dockerize an existing project](#dockerize-an-existing-project)
20
+ - [Manage your Space via GitHub](#manage-your-space-via-github)
 
21
 
22
  <!-- tocstop -->
23
 
 
69
  This should force push changes in the **main** branch from GitHub into your πŸ€— space.
70
 
71
  For further information, you can check out the [guide on Hugging Face](https://huggingface.co/docs/hub/spaces-github-actions).
72
+
package-lock.json CHANGED
@@ -13,6 +13,7 @@
13
  "@emotion/react": "11.10.6",
14
  "@emotion/server": "11.10.0",
15
  "@emotion/styled": "11.10.6",
 
16
  "@mui/icons-material": "5.11.16",
17
  "@mui/material": "5.12.0",
18
  "@types/node": "20.1.4",
@@ -374,6 +375,14 @@
374
  "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
375
  }
376
  },
 
 
 
 
 
 
 
 
377
  "node_modules/@humanwhocodes/config-array": {
378
  "version": "0.11.8",
379
  "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz",
 
13
  "@emotion/react": "11.10.6",
14
  "@emotion/server": "11.10.0",
15
  "@emotion/styled": "11.10.6",
16
+ "@huggingface/inference": "2.3.3",
17
  "@mui/icons-material": "5.11.16",
18
  "@mui/material": "5.12.0",
19
  "@types/node": "20.1.4",
 
375
  "node": "^12.22.0 || ^14.17.0 || >=16.0.0"
376
  }
377
  },
378
+ "node_modules/@huggingface/inference": {
379
+ "version": "2.3.3",
380
+ "resolved": "https://registry.npmjs.org/@huggingface/inference/-/inference-2.3.3.tgz",
381
+ "integrity": "sha512-/2vl+RIazkpSVQiTq7dPL8trgFjXQOnEzfJo6QL5y2/kCiHB+PPWzCe9qsLKt0/R46eMzG1PuCgAOlCO+vd11g==",
382
+ "engines": {
383
+ "node": ">=18"
384
+ }
385
+ },
386
  "node_modules/@humanwhocodes/config-array": {
387
  "version": "0.11.8",
388
  "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz",
package.json CHANGED
@@ -24,9 +24,10 @@
24
  },
25
  "dependencies": {
26
  "@emotion/cache": "11.10.7",
27
- "@emotion/server": "11.10.0",
28
  "@emotion/react": "11.10.6",
 
29
  "@emotion/styled": "11.10.6",
 
30
  "@mui/icons-material": "5.11.16",
31
  "@mui/material": "5.12.0",
32
  "@types/node": "20.1.4",
 
24
  },
25
  "dependencies": {
26
  "@emotion/cache": "11.10.7",
 
27
  "@emotion/react": "11.10.6",
28
+ "@emotion/server": "11.10.0",
29
  "@emotion/styled": "11.10.6",
30
+ "@huggingface/inference": "2.3.3",
31
  "@mui/icons-material": "5.11.16",
32
  "@mui/material": "5.12.0",
33
  "@types/node": "20.1.4",
src/components/boxes.tsx ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Paper, PaperProps } from "@mui/material";
2
+ import { styled } from "@mui/material/styles";
3
+
4
+ export const SectionBox = styled(Paper)<PaperProps>(({ theme }) => ({
5
+ display: "flex",
6
+ alignItems: "center",
7
+ justifyContent: "center",
8
+ padding: 15,
9
+ border: `5px solid transparent`,
10
+ borderImage: `linear-gradient(to bottom right, #b827fc 0%, #2c90fc 25%, #b8fd33 50%, #fec837 75%, #fd1892 100%)`,
11
+ borderImageSlice: 1,
12
+ }));
13
+
14
+ export const HighlightBox = styled(Paper)<PaperProps>(({ theme }) => ({
15
+ display: "flex",
16
+ alignItems: "center",
17
+ justifyContent: "center",
18
+ padding: 10,
19
+ borderBottom: `3px solid transparent`,
20
+ borderImage: `linear-gradient(to bottom right, #b827fc 0%, #2c90fc 25%, #b8fd33 50%, #fec837 75%, #fd1892 100%)`,
21
+ borderImageSlice: 1,
22
+ }));
src/components/example-components.tsx ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Typography } from "@mui/material";
2
+ import Huggingface from "./huggingface/huggingface";
3
+ import { SectionBox } from "./boxes";
4
+
5
+ export default function ExampleComponents() {
6
+ return (
7
+ <>
8
+ <SectionBox>
9
+ <Typography component="h2" variant="h3" sx={{ textAlign: "center" }}>
10
+ Example Components
11
+ </Typography>
12
+ </SectionBox>
13
+ <Huggingface />
14
+ </>
15
+ );
16
+ }
src/components/footer.tsx CHANGED
@@ -11,22 +11,18 @@ const Footer = () => {
11
  justifyContent: "center",
12
  gap: 1,
13
  alignItems: "center",
 
 
14
  }}
15
  >
16
- <Link href="https://failfa.st" display="flex" alignItems="center">
17
- Powered by{" "}
18
- <Image src="/failfast.svg" alt="failfast Logo" width="32" height="32" />
19
- </Link>
20
-
21
- <Divider orientation="vertical" flexItem />
22
-
23
  <Link
24
- href="https://github.com/failfa-st/nextjs-docker-starter"
25
- target="_blank"
26
- rel="noopener noreferrer"
 
27
  >
28
- {" "}
29
- Contribute on GitHub
30
  </Link>
31
  </Box>
32
  );
 
11
  justifyContent: "center",
12
  gap: 1,
13
  alignItems: "center",
14
+ mt: 8,
15
+ mb: 4,
16
  }}
17
  >
 
 
 
 
 
 
 
18
  <Link
19
+ href="https://failfa.st"
20
+ display="flex"
21
+ alignItems="center"
22
+ rel="noopener"
23
  >
24
+ <Box sx={{ mr: 0.5 }}>Powered by</Box>{" "}
25
+ <Image src="/failfast.svg" alt="failfast Logo" width="32" height="32" />
26
  </Link>
27
  </Box>
28
  );
src/components/getting-started.tsx ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ Button,
3
+ Grid,
4
+ Link,
5
+ List,
6
+ ListItem,
7
+ ListItemIcon,
8
+ ListItemText,
9
+ ListSubheader,
10
+ Paper,
11
+ Stack,
12
+ Typography,
13
+ } from "@mui/material";
14
+
15
+ import ViewQuiltIcon from "@mui/icons-material/ViewQuilt";
16
+ import SailingIcon from "@mui/icons-material/Sailing";
17
+ import LightModeIcon from "@mui/icons-material/LightMode";
18
+ import SentimentVerySatisfiedIcon from "@mui/icons-material/SentimentVerySatisfied";
19
+ import ContentCopyIcon from "@mui/icons-material/ContentCopy";
20
+ import LinkIcon from "@mui/icons-material/Link";
21
+ import SyncIcon from "@mui/icons-material/Sync";
22
+ import { HighlightBox } from "./boxes";
23
+
24
+ export default function GettingStarted() {
25
+ return (
26
+ <>
27
+ <Stack sx={{ alignItems: "center", mb: 2 }}>
28
+ <HighlightBox>
29
+ <Typography variant="h5" component="p">
30
+ Run your ML demo with ease in a Next.js/React environment
31
+ </Typography>
32
+ </HighlightBox>
33
+ </Stack>
34
+
35
+ <Grid container spacing={2}>
36
+ <Grid item sm={8} lg={6}>
37
+ <Paper sx={{ p: 2 }}>
38
+ <List disablePadding>
39
+ <ListSubheader>Features</ListSubheader>
40
+
41
+ <ListItem>
42
+ <ListItemIcon>
43
+ <SentimentVerySatisfiedIcon />
44
+ </ListItemIcon>
45
+ <ListItemText>
46
+ <Link
47
+ href="https://huggingface.co/docs/huggingface.js/index"
48
+ target="_blank"
49
+ rel="noopener"
50
+ >
51
+ huggingface.js
52
+ </Link>{" "}
53
+ components (WIP)
54
+ </ListItemText>
55
+ </ListItem>
56
+
57
+ <ListItem>
58
+ <ListItemIcon>
59
+ <LinkIcon />
60
+ </ListItemIcon>
61
+ <ListItemText>
62
+ <Link
63
+ href="https://js.langchain.com/docs"
64
+ target="_blank"
65
+ rel="noopener"
66
+ >
67
+ langchain.js
68
+ </Link>{" "}
69
+ components (WIP)
70
+ </ListItemText>
71
+ </ListItem>
72
+
73
+ <ListItem>
74
+ <ListItemIcon>
75
+ <ViewQuiltIcon />
76
+ </ListItemIcon>
77
+ <ListItemText>
78
+ Rapid prototyping with{" "}
79
+ <Link
80
+ href="https://mui.com/material-ui/getting-started/overview/"
81
+ target="_blank"
82
+ rel="noopener"
83
+ >
84
+ MUI
85
+ </Link>
86
+ </ListItemText>
87
+ </ListItem>
88
+ <ListItem>
89
+ <ListItemIcon>
90
+ <LightModeIcon />
91
+ </ListItemIcon>
92
+ <ListItemText>
93
+ Dark / light theme based on system preferences
94
+ </ListItemText>
95
+ </ListItem>
96
+ <ListItem>
97
+ <ListItemIcon>
98
+ <SyncIcon />
99
+ </ListItemIcon>
100
+ <ListItemText>
101
+ Sync your repo on GitHub with your πŸ€— Space via a GitHub
102
+ Action
103
+ </ListItemText>
104
+ </ListItem>
105
+ <ListItem>
106
+ <ListItemIcon>
107
+ <SailingIcon />
108
+ </ListItemIcon>
109
+ <ListItemText>Runs in Docker or localhost</ListItemText>
110
+ </ListItem>
111
+ </List>
112
+ </Paper>
113
+ </Grid>
114
+
115
+ <Grid item sm={4} lg={3}>
116
+ <Stack gap={2}>
117
+ <Paper sx={{ p: 2 }}>
118
+ <Stack gap={2}>
119
+ <Button
120
+ startIcon={<ContentCopyIcon />}
121
+ variant="contained"
122
+ href="https://huggingface.co/spaces/failfast/nextjs-docker-starter?duplicate=true"
123
+ target="_blank"
124
+ rel="noopener"
125
+ >
126
+ Duplicate space
127
+ </Button>
128
+
129
+ <Button
130
+ href="https://github.com/failfa-st/nextjs-docker-starter"
131
+ target="_blank"
132
+ rel="noopener"
133
+ >
134
+ Contribute on GitHub
135
+ </Button>
136
+ </Stack>
137
+ </Paper>
138
+
139
+ <Paper sx={{ p: 2 }}>
140
+ <Typography variant="body1">
141
+ Get started with the{" "}
142
+ <Link href="https://huggingface.co/spaces/failfast/nextjs-docker-starter/blob/main/README.md">
143
+ README
144
+ </Link>
145
+ </Typography>
146
+ </Paper>
147
+
148
+ <Paper sx={{ p: 2 }}>
149
+ <Typography variant="body1">
150
+ Something missing?{" "}
151
+ <Link href="https://huggingface.co/spaces/failfast/nextjs-docker-starter/discussions">
152
+ Please let us know!
153
+ </Link>
154
+ </Typography>
155
+ </Paper>
156
+ </Stack>
157
+ </Grid>
158
+ </Grid>
159
+ </>
160
+ );
161
+ }
src/components/huggingface/huggingface.tsx ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Typography } from "@mui/material";
2
+ import { HfInference } from "@huggingface/inference";
3
+ import { useEffect } from "react";
4
+ import Summarization from "./inference/summarization";
5
+
6
+ export type InferenceProps = {
7
+ token?: string;
8
+ model: string;
9
+ };
10
+
11
+ export default function Huggingface() {
12
+ return (
13
+ <>
14
+ <Typography component="h4" variant="h4">
15
+ huggingface.js
16
+ </Typography>
17
+
18
+ <Typography component="h5" variant="h5">
19
+ Summarization
20
+ </Typography>
21
+ <Summarization model="facebook/bart-large-cnn" />
22
+ </>
23
+ );
24
+ }
src/components/huggingface/inference/summarization.tsx ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ Alert,
3
+ Button,
4
+ IconButton,
5
+ InputAdornment,
6
+ Paper,
7
+ Stack,
8
+ TextField,
9
+ } from "@mui/material";
10
+ import { useEffect, useRef, useState } from "react";
11
+ import { HfInference } from "@huggingface/inference";
12
+ import { Visibility, VisibilityOff } from "@mui/icons-material";
13
+ import { InferenceProps } from "../huggingface";
14
+
15
+ export default function Summarization(props: InferenceProps) {
16
+ const { model } = props;
17
+
18
+ const [token, setToken] = useState<string>("");
19
+ const [summary, setSummary] = useState<string>("");
20
+ const [error, setError] = useState<string>("");
21
+ const [showToken, setShowToken] = useState(false);
22
+
23
+ const inference = useRef<HfInference | null>(null);
24
+
25
+ useEffect(() => {
26
+ inference.current = new HfInference(token);
27
+ }, [token]);
28
+
29
+ const handleSubmit = (event: any) => {
30
+ event.preventDefault();
31
+ const data = new FormData(event.currentTarget);
32
+
33
+ setToken(data.get("token") as string);
34
+
35
+ const text = data.get("text") as string;
36
+
37
+ call(text);
38
+ };
39
+
40
+ const handleShowToken = () => setShowToken(!showToken);
41
+
42
+ const call = async (inputs: string) => {
43
+ try {
44
+ const response = await inference.current?.summarization({
45
+ model,
46
+ inputs,
47
+ parameters: {
48
+ max_length: 100,
49
+ },
50
+ });
51
+
52
+ setSummary(response?.summary_text as string);
53
+ setError("");
54
+ } catch (error) {
55
+ if (error instanceof Error) {
56
+ setError(error.message);
57
+ } else {
58
+ setError("An unknown error occurred");
59
+ }
60
+ }
61
+ };
62
+
63
+ return (
64
+ <>
65
+ <Paper component="form" onSubmit={handleSubmit} sx={{ padding: "1em" }}>
66
+ <Stack spacing={2}>
67
+ <TextField
68
+ variant="filled"
69
+ label="HF Token"
70
+ name="token"
71
+ type={showToken ? "text" : "password"}
72
+ InputProps={{
73
+ endAdornment: (
74
+ <InputAdornment position="end">
75
+ <IconButton onClick={handleShowToken}>
76
+ {showToken ? <Visibility /> : <VisibilityOff />}
77
+ </IconButton>
78
+ </InputAdornment>
79
+ ),
80
+ }}
81
+ />
82
+ <TextField
83
+ variant="filled"
84
+ label="Text to summarize"
85
+ multiline
86
+ required
87
+ minRows={4}
88
+ name="text"
89
+ />
90
+ <Button type="submit" variant="contained">
91
+ Run
92
+ </Button>
93
+
94
+ {error && <Alert severity="error">{error}</Alert>}
95
+
96
+ <TextField
97
+ variant="outlined"
98
+ label="Summary"
99
+ multiline
100
+ minRows={2}
101
+ name="text"
102
+ value={summary}
103
+ />
104
+ </Stack>
105
+ </Paper>
106
+ </>
107
+ );
108
+ }
src/components/title.tsx CHANGED
@@ -8,7 +8,7 @@ export default function Title() {
8
  display: "flex",
9
  justifyContent: "center",
10
  alignItems: "center",
11
- minHeight: "50vh",
12
  }}
13
  >
14
  <Typography variant="h2" component="h1">
@@ -20,14 +20,6 @@ export default function Title() {
20
  >
21
  Next.js
22
  </Link>{" "}
23
- in{" "}
24
- <Link
25
- href="https://www.docker.com"
26
- target="_blank"
27
- rel="noopener noreferrer"
28
- >
29
- Docker
30
- </Link>{" "}
31
  on πŸ€—{" "}
32
  <Link
33
  href="https://huggingface.co/spaces"
@@ -36,7 +28,6 @@ export default function Title() {
36
  >
37
  Spaces
38
  </Link>
39
- !
40
  </Typography>
41
  </Box>
42
  );
 
8
  display: "flex",
9
  justifyContent: "center",
10
  alignItems: "center",
11
+ minHeight: "20vh",
12
  }}
13
  >
14
  <Typography variant="h2" component="h1">
 
20
  >
21
  Next.js
22
  </Link>{" "}
 
 
 
 
 
 
 
 
23
  on πŸ€—{" "}
24
  <Link
25
  href="https://huggingface.co/spaces"
 
28
  >
29
  Spaces
30
  </Link>
 
31
  </Typography>
32
  </Box>
33
  );
src/lib/theme.ts CHANGED
@@ -31,10 +31,10 @@ const theme = extendTheme({
31
  dark: {
32
  palette: {
33
  primary: {
34
- main: "#00d720",
35
  },
36
  secondary: {
37
- main: "#cc06ed",
38
  },
39
  },
40
  },
@@ -42,6 +42,15 @@ const theme = extendTheme({
42
  typography: {
43
  ...roboto.style,
44
  },
 
 
 
 
 
 
 
 
 
45
  });
46
 
47
  export default theme;
 
31
  dark: {
32
  palette: {
33
  primary: {
34
+ main: "#2c90fc",
35
  },
36
  secondary: {
37
+ main: "#b827fc",
38
  },
39
  },
40
  },
 
42
  typography: {
43
  ...roboto.style,
44
  },
45
+ components: {
46
+ MuiLink: {
47
+ styleOverrides: {
48
+ root: {
49
+ textDecoration: "none",
50
+ },
51
+ },
52
+ },
53
+ },
54
  });
55
 
56
  export default theme;
src/pages/index.tsx CHANGED
@@ -2,6 +2,10 @@ import Head from "next/head";
2
  import Container from "@mui/material/Container";
3
  import Footer from "@/components/footer";
4
  import Title from "@/components/title";
 
 
 
 
5
 
6
  export default function Home() {
7
  return (
@@ -13,7 +17,13 @@ export default function Home() {
13
  </Head>
14
 
15
  <Container component="main" sx={{ minHeight: "90vh" }}>
16
- <Title />
 
 
 
 
 
 
17
  </Container>
18
 
19
  <Footer />
 
2
  import Container from "@mui/material/Container";
3
  import Footer from "@/components/footer";
4
  import Title from "@/components/title";
5
+ import Huggingface from "@/components/huggingface/huggingface";
6
+ import GettingStarted from "@/components/getting-started";
7
+ import ExampleComponents from "@/components/example-components";
8
+ import { Stack } from "@mui/material";
9
 
10
  export default function Home() {
11
  return (
 
17
  </Head>
18
 
19
  <Container component="main" sx={{ minHeight: "90vh" }}>
20
+ <Stack spacing={4} useFlexGap>
21
+ <Title />
22
+
23
+ <GettingStarted />
24
+
25
+ <ExampleComponents />
26
+ </Stack>
27
  </Container>
28
 
29
  <Footer />