Spaces:
Running
Running
wuyiqunLu
commited on
Commit
β’
085b520
1
Parent(s):
58d7e55
feat: add docker file to deploy to hf (#37)
Browse files- Dockerfile +49 -0
- README.md +9 -0
- app/layout.tsx +1 -1
- components/chat/ChatList.tsx +17 -7
- components/ui/Img.tsx +4 -0
- next.config.js +1 -0
Dockerfile
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM node:20 AS base
|
2 |
+
ENV PNPM_HOME="/pnpm"
|
3 |
+
ENV PATH="$PNPM_HOME:$PATH"
|
4 |
+
RUN corepack enable
|
5 |
+
|
6 |
+
FROM base AS deps
|
7 |
+
WORKDIR /app
|
8 |
+
COPY package.json pnpm-lock.yaml ./
|
9 |
+
RUN pnpm i --frozen-lockfile
|
10 |
+
|
11 |
+
# Rebuild the source code only when needed
|
12 |
+
FROM base AS builder
|
13 |
+
WORKDIR /app
|
14 |
+
COPY --from=deps --link /app/node_modules ./node_modules
|
15 |
+
COPY --link . .
|
16 |
+
|
17 |
+
RUN --mount=type=secret,id=AUTH_SECRET \
|
18 |
+
--mount=type=secret,id=OPENAI_API_KEY \
|
19 |
+
AUTH_SECRET="$(cat /run/secrets/AUTH_SECRET)" \
|
20 |
+
OPENAI_API_KEY="$(cat /run/secrets/OPENAI_API_KEY)" \
|
21 |
+
NEXT_SHARP_PATH="/app/node_modules/sharp" \
|
22 |
+
USE_STANDALONE_BUILD=True \
|
23 |
+
pnpm run build
|
24 |
+
|
25 |
+
RUN mkdir -p /app/.next/cache/images
|
26 |
+
|
27 |
+
# Production image, copy all the files and run next
|
28 |
+
FROM base AS runner
|
29 |
+
WORKDIR /app
|
30 |
+
|
31 |
+
ENV NODE_ENV production
|
32 |
+
|
33 |
+
COPY --from=builder --link /app/public ./public
|
34 |
+
|
35 |
+
# Automatically leverage output traces to reduce image size
|
36 |
+
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
37 |
+
COPY --chown=nextjs:nodejs --from=builder /app/ ./
|
38 |
+
COPY --from=builder --link --chown=1000:1000 /app/.next/standalone ./
|
39 |
+
COPY --from=builder --link --chown=1000:1000 /app/.next/static ./.next/static
|
40 |
+
COPY --from=builder --link --chown=1000:1000 /app/.next/cache/images ./.next/cache/images
|
41 |
+
|
42 |
+
USER nextjs
|
43 |
+
|
44 |
+
EXPOSE 7860
|
45 |
+
|
46 |
+
ENV PORT 7860
|
47 |
+
ENV HOSTNAME 0.0.0.0
|
48 |
+
|
49 |
+
CMD ["node", "server.js"]
|
README.md
CHANGED
@@ -1,3 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<a href="https://chat.vercel.ai/">
|
2 |
<img alt="Next.js 14 and App Router-ready AI chatbot." src="https://chat.vercel.ai/opengraph-image.png">
|
3 |
<h1 align="center">Next.js AI Chatbot</h1>
|
|
|
1 |
+
---
|
2 |
+
title: Vision Agent
|
3 |
+
emoji: π
|
4 |
+
colorFrom: yellow
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: docker
|
7 |
+
pinned: false
|
8 |
+
---
|
9 |
+
|
10 |
<a href="https://chat.vercel.ai/">
|
11 |
<img alt="Next.js 14 and App Router-ready AI chatbot." src="https://chat.vercel.ai/opengraph-image.png">
|
12 |
<h1 align="center">Next.js AI Chatbot</h1>
|
app/layout.tsx
CHANGED
@@ -51,7 +51,7 @@ export default function RootLayout({ children }: RootLayoutProps) {
|
|
51 |
disableTransitionOnChange
|
52 |
>
|
53 |
<div className="flex flex-col min-h-screen">
|
54 |
-
<Header />
|
55 |
<main className="flex flex-col flex-1 bg-muted/50">{children}</main>
|
56 |
</div>
|
57 |
<TailwindIndicator />
|
|
|
51 |
disableTransitionOnChange
|
52 |
>
|
53 |
<div className="flex flex-col min-h-screen">
|
54 |
+
{!process.env.NEXT_PUBLIC_IS_HUGGING_FACE && <Header />}
|
55 |
<main className="flex flex-col flex-1 bg-muted/50">{children}</main>
|
56 |
</div>
|
57 |
<TailwindIndicator />
|
components/chat/ChatList.tsx
CHANGED
@@ -22,13 +22,23 @@ export function ChatList({ messages, session }: ChatList) {
|
|
22 |
<IconExclamationTriangle />
|
23 |
</div>
|
24 |
<div className="flex-1 px-1 ml-4 space-y-2 overflow-hidden">
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
</div>
|
33 |
</div>
|
34 |
<Separator className="my-4" />
|
|
|
22 |
<IconExclamationTriangle />
|
23 |
</div>
|
24 |
<div className="flex-1 px-1 ml-4 space-y-2 overflow-hidden">
|
25 |
+
{!process.env.NEXT_PUBLIC_IS_HUGGING_FACE ? (
|
26 |
+
<p className="text-muted-foreground leading-normal">
|
27 |
+
Please visit and login into{' '}
|
28 |
+
<Link href="https://va.landing.ai/" className="underline">
|
29 |
+
our landing website
|
30 |
+
</Link>{' '}
|
31 |
+
to save and revisit your chat history!
|
32 |
+
</p>
|
33 |
+
) : (
|
34 |
+
<p className="text-muted-foreground leading-normal">
|
35 |
+
Please{' '}
|
36 |
+
<Link href="/sign-in" className="underline">
|
37 |
+
log in
|
38 |
+
</Link>{' '}
|
39 |
+
to save and revisit your chat history!
|
40 |
+
</p>
|
41 |
+
)}
|
42 |
</div>
|
43 |
</div>
|
44 |
<Separator className="my-4" />
|
components/ui/Img.tsx
CHANGED
@@ -39,6 +39,10 @@ const Img = React.forwardRef<
|
|
39 |
generateThumbnail();
|
40 |
}, [isVideo, src]);
|
41 |
|
|
|
|
|
|
|
|
|
42 |
return (
|
43 |
<Image
|
44 |
src={isVideo ? thumbnail : src}
|
|
|
39 |
generateThumbnail();
|
40 |
}, [isVideo, src]);
|
41 |
|
42 |
+
if (isVideo && !thumbnail) {
|
43 |
+
return null;
|
44 |
+
}
|
45 |
+
|
46 |
return (
|
47 |
<Image
|
48 |
src={isVideo ? thumbnail : src}
|
next.config.js
CHANGED
@@ -12,4 +12,5 @@ module.exports = {
|
|
12 |
experimental: {
|
13 |
serverComponentsExternalPackages: ['pino', 'pino-loki'],
|
14 |
},
|
|
|
15 |
};
|
|
|
12 |
experimental: {
|
13 |
serverComponentsExternalPackages: ['pino', 'pino-loki'],
|
14 |
},
|
15 |
+
...(process.env.USE_STANDALONE_BUILD ? { output: 'standalone' } : {}),
|
16 |
};
|