tra2 / src /components /DeployGuide.tsx
omar1988omaralconl's picture
Upload 15 files
20105f5 verified
Raw History Blame Contribute Delete
15.3 kB
import { useState } from 'react';
const STEPS = [
{
title: '1. Create a Hugging Face Account',
content: `Go to huggingface.co and sign up for a free account (if you don't have one already).`,
link: 'https://huggingface.co/join',
linkText: 'Sign up at huggingface.co',
},
{
title: '2. Create a New Space',
content: `Click "New Space" from your profile. Give it a name like "subtitle-translator".
For the SDK, choose "Static" (this is a pre-built static site).
Set visibility to "Public" (free tier).`,
link: 'https://huggingface.co/new-space',
linkText: 'Create New Space β†’',
},
{
title: '3. Clone the Space Repository',
content: `Open a terminal and clone your new Space:
git clone https://huggingface.co/spaces/YOUR_USERNAME/subtitle-translator
cd subtitle-translator`,
code: `git clone https://huggingface.co/spaces/YOUR_USERNAME/subtitle-translator
cd subtitle-translator`,
},
{
title: '4. Build this Project Locally',
content: `Make sure you have Node.js installed. Then build the project:
npm install
npm run build
This creates a "dist/" folder with the static files.`,
code: `npm install
npm run build`,
},
{
title: '5. Copy Build Files to Space',
content: `Copy all files from the "dist/" folder into the cloned Space folder:
cp -r dist/* /path/to/subtitle-translator/
Your Space folder should now have: index.html, assets/, etc.`,
code: `# On Mac/Linux:
cp -r dist/* ./subtitle-translator/
# On Windows:
xcopy dist\\* subtitle-translator\\ /E /Y`,
},
{
title: '6. Push to Hugging Face',
content: `Navigate into the Space folder and push:
cd subtitle-translator
git add .
git commit -m "Deploy subtitle translator"
git push
Your app will be live at:
https://huggingface.co/spaces/YOUR_USERNAME/subtitle-translator`,
code: `cd subtitle-translator
git add .
git commit -m "Deploy subtitle translator"
git push`,
},
];
const DOCKER_README = `---
title: SubTranslate - Subtitle Translator
emoji: 🌍
colorFrom: purple
colorTo: pink
sdk: static
pinned: false
---`;
export function DeployGuide({ onClose }: { onClose: () => void }) {
const [copiedIdx, setCopiedIdx] = useState<number | null>(null);
const [activeTab, setActiveTab] = useState<'static' | 'docker'>('static');
const copyToClipboard = (text: string, idx: number) => {
navigator.clipboard.writeText(text);
setCopiedIdx(idx);
setTimeout(() => setCopiedIdx(null), 2000);
};
return (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
{/* Backdrop */}
<div
className="absolute inset-0 bg-black/70 backdrop-blur-sm"
onClick={onClose}
/>
{/* Modal */}
<div className="relative w-full max-w-3xl max-h-[90vh] rounded-2xl bg-slate-900 border border-white/10 shadow-2xl shadow-purple-500/10 overflow-hidden flex flex-col">
{/* Header */}
<div className="flex items-center justify-between px-6 py-4 border-b border-white/10 bg-white/5 shrink-0">
<div className="flex items-center gap-3">
<div className="flex h-9 w-9 items-center justify-center rounded-lg bg-gradient-to-br from-yellow-500 to-orange-600">
<span className="text-lg">πŸ€—</span>
</div>
<div>
<h2 className="text-lg font-bold text-white">
Deploy to Hugging Face Spaces
</h2>
<p className="text-xs text-slate-400">
Host your subtitle translator for free
</p>
</div>
</div>
<button
onClick={onClose}
className="p-2 rounded-lg hover:bg-white/10 transition text-slate-400 hover:text-white"
>
<svg className="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
<line x1="18" y1="6" x2="6" y2="18" />
<line x1="6" y1="6" x2="18" y2="18" />
</svg>
</button>
</div>
{/* Tabs */}
<div className="flex border-b border-white/10 shrink-0">
<button
onClick={() => setActiveTab('static')}
className={`px-6 py-3 text-sm font-medium transition ${
activeTab === 'static'
? 'text-violet-400 border-b-2 border-violet-400 bg-white/5'
: 'text-slate-400 hover:text-white'
}`}
>
πŸ“„ Static Site (Easiest)
</button>
<button
onClick={() => setActiveTab('docker')}
className={`px-6 py-3 text-sm font-medium transition ${
activeTab === 'docker'
? 'text-violet-400 border-b-2 border-violet-400 bg-white/5'
: 'text-slate-400 hover:text-white'
}`}
>
🐳 Docker (Advanced)
</button>
</div>
{/* Content */}
<div className="overflow-y-auto p-6 space-y-6 flex-1">
{activeTab === 'static' && (
<>
<div className="rounded-xl bg-emerald-500/10 border border-emerald-500/20 p-4">
<p className="text-sm text-emerald-300">
<strong>✨ Recommended:</strong> The Static SDK is the
simplest way to deploy. It serves your built HTML/CSS/JS files
directly β€” no server needed.
</p>
</div>
{STEPS.map((step, idx) => (
<div
key={idx}
className="rounded-xl bg-white/5 border border-white/10 overflow-hidden"
>
<div className="px-5 py-3 bg-white/5 border-b border-white/10">
<h3 className="font-semibold text-white">{step.title}</h3>
</div>
<div className="px-5 py-4 space-y-3">
<p className="text-sm text-slate-300 whitespace-pre-line leading-relaxed">
{step.content}
</p>
{step.code && (
<div className="relative">
<pre className="rounded-lg bg-black/40 border border-white/10 p-4 text-sm text-green-400 font-mono overflow-x-auto">
{step.code}
</pre>
<button
onClick={() => copyToClipboard(step.code!, idx)}
className="absolute top-2 right-2 px-2.5 py-1 rounded-md bg-white/10 hover:bg-white/20 transition text-xs text-slate-300"
>
{copiedIdx === idx ? 'βœ“ Copied!' : 'Copy'}
</button>
</div>
)}
{step.link && (
<a
href={step.link}
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1.5 text-sm text-violet-400 hover:text-violet-300 underline underline-offset-2"
>
{step.linkText}
<svg className="h-3.5 w-3.5" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth={2}>
<path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" />
<polyline points="15 3 21 3 21 9" />
<line x1="10" y1="14" x2="21" y2="3" />
</svg>
</a>
)}
</div>
</div>
))}
</>
)}
{activeTab === 'docker' && (
<>
<div className="rounded-xl bg-blue-500/10 border border-blue-500/20 p-4">
<p className="text-sm text-blue-300">
<strong>🐳 Docker:</strong> For advanced users. This uses a
Dockerfile to build and serve the app inside a container on
Hugging Face Spaces.
</p>
</div>
<div className="rounded-xl bg-white/5 border border-white/10 overflow-hidden">
<div className="px-5 py-3 bg-white/5 border-b border-white/10">
<h3 className="font-semibold text-white">
1. Create Space with Docker SDK
</h3>
</div>
<div className="px-5 py-4 space-y-3">
<p className="text-sm text-slate-300">
Create a new Space and select <strong>"Docker"</strong> as
the SDK.
</p>
<a
href="https://huggingface.co/new-space"
target="_blank"
rel="noopener noreferrer"
className="inline-flex items-center gap-1.5 text-sm text-violet-400 hover:text-violet-300 underline underline-offset-2"
>
Create New Space β†’
</a>
</div>
</div>
<div className="rounded-xl bg-white/5 border border-white/10 overflow-hidden">
<div className="px-5 py-3 bg-white/5 border-b border-white/10">
<h3 className="font-semibold text-white">
2. Add README.md (Space metadata)
</h3>
</div>
<div className="px-5 py-4 space-y-3">
<p className="text-sm text-slate-300">
Create a <code className="text-violet-300 bg-white/10 px-1.5 py-0.5 rounded">README.md</code> in your Space root:
</p>
<div className="relative">
<pre className="rounded-lg bg-black/40 border border-white/10 p-4 text-sm text-green-400 font-mono overflow-x-auto">
{DOCKER_README}
</pre>
<button
onClick={() => copyToClipboard(DOCKER_README, 100)}
className="absolute top-2 right-2 px-2.5 py-1 rounded-md bg-white/10 hover:bg-white/20 transition text-xs text-slate-300"
>
{copiedIdx === 100 ? 'βœ“ Copied!' : 'Copy'}
</button>
</div>
</div>
</div>
<div className="rounded-xl bg-white/5 border border-white/10 overflow-hidden">
<div className="px-5 py-3 bg-white/5 border-b border-white/10">
<h3 className="font-semibold text-white">
3. Add Dockerfile
</h3>
</div>
<div className="px-5 py-4 space-y-3">
<p className="text-sm text-slate-300">
Create a <code className="text-violet-300 bg-white/10 px-1.5 py-0.5 rounded">Dockerfile</code>:
</p>
<div className="relative">
<pre className="rounded-lg bg-black/40 border border-white/10 p-4 text-sm text-green-400 font-mono overflow-x-auto whitespace-pre">
{`# Build stage
FROM node:20-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Production stage
FROM nginx:alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build /app/dist /usr/share/nginx/html
EXPOSE 7860
CMD ["nginx", "-g", "daemon off;"]
# ⚠️ IMPORTANT: Also add nginx.conf file:
# server {
# listen 7860;
# server_name _;
# root /usr/share/nginx/html;
# index index.html;
# location / {
# try_files $uri $uri/ /index.html;
# }
# }`}
</pre>
<button
onClick={() =>
copyToClipboard(
`FROM node:18-alpine AS build\nWORKDIR /app\nCOPY package*.json ./\nRUN npm ci\nCOPY . .\nRUN npm run build\n\nFROM nginx:alpine\nCOPY --from=build /app/dist /usr/share/nginx/html\nEXPOSE 7860\nCMD ["nginx", "-g", "daemon off;"]`,
101
)
}
className="absolute top-2 right-2 px-2.5 py-1 rounded-md bg-white/10 hover:bg-white/20 transition text-xs text-slate-300"
>
{copiedIdx === 101 ? 'βœ“ Copied!' : 'Copy'}
</button>
</div>
</div>
</div>
<div className="rounded-xl bg-white/5 border border-white/10 overflow-hidden">
<div className="px-5 py-3 bg-white/5 border-b border-white/10">
<h3 className="font-semibold text-white">
4. Push all project files
</h3>
</div>
<div className="px-5 py-4 space-y-3">
<p className="text-sm text-slate-300">
Push ALL project files (src/, package.json, etc.) along with the Dockerfile and README.md:
</p>
<div className="relative">
<pre className="rounded-lg bg-black/40 border border-white/10 p-4 text-sm text-green-400 font-mono overflow-x-auto">
{`git add .
git commit -m "Deploy subtitle translator"
git push`}
</pre>
</div>
<p className="text-sm text-slate-400">
Hugging Face will automatically build the Docker image and
deploy your app! πŸŽ‰
</p>
</div>
</div>
</>
)}
{/* Quick alternative */}
<div className="rounded-xl bg-gradient-to-r from-violet-500/10 to-fuchsia-500/10 border border-violet-500/20 p-5">
<h3 className="font-semibold text-white mb-2">
⚑ Quickest Method: Upload via Browser
</h3>
<ol className="text-sm text-slate-300 space-y-2 list-decimal list-inside">
<li>
Go to{' '}
<a
href="https://huggingface.co/new-space"
target="_blank"
rel="noopener noreferrer"
className="text-violet-400 underline"
>
huggingface.co/new-space
</a>
</li>
<li>Select <strong>"Static"</strong> SDK, name your space</li>
<li>
Go to <strong>Files β†’ Add file β†’ Upload files</strong>
</li>
<li>
Upload the contents of the <code className="text-violet-300 bg-white/10 px-1 py-0.5 rounded text-xs">dist/</code> folder (index.html + assets/)
</li>
<li>Your app goes live instantly! πŸš€</li>
</ol>
</div>
</div>
{/* Footer */}
<div className="px-6 py-4 border-t border-white/10 bg-white/5 shrink-0">
<button
onClick={onClose}
className="px-5 py-2 rounded-lg bg-white/10 hover:bg-white/20 transition font-medium text-sm"
>
Close
</button>
</div>
</div>
</div>
);
}