Spaces:
Sleeping
Sleeping
Download frontend/src/components/FileUpload.jsx from rajesh9698/all: direct link, hf CLI and curl.
- Browser
- Download file 4.39 kB
-
https://huggingface.co/spaces/rajesh9698/all/resolve/main/frontend/src/components/FileUpload.jsx
- Command line
-
hf download hf://spaces/rajesh9698/all/frontend/src/components/FileUpload.jsx
-
curl -L -o FileUpload.jsx https://huggingface.co/spaces/rajesh9698/all/resolve/main/frontend/src/components/FileUpload.jsx
4.39 kB
| import React, { useRef, useState } from 'react'; | |
| import { UploadCloud, Image as ImageIcon, Video, X, Loader2 } from 'lucide-react'; | |
| const FileUpload = ({ onUpload, isProcessing, file }) => { | |
| const [dragActive, setDragActive] = useState(false); | |
| const inputRef = useRef(null); | |
| const handleDrag = (e) => { | |
| e.preventDefault(); | |
| e.stopPropagation(); | |
| if (e.type === "dragenter" || e.type === "dragover") { | |
| setDragActive(true); | |
| } else if (e.type === "dragleave") { | |
| setDragActive(false); | |
| } | |
| }; | |
| const handleDrop = (e) => { | |
| e.preventDefault(); | |
| e.stopPropagation(); | |
| setDragActive(false); | |
| if (e.dataTransfer.files && e.dataTransfer.files[0]) { | |
| onUpload(e.dataTransfer.files[0]); | |
| } | |
| }; | |
| const handleChange = (e) => { | |
| e.preventDefault(); | |
| if (e.target.files && e.target.files[0]) { | |
| onUpload(e.target.files[0]); | |
| } | |
| }; | |
| const isVideo = file?.type.startsWith('video/'); | |
| return ( | |
| <div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}> | |
| {!file ? ( | |
| <div | |
| style={{ | |
| border: `2px dashed ${dragActive ? 'var(--color-neon-blue)' : 'rgba(140, 155, 186, 0.3)'}`, | |
| borderRadius: '12px', | |
| padding: '2rem 1rem', | |
| textAlign: 'center', | |
| backgroundColor: dragActive ? 'rgba(0, 229, 255, 0.05)' : 'rgba(0,0,0,0.2)', | |
| transition: 'all 0.3s ease', | |
| cursor: 'pointer' | |
| }} | |
| onDragEnter={handleDrag} | |
| onDragLeave={handleDrag} | |
| onDragOver={handleDrag} | |
| onDrop={handleDrop} | |
| onClick={() => inputRef.current.click()} | |
| > | |
| <input | |
| ref={inputRef} | |
| type="file" | |
| accept="image/*,video/*" | |
| onChange={handleChange} | |
| style={{ display: "none" }} | |
| /> | |
| <UploadCloud | |
| size={40} | |
| color={dragActive ? 'var(--color-neon-blue)' : 'var(--color-text-muted)'} | |
| style={{ margin: '0 auto 1rem', transition: 'all 0.3s ease' }} | |
| /> | |
| <p style={{ margin: '0 0 0.5rem', fontWeight: 500 }}> | |
| Drag and drop feed here | |
| </p> | |
| <p style={{ margin: 0, fontSize: '0.8rem', color: 'var(--color-text-muted)' }}> | |
| Support for Image or Video formats | |
| </p> | |
| </div> | |
| ) : ( | |
| <div style={{ position: 'relative', borderRadius: '12px', overflow: 'hidden', border: '1px solid rgba(255,255,255,0.1)', background: '#000' }}> | |
| {isVideo ? ( | |
| <video | |
| src={URL.createObjectURL(file)} | |
| controls | |
| style={{ width: '100%', display: 'block', opacity: isProcessing ? 0.5 : 1 }} | |
| /> | |
| ) : ( | |
| <img | |
| src={URL.createObjectURL(file)} | |
| alt="Uploaded feed" | |
| style={{ width: '100%', display: 'block', objectFit: 'cover', maxHeight: '250px', opacity: isProcessing ? 0.5 : 1 }} | |
| /> | |
| )} | |
| {isProcessing && ( | |
| <div style={{ position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', background: 'rgba(0,0,0,0.5)' }}> | |
| <Loader2 className="animate-pulse" size={32} color="var(--color-neon-blue)" style={{ animation: 'spin 2s linear infinite' }} /> | |
| <p style={{ marginTop: '1rem', color: 'var(--color-neon-blue)', fontWeight: 'bold' }} className="glow-text"> | |
| ANALYZING FEED... | |
| </p> | |
| </div> | |
| )} | |
| </div> | |
| )} | |
| {file && !isProcessing && ( | |
| <button | |
| className="btn-primary" | |
| onClick={() => onUpload(null)} | |
| style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', gap: '0.5rem' }} | |
| > | |
| <UploadCloud size={18} /> Load New Feed | |
| </button> | |
| )} | |
| </div> | |
| ); | |
| }; | |
| // Add standard spin keyframes if not present | |
| if (typeof document !== 'undefined') { | |
| const style = document.createElement('style'); | |
| style.innerHTML = ` | |
| @keyframes spin { 100% { transform: rotate(360deg); } } | |
| `; | |
| document.head.appendChild(style); | |
| } | |
| export default FileUpload; | |