Spaces:
Build error
Build error
Raumkommander2
commited on
Commit
·
ff373c0
1
Parent(s):
a2ed93f
inital deployment1
Browse files- Dockerfile +13 -0
- WebcamImageSaver.js +59 -0
- package.json +16 -0
- requirements.txt +11 -0
Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM node:18-alpine
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
COPY package.json package-lock.json ./
|
6 |
+
RUN npm install
|
7 |
+
|
8 |
+
COPY . ./
|
9 |
+
|
10 |
+
RUN npm run build
|
11 |
+
|
12 |
+
CMD ["npx", "serve", "-s", "build", "-l", "7860"]
|
13 |
+
|
WebcamImageSaver.js
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useRef, useState } from "react";
|
2 |
+
import { Button } from "@/components/ui/button";
|
3 |
+
import { Card, CardContent } from "@/components/ui/card";
|
4 |
+
import { Download } from "lucide-react";
|
5 |
+
|
6 |
+
export default function WebcamImageSaver() {
|
7 |
+
const videoRef = useRef(null);
|
8 |
+
const canvasRef = useRef(null);
|
9 |
+
const [imageUrl, setImageUrl] = useState("");
|
10 |
+
|
11 |
+
const startCamera = async () => {
|
12 |
+
try {
|
13 |
+
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
|
14 |
+
if (videoRef.current) {
|
15 |
+
videoRef.current.srcObject = stream;
|
16 |
+
}
|
17 |
+
} catch (error) {
|
18 |
+
console.error("Error accessing webcam:", error);
|
19 |
+
}
|
20 |
+
};
|
21 |
+
|
22 |
+
const captureImage = () => {
|
23 |
+
if (!videoRef.current || !canvasRef.current) return;
|
24 |
+
const context = canvasRef.current.getContext("2d");
|
25 |
+
context.drawImage(videoRef.current, 0, 0, 640, 480);
|
26 |
+
const imageDataUrl = canvasRef.current.toDataURL("image/png");
|
27 |
+
setImageUrl(imageDataUrl);
|
28 |
+
};
|
29 |
+
|
30 |
+
const saveImage = () => {
|
31 |
+
if (!imageUrl) return;
|
32 |
+
const link = document.createElement("a");
|
33 |
+
link.href = imageUrl;
|
34 |
+
link.download = "webcam_image.png";
|
35 |
+
document.body.appendChild(link);
|
36 |
+
link.click();
|
37 |
+
document.body.removeChild(link);
|
38 |
+
};
|
39 |
+
|
40 |
+
return (
|
41 |
+
<div className="flex flex-col items-center gap-4 p-4">
|
42 |
+
<Button onClick={startCamera}>Start Camera</Button>
|
43 |
+
<video ref={videoRef} autoPlay className="rounded-lg shadow-md" width={640} height={480} />
|
44 |
+
<canvas ref={canvasRef} width={640} height={480} className="hidden" />
|
45 |
+
<Button onClick={captureImage}>Capture Image</Button>
|
46 |
+
{imageUrl && (
|
47 |
+
<Card className="p-4">
|
48 |
+
<CardContent>
|
49 |
+
<img src={imageUrl} alt="Captured" className="rounded-lg shadow-md" />
|
50 |
+
<Button onClick={saveImage} className="mt-4 flex items-center">
|
51 |
+
<Download className="mr-2" /> Save Image
|
52 |
+
</Button>
|
53 |
+
</CardContent>
|
54 |
+
</Card>
|
55 |
+
)}
|
56 |
+
</div>
|
57 |
+
);
|
58 |
+
}
|
59 |
+
|
package.json
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"name": "huggingface-webcam",
|
3 |
+
"version": "1.0.0",
|
4 |
+
"private": true,
|
5 |
+
"dependencies": {
|
6 |
+
"react": "^18.0.0",
|
7 |
+
"react-dom": "^18.0.0",
|
8 |
+
"lucide-react": "^0.24.0",
|
9 |
+
"tailwindcss": "^3.0.0",
|
10 |
+
"serve": "^14.0.1"
|
11 |
+
},
|
12 |
+
"scripts": {
|
13 |
+
"start": "react-scripts start",
|
14 |
+
"build": "react-scripts build"
|
15 |
+
}
|
16 |
+
}
|
requirements.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
opencv-python
|
3 |
+
torch
|
4 |
+
torchvision
|
5 |
+
numpy
|
6 |
+
diffusers
|
7 |
+
transformers
|
8 |
+
Pillow
|
9 |
+
accelerate
|
10 |
+
fastapi
|
11 |
+
uvicorn
|