Spaces:
Running
Running
Update index.html
Browse files- index.html +198 -169
index.html
CHANGED
|
@@ -1,175 +1,204 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
-
<head>
|
| 4 |
-
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Image
|
| 7 |
-
<
|
| 8 |
-
/* General Styles */
|
| 9 |
-
* {
|
| 10 |
-
margin: 0;
|
| 11 |
-
padding: 0;
|
| 12 |
-
box-sizing: border-box;
|
| 13 |
-
}
|
| 14 |
-
|
| 15 |
-
body {
|
| 16 |
-
background-color: white;
|
| 17 |
-
font-family: Arial, sans-serif;
|
| 18 |
-
display: flex;
|
| 19 |
-
justify-content: center;
|
| 20 |
-
align-items: center;
|
| 21 |
-
height: 100vh;
|
| 22 |
-
}
|
| 23 |
-
|
| 24 |
-
.container {
|
| 25 |
-
text-align: center;
|
| 26 |
-
width: 90%;
|
| 27 |
-
max-width: 1255px;
|
| 28 |
-
}
|
| 29 |
-
|
| 30 |
-
/* Header Image */
|
| 31 |
-
.header img {
|
| 32 |
-
width: 100%;
|
| 33 |
-
height: auto;
|
| 34 |
-
max-width: 1255px;
|
| 35 |
-
margin-bottom: 20px;
|
| 36 |
-
}
|
| 37 |
-
|
| 38 |
-
/* Drop Area */
|
| 39 |
-
#drop-area {
|
| 40 |
-
border: 2px dashed #ccc;
|
| 41 |
-
border-radius: 10px;
|
| 42 |
-
padding: 20px;
|
| 43 |
-
margin: 20px auto;
|
| 44 |
-
background-color: #fff;
|
| 45 |
-
transition: background-color 0.3s ease;
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
-
#drop-area:hover {
|
| 49 |
-
background-color: #f0f0f0;
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
#drop-area p {
|
| 53 |
-
margin: 10px 0;
|
| 54 |
-
font-size: 18px;
|
| 55 |
-
color: #333;
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
-
#file-input-button {
|
| 59 |
-
padding: 10px 20px;
|
| 60 |
-
background-color: #007bff;
|
| 61 |
-
color: white;
|
| 62 |
-
border: none;
|
| 63 |
-
border-radius: 5px;
|
| 64 |
-
cursor: pointer;
|
| 65 |
-
font-size: 16px;
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
#file-input-button:hover {
|
| 69 |
-
background-color: #0056b3;
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
/* Gallery */
|
| 73 |
-
.gallery {
|
| 74 |
-
display: grid;
|
| 75 |
-
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
| 76 |
-
gap: 10px;
|
| 77 |
-
margin-top: 20px;
|
| 78 |
-
}
|
| 79 |
-
|
| 80 |
-
.gallery img {
|
| 81 |
-
width: 100%;
|
| 82 |
-
height: auto;
|
| 83 |
-
border-radius: 10px;
|
| 84 |
-
object-fit: cover;
|
| 85 |
-
}
|
| 86 |
-
</style>
|
| 87 |
-
</head>
|
| 88 |
-
<body>
|
| 89 |
-
<div class="container">
|
| 90 |
-
<!-- Header Image -->
|
| 91 |
-
<div class="header">
|
| 92 |
-
<img src="https://huggingface.co/spaces/pakdeveloper/Static-002/resolve/main/imageuploadscript.png" alt="Image Upload Script" width="1255">
|
| 93 |
-
</div>
|
| 94 |
-
|
| 95 |
-
<!-- Drag & Drop Area -->
|
| 96 |
-
<div id="drop-area">
|
| 97 |
-
<p>Drag & Drop your images here</p>
|
| 98 |
-
<p>or</p>
|
| 99 |
-
<button id="file-input-button">Upload Files</button>
|
| 100 |
-
<input type="file" id="file-input" multiple accept="image/*" style="display: none;">
|
| 101 |
-
</div>
|
| 102 |
-
|
| 103 |
-
<!-- Image Gallery -->
|
| 104 |
-
<div id="gallery" class="gallery"></div>
|
| 105 |
-
</div>
|
| 106 |
-
|
| 107 |
<script>
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
// Prevent default drag behaviors
|
| 114 |
-
['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
|
| 115 |
-
dropArea.addEventListener(eventName, preventDefaults, false);
|
| 116 |
-
});
|
| 117 |
-
|
| 118 |
-
function preventDefaults(e) {
|
| 119 |
-
e.preventDefault();
|
| 120 |
-
e.stopPropagation();
|
| 121 |
-
}
|
| 122 |
-
|
| 123 |
-
// Highlight drop area when item is dragged over it
|
| 124 |
-
['dragenter', 'dragover'].forEach(eventName => {
|
| 125 |
-
dropArea.addEventListener(eventName, () => dropArea.classList.add('highlight'), false);
|
| 126 |
-
});
|
| 127 |
-
|
| 128 |
-
['dragleave', 'drop'].forEach(eventName => {
|
| 129 |
-
dropArea.addEventListener(eventName, () => dropArea.classList.remove('highlight'), false);
|
| 130 |
-
});
|
| 131 |
-
|
| 132 |
-
// Handle dropped files
|
| 133 |
-
dropArea.addEventListener('drop', handleDrop, false);
|
| 134 |
-
|
| 135 |
-
function handleDrop(e) {
|
| 136 |
-
const dt = e.dataTransfer;
|
| 137 |
-
const files = dt.files;
|
| 138 |
-
|
| 139 |
-
handleFiles(files);
|
| 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 |
</script>
|
| 174 |
-
</
|
|
|
|
| 175 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>Image Gallery</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
<script>
|
| 9 |
+
tailwind.config = {
|
| 10 |
+
theme: {
|
| 11 |
+
extend: {
|
| 12 |
+
colors: {
|
| 13 |
+
primary: 'rgb(147, 51, 234)'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
}
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
}
|
| 18 |
+
</script>
|
| 19 |
+
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
|
| 20 |
+
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
|
| 21 |
+
<script src="https://unpkg.com/react-masonry-css@1.0.16/dist/react-masonry-css.min.js"></script>
|
| 22 |
+
<script src="https://unpkg.com/lucide-react"></script>
|
| 23 |
+
<script src="https://cdn.jsdelivr.net/npm/sonner"></script>
|
| 24 |
+
</head>
|
| 25 |
+
<body>
|
| 26 |
+
<div id="root"></div>
|
| 27 |
+
<script src="https://cdn.gpteng.co/gptengineer.js" type="module"></script>
|
| 28 |
+
<script type="text/babel">
|
| 29 |
+
const { useState, useCallback, useRef } = React;
|
| 30 |
+
const { Upload } = lucide;
|
| 31 |
+
const { toast } = sonner;
|
| 32 |
+
|
| 33 |
+
const DragDropZone = ({ onFilesAdded }) => {
|
| 34 |
+
const [isDragging, setIsDragging] = useState(false);
|
| 35 |
+
const fileInputRef = useRef(null);
|
| 36 |
+
|
| 37 |
+
const handleDrag = useCallback((e) => {
|
| 38 |
+
e.preventDefault();
|
| 39 |
+
e.stopPropagation();
|
| 40 |
+
}, []);
|
| 41 |
+
|
| 42 |
+
const handleDragIn = useCallback((e) => {
|
| 43 |
+
e.preventDefault();
|
| 44 |
+
e.stopPropagation();
|
| 45 |
+
setIsDragging(true);
|
| 46 |
+
}, []);
|
| 47 |
+
|
| 48 |
+
const handleDragOut = useCallback((e) => {
|
| 49 |
+
e.preventDefault();
|
| 50 |
+
e.stopPropagation();
|
| 51 |
+
setIsDragging(false);
|
| 52 |
+
}, []);
|
| 53 |
+
|
| 54 |
+
const handleDrop = useCallback((e) => {
|
| 55 |
+
e.preventDefault();
|
| 56 |
+
e.stopPropagation();
|
| 57 |
+
setIsDragging(false);
|
| 58 |
+
|
| 59 |
+
const files = Array.from(e.dataTransfer.files);
|
| 60 |
+
const imageFiles = files.filter(file => file.type.startsWith('image/'));
|
| 61 |
+
|
| 62 |
+
if (imageFiles.length === 0) {
|
| 63 |
+
toast.error('Please drop image files only');
|
| 64 |
+
return;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
onFilesAdded(imageFiles);
|
| 68 |
+
}, [onFilesAdded]);
|
| 69 |
+
|
| 70 |
+
const handleFileInput = useCallback((e) => {
|
| 71 |
+
const files = Array.from(e.target.files || []);
|
| 72 |
+
const imageFiles = files.filter(file => file.type.startsWith('image/'));
|
| 73 |
+
|
| 74 |
+
if (imageFiles.length === 0) {
|
| 75 |
+
toast.error('Please select image files only');
|
| 76 |
+
return;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
onFilesAdded(imageFiles);
|
| 80 |
+
e.target.value = '';
|
| 81 |
+
}, [onFilesAdded]);
|
| 82 |
+
|
| 83 |
+
const handleClick = () => {
|
| 84 |
+
fileInputRef.current?.click();
|
| 85 |
+
};
|
| 86 |
+
|
| 87 |
+
return (
|
| 88 |
+
<div
|
| 89 |
+
className={`relative min-h-[200px] rounded-xl border-2 border-dashed transition-all duration-300 ease-in-out cursor-pointer ${
|
| 90 |
+
isDragging
|
| 91 |
+
? 'border-primary bg-primary/5'
|
| 92 |
+
: 'border-gray-200 hover:border-primary/50'
|
| 93 |
+
}`}
|
| 94 |
+
onDragEnter={handleDragIn}
|
| 95 |
+
onDragLeave={handleDragOut}
|
| 96 |
+
onDragOver={handleDrag}
|
| 97 |
+
onDrop={handleDrop}
|
| 98 |
+
onClick={handleClick}
|
| 99 |
+
>
|
| 100 |
+
<input
|
| 101 |
+
ref={fileInputRef}
|
| 102 |
+
type="file"
|
| 103 |
+
className="hidden"
|
| 104 |
+
multiple
|
| 105 |
+
accept="image/*"
|
| 106 |
+
onChange={handleFileInput}
|
| 107 |
+
/>
|
| 108 |
+
<div className="absolute inset-0 flex flex-col items-center justify-center space-y-4 p-6 text-center">
|
| 109 |
+
<div className="rounded-full bg-primary/10 p-4">
|
| 110 |
+
<Upload className="h-6 w-6 text-primary" />
|
| 111 |
+
</div>
|
| 112 |
+
<div>
|
| 113 |
+
<p className="text-lg font-medium text-gray-900">
|
| 114 |
+
Drag & Drop images here
|
| 115 |
+
</p>
|
| 116 |
+
<p className="mt-1 text-sm text-gray-500">or click anywhere to upload</p>
|
| 117 |
+
</div>
|
| 118 |
+
</div>
|
| 119 |
+
</div>
|
| 120 |
+
);
|
| 121 |
+
};
|
| 122 |
+
|
| 123 |
+
const ImageGallery = ({ images }) => {
|
| 124 |
+
const breakpointColumns = {
|
| 125 |
+
default: 4,
|
| 126 |
+
1100: 3,
|
| 127 |
+
700: 2,
|
| 128 |
+
500: 1,
|
| 129 |
+
};
|
| 130 |
+
|
| 131 |
+
return (
|
| 132 |
+
<Masonry
|
| 133 |
+
breakpointCols={breakpointColumns}
|
| 134 |
+
className="flex w-full gap-4"
|
| 135 |
+
columnClassName="space-y-4"
|
| 136 |
+
>
|
| 137 |
+
{images.map((image, index) => (
|
| 138 |
+
<div
|
| 139 |
+
key={index}
|
| 140 |
+
className="relative overflow-hidden rounded-lg bg-gray-100 shadow-sm transition-all duration-300 hover:shadow-md"
|
| 141 |
+
>
|
| 142 |
+
<img
|
| 143 |
+
src={image}
|
| 144 |
+
alt={`Gallery image ${index + 1}`}
|
| 145 |
+
className="h-auto w-full object-cover"
|
| 146 |
+
loading="lazy"
|
| 147 |
+
/>
|
| 148 |
+
</div>
|
| 149 |
+
))}
|
| 150 |
+
</Masonry>
|
| 151 |
+
);
|
| 152 |
+
};
|
| 153 |
+
|
| 154 |
+
const App = () => {
|
| 155 |
+
const [images, setImages] = useState([]);
|
| 156 |
+
|
| 157 |
+
const handleFilesAdded = useCallback((files) => {
|
| 158 |
+
const newImages = files.map(file => URL.createObjectURL(file));
|
| 159 |
+
setImages(prev => [...prev, ...newImages]);
|
| 160 |
+
toast.success(`${files.length} image${files.length === 1 ? '' : 's'} uploaded`);
|
| 161 |
+
}, []);
|
| 162 |
+
|
| 163 |
+
return (
|
| 164 |
+
<div className="mx-auto max-w-7xl px-4 py-8 sm:px-6 lg:px-8">
|
| 165 |
+
<div className="space-y-8">
|
| 166 |
+
<div>
|
| 167 |
+
<h1 className="text-4xl font-bold tracking-tight text-gray-900">
|
| 168 |
+
Image Gallery
|
| 169 |
+
</h1>
|
| 170 |
+
<p className="mt-2 text-lg text-gray-600">
|
| 171 |
+
Upload your images by dragging and dropping them below
|
| 172 |
+
</p>
|
| 173 |
+
</div>
|
| 174 |
+
|
| 175 |
+
<DragDropZone onFilesAdded={handleFilesAdded} />
|
| 176 |
+
|
| 177 |
+
<div className="space-y-4">
|
| 178 |
+
<h2 className="text-2xl font-semibold text-gray-900">
|
| 179 |
+
Your Images
|
| 180 |
+
</h2>
|
| 181 |
+
{images.length > 0 ? (
|
| 182 |
+
<ImageGallery images={images} />
|
| 183 |
+
) : (
|
| 184 |
+
<p className="text-center text-gray-500 py-12">
|
| 185 |
+
No images uploaded yet. Start by dropping some images above!
|
| 186 |
+
</p>
|
| 187 |
+
)}
|
| 188 |
+
</div>
|
| 189 |
+
</div>
|
| 190 |
+
</div>
|
| 191 |
+
);
|
| 192 |
+
};
|
| 193 |
+
|
| 194 |
+
const root = ReactDOM.createRoot(document.getElementById('root'));
|
| 195 |
+
root.render(
|
| 196 |
+
<React.StrictMode>
|
| 197 |
+
<App />
|
| 198 |
+
<Toaster />
|
| 199 |
+
</React.StrictMode>
|
| 200 |
+
);
|
| 201 |
</script>
|
| 202 |
+
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
| 203 |
+
</body>
|
| 204 |
</html>
|