Spaces:
Running
Running
Download src/components/EnhancementControls.tsx from suplo6669/sharpify-ai: direct link, hf CLI and curl.
- Browser
- Download file 5.57 kB
-
https://huggingface.co/spaces/suplo6669/sharpify-ai/resolve/main/src/components/EnhancementControls.tsx
- Command line
-
hf download hf://spaces/suplo6669/sharpify-ai/src/components/EnhancementControls.tsx
-
curl -L -o EnhancementControls.tsx https://huggingface.co/spaces/suplo6669/sharpify-ai/resolve/main/src/components/EnhancementControls.tsx
5.57 kB
| import { ArrowUpRight, Check, CircleHelp, Download, LoaderCircle, WandSparkles } from "lucide-react"; | |
| import type { EnhancementSettings, OutputFormat, UpscaleFactor } from "@/types/enhancement"; | |
| type EnhancementControlsProps = { | |
| settings: EnhancementSettings; | |
| onChange: (settings: EnhancementSettings) => void; | |
| onEnhance: () => void; | |
| onDownload: () => void; | |
| hasImage: boolean; | |
| hasResult: boolean; | |
| isProcessing: boolean; | |
| isPreviewing: boolean; | |
| canEnhance: boolean; | |
| requiresAuth: boolean; | |
| processingStatus: string | null; | |
| }; | |
| const formats: { value: OutputFormat; label: string; detail: string }[] = [ | |
| { value: "png", label: "PNG", detail: "Lossless" }, | |
| { value: "jpeg", label: "JPG", detail: "Smaller file" }, | |
| { value: "webp", label: "WEBP", detail: "Modern" }, | |
| ]; | |
| export function EnhancementControls({ | |
| settings, | |
| onChange, | |
| onEnhance, | |
| onDownload, | |
| hasImage, | |
| hasResult, | |
| isProcessing, | |
| isPreviewing, | |
| canEnhance, | |
| requiresAuth, | |
| processingStatus, | |
| }: EnhancementControlsProps) { | |
| const isBusy = isProcessing || isPreviewing; | |
| function setScale(scale: UpscaleFactor) { | |
| onChange({ ...settings, scale }); | |
| } | |
| function setFormat(outputFormat: OutputFormat) { | |
| onChange({ ...settings, outputFormat }); | |
| } | |
| return ( | |
| <aside className="settings-panel" aria-label="Enhancement settings"> | |
| <div className="settings-heading"> | |
| <div> | |
| <p className="section-kicker">MAKE IT YOURS</p> | |
| <h3>Enhancement settings</h3> | |
| </div> | |
| <span className="settings-step">01 <span>/ 02</span></span> | |
| </div> | |
| <fieldset className="settings-field" disabled={!hasImage || isBusy}> | |
| <legend>Upscale size</legend> | |
| <p className="field-caption">Give your image more room to breathe.</p> | |
| <div className="scale-options" role="group" aria-label="Upscale factor"> | |
| {([2, 4] as const).map((scale) => ( | |
| <button | |
| aria-pressed={settings.scale === scale} | |
| className={`scale-option${settings.scale === scale ? " is-selected" : ""}`} | |
| key={scale} | |
| onClick={() => setScale(scale)} | |
| type="button" | |
| > | |
| <span className="scale-option-top">{scale}×</span> | |
| <span className="scale-option-bottom">{scale === 2 ? "Balanced" : "Maximum detail"}</span> | |
| {settings.scale === scale && <span className="selected-mark"><Check size={11} /></span>} | |
| </button> | |
| ))} | |
| </div> | |
| </fieldset> | |
| <fieldset className="settings-field format-field" disabled={!hasImage || isBusy}> | |
| <legend>Save format</legend> | |
| <p className="field-caption">Choose how your result is delivered.</p> | |
| <div className="format-options" role="group" aria-label="Output image format"> | |
| {formats.map((format) => ( | |
| <button | |
| aria-pressed={settings.outputFormat === format.value} | |
| className={`format-option${settings.outputFormat === format.value ? " is-selected" : ""}`} | |
| key={format.value} | |
| onClick={() => setFormat(format.value)} | |
| type="button" | |
| > | |
| <span className="format-label">{format.label}</span> | |
| <span className="format-detail">{format.detail}</span> | |
| </button> | |
| ))} | |
| </div> | |
| </fieldset> | |
| <div className="future-setting" aria-label="Face restoration will be available later"> | |
| <div className="future-setting-icon"><WandSparkles size={15} /></div> | |
| <div className="future-setting-copy"><strong>Face restoration</strong><span>Coming in a future model</span></div> | |
| <span className="coming-soon">SOON</span> | |
| </div> | |
| {isProcessing && ( | |
| <div className="processing-status" role="status" aria-live="polite"> | |
| <LoaderCircle className="spin" size={17} /> | |
| <span><strong>{processingStatus?.startsWith("Waiting") ? "Waiting for GPU" : "Enhancing your image"}</strong><small>{processingStatus ?? `AI is restoring detail at ${settings.scale}×.`}</small></span> | |
| </div> | |
| )} | |
| {isPreviewing && ( | |
| <div className="processing-status" role="status" aria-live="polite"> | |
| <LoaderCircle className="spin" size={17} /> | |
| <span><strong>Preparing your image</strong><small>Loading the new preview.</small></span> | |
| </div> | |
| )} | |
| {hasResult ? ( | |
| <button className="button button-dark download-button" type="button" onClick={onDownload} disabled={isBusy}> | |
| <Download size={17} /> Download full-size image <ArrowUpRight size={15} className="button-tail" /> | |
| </button> | |
| ) : ( | |
| <button className="button button-dark enhance-button" type="button" onClick={onEnhance} disabled={!hasImage || isBusy || !canEnhance}> | |
| {isBusy ? <LoaderCircle className="spin" size={17} /> : <WandSparkles size={17} />} | |
| {isPreviewing ? "Preparing your image…" : isProcessing ? "Working on your image…" : requiresAuth && !canEnhance ? "Sign in to enhance" : "Enhance with AI"} | |
| {!isBusy && <ArrowUpRight size={15} className="button-tail" />} | |
| </button> | |
| )} | |
| <p className="settings-footnote"><CircleHelp size={13} /> {requiresAuth ? "Processing uses your Hugging Face ZeroGPU quota." : "Processing time depends on image size and your device."}</p> | |
| {hasResult && <button className="enhance-again" type="button" onClick={onEnhance} disabled={isBusy}>Try these settings on the image</button>} | |
| </aside> | |
| ); | |
| } | |