Spaces:
Sleeping
Sleeping
File size: 15,303 Bytes
20105f5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 | 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>
);
}
|