Spaces:
Running
Running
File size: 5,566 Bytes
1d8be9a | 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 | 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>
);
}
|