Commit
·
6ad1eb1
verified
·
0
Parent(s):
Initial commit
Browse files- .gitattributes +35 -0
- Dockerfile +70 -0
- README.md +42 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Adapted from https://github.com/vercel/next.js/blob/canary/examples/with-docker/Dockerfile
|
| 2 |
+
# For more information, see https://nextjs.org/docs/pages/building-your-application/deploying#docker-image
|
| 3 |
+
|
| 4 |
+
# Use a base image for building
|
| 5 |
+
FROM node:18-slim AS base
|
| 6 |
+
|
| 7 |
+
# Install git
|
| 8 |
+
RUN apt-get update && apt-get install -y git
|
| 9 |
+
|
| 10 |
+
# Clone the repository and navigate to the next-server folder
|
| 11 |
+
WORKDIR /app
|
| 12 |
+
RUN git clone https://github.com/huggingface/transformers.js-examples .
|
| 13 |
+
|
| 14 |
+
# Set the working directory to the next-server folder
|
| 15 |
+
WORKDIR /app/next-server
|
| 16 |
+
|
| 17 |
+
# Install dependencies only when needed
|
| 18 |
+
FROM base AS deps
|
| 19 |
+
|
| 20 |
+
# Install dependencies based on the preferred package manager
|
| 21 |
+
RUN \
|
| 22 |
+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
|
| 23 |
+
elif [ -f package-lock.json ]; then npm ci; \
|
| 24 |
+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
|
| 25 |
+
else echo "Lockfile not found." && exit 1; \
|
| 26 |
+
fi
|
| 27 |
+
|
| 28 |
+
# Rebuild the source code only when needed
|
| 29 |
+
FROM base AS builder
|
| 30 |
+
WORKDIR /app/next-server
|
| 31 |
+
COPY --from=deps /app/next-server/node_modules ./node_modules
|
| 32 |
+
COPY . .
|
| 33 |
+
|
| 34 |
+
RUN \
|
| 35 |
+
if [ -f yarn.lock ]; then yarn run build; \
|
| 36 |
+
elif [ -f package-lock.json ]; then npm run build; \
|
| 37 |
+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
|
| 38 |
+
else echo "Lockfile not found." && exit 1; \
|
| 39 |
+
fi
|
| 40 |
+
|
| 41 |
+
# Production image, copy all the files and run next
|
| 42 |
+
FROM base AS runner
|
| 43 |
+
WORKDIR /app/next-server
|
| 44 |
+
|
| 45 |
+
ENV NODE_ENV=production
|
| 46 |
+
|
| 47 |
+
RUN addgroup --system --gid 1001 nodejs
|
| 48 |
+
RUN adduser --system --uid 1001 nextjs
|
| 49 |
+
|
| 50 |
+
COPY --from=builder /app/next-server/public ./public
|
| 51 |
+
|
| 52 |
+
# Set the correct permission for prerender cache
|
| 53 |
+
RUN mkdir .next
|
| 54 |
+
RUN chown nextjs:nodejs .next
|
| 55 |
+
|
| 56 |
+
# Automatically leverage output traces to reduce image size
|
| 57 |
+
COPY --from=builder --chown=nextjs:nodejs /app/next-server/.next/standalone ./
|
| 58 |
+
COPY --from=builder --chown=nextjs:nodejs /app/next-server/.next/static ./.next/static
|
| 59 |
+
|
| 60 |
+
USER nextjs
|
| 61 |
+
|
| 62 |
+
# Allow the running process to write model files to the cache folder.
|
| 63 |
+
RUN mkdir -p /app/next-server/node_modules/@huggingface/transformers/.cache
|
| 64 |
+
RUN chmod 777 -R /app/next-server/node_modules/@huggingface/transformers/.cache
|
| 65 |
+
|
| 66 |
+
EXPOSE 3000
|
| 67 |
+
|
| 68 |
+
ENV PORT=3000
|
| 69 |
+
ENV HOSTNAME="0.0.0.0"
|
| 70 |
+
CMD ["node", "server.js"]
|
README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: Next.js + Transformers.js Server Template
|
| 3 |
+
emoji: 🗄️
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: purple
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
app_port: 3000
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# next-server
|
| 12 |
+
|
| 13 |
+
This project, bootstrapped using generated by [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app), demonstrates how to use `@huggingface/transformers` in [Next.js](https://nextjs.org).
|
| 14 |
+
|
| 15 |
+
## Instructions
|
| 16 |
+
|
| 17 |
+
1. Clone the repository:
|
| 18 |
+
```sh
|
| 19 |
+
git clone https://github.com/huggingface/transformers.js-examples.git
|
| 20 |
+
```
|
| 21 |
+
2. Change directory to the `next-server` project:
|
| 22 |
+
```sh
|
| 23 |
+
cd transformers.js-examples/next-server
|
| 24 |
+
```
|
| 25 |
+
3. Install the dependencies:
|
| 26 |
+
```sh
|
| 27 |
+
npm install
|
| 28 |
+
```
|
| 29 |
+
4. Run the development server:
|
| 30 |
+
```sh
|
| 31 |
+
npm run dev
|
| 32 |
+
```
|
| 33 |
+
5. Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
| 34 |
+
|
| 35 |
+
6. You can start editing the page by modifying `app/page.js` (Next.js) and `app/api/classify/route.js` (Transformers.js). The page auto-updates as you edit the file.
|
| 36 |
+
|
| 37 |
+
## Learn More
|
| 38 |
+
|
| 39 |
+
To learn more about Next.js, take a look at the following resources:
|
| 40 |
+
|
| 41 |
+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
| 42 |
+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|