import { FormEvent, useRef } from "react" import { useStore } from "@/lib/states" import { Switch } from "../ui/switch" import { NumberInput } from "../ui/input" import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue, } from "../ui/select" import { Textarea } from "../ui/textarea" import { ExtenderDirection, PowerPaintTask } from "@/lib/types" import { Separator } from "../ui/separator" import { Button, ImageUploadButton } from "../ui/button" import { Slider } from "../ui/slider" import { useImage } from "@/hooks/useImage" import { ANYTEXT, INSTRUCT_PIX2PIX, PAINT_BY_EXAMPLE, POWERPAINT, } from "@/lib/const" import { RowContainer, LabelTitle } from "./LabelTitle" import { Upload } from "lucide-react" import { useClickAway } from "react-use" const ExtenderButton = ({ text, onClick, }: { text: string onClick: () => void }) => { const [showExtender] = useStore((state) => [state.settings.showExtender]) return ( ) } const DiffusionOptions = () => { const [ samplers, settings, paintByExampleFile, isProcessing, updateSettings, runInpainting, updateAppState, updateExtenderByBuiltIn, updateExtenderDirection, adjustMask, clearMask, updateEnablePowerPaintV2, updateEnableBrushNet, updateEnableControlnet, updateLCMLora, ] = useStore((state) => [ state.serverConfig.samplers, state.settings, state.paintByExampleFile, state.getIsProcessing(), state.updateSettings, state.runInpainting, state.updateAppState, state.updateExtenderByBuiltIn, state.updateExtenderDirection, state.adjustMask, state.clearMask, state.updateEnablePowerPaintV2, state.updateEnableBrushNet, state.updateEnableControlnet, state.updateLCMLora, ]) const [exampleImage, isExampleImageLoaded] = useImage(paintByExampleFile) const negativePromptRef = useRef(null) useClickAway(negativePromptRef, () => { if (negativePromptRef?.current) { const input = negativePromptRef.current as HTMLInputElement input.blur() } }) const onKeyUp = (e: React.KeyboardEvent) => { // negativePrompt 回车触发 inpainting if (e.key === "Enter" && e.ctrlKey && settings.prompt.length !== 0) { runInpainting() } } const renderCropper = () => { return ( { updateSettings({ showCropper: value }) if (value) { updateSettings({ showExtender: false }) } }} /> ) } const renderBrushNetSetting = () => { if (!settings.model.support_brushnet) { return null } let toolTip = "BrushNet is a plug-and-play image inpainting model works on any SD1.5 base models." return (
{ updateEnableBrushNet(value) }} /> {/* updateSettings({ brushnetConditioningScale: vals[0] / 100 }) } /> { updateSettings({ brushnetConditioningScale: val }) }} /> */}
) } const renderConterNetSetting = () => { if (!settings.model.support_controlnet) { return null } let toolTip = "Using an additional conditioning image to control how an image is generated" return (
{ updateEnableControlnet(value) }} />
updateSettings({ controlnetConditioningScale: vals[0] / 100 }) } /> { updateSettings({ controlnetConditioningScale: val }) }} />
) } const renderLCMLora = () => { if (!settings.model.support_lcm_lora) { return null } let toolTip = "Enable quality image generation in typically 2-8 steps. Suggest disabling guidance_scale by setting it to 0. You can also try values between 1.0 and 2.0. When LCM Lora is enabled, LCMSampler will be used automatically." return ( <> { updateLCMLora(value) }} /> ) } const renderNegativePrompt = () => { if (!settings.model.need_prompt) { return null } return (