Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 17,745 Bytes
1c1e6e9 11d758a b022cb9 11d758a 1c1e6e9 b022cb9 11d758a 4f8f050 b022cb9 11d758a faf4ba4 11d758a b022cb9 1c1e6e9 11d758a b022cb9 11d758a b022cb9 11d758a b022cb9 11d758a 2f9a87c b022cb9 2f9a87c b022cb9 2f9a87c 1c1e6e9 b022cb9 b1fd525 1c1e6e9 4f8f050 b022cb9 11d758a c1936bb 11d758a 1c1e6e9 11d758a ff7ca75 11d758a 1c1e6e9 11d758a faf4ba4 1c1e6e9 faf4ba4 11d758a 1c1e6e9 11d758a 9bb9c53 11d758a 1c1e6e9 11d758a 1c1e6e9 11d758a b022cb9 11d758a 1c1e6e9 11d758a 1c1e6e9 11d758a 1c1e6e9 11d758a 1c1e6e9 7563597 11d758a 1c1e6e9 81f7921 b022cb9 81f7921 b022cb9 81f7921 b022cb9 1c1e6e9 2f9a87c 11d758a |
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 133 134 135 136 137 138 139 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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
"use client"
import { useState } from "react"
import { useLocalStorage } from 'usehooks-ts'
import { Button } from "@/components/ui/button"
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select"
import { LLMVendor, RenderingModelVendor } from "@/types"
import { Input } from "@/components/ui/input"
import { Label } from "./label"
import { Field } from "./field"
import { localStorageKeys } from "./localStorageKeys"
import { defaultSettings } from "./defaultSettings"
import { useDynamicConfig } from "@/lib/useDynamicConfig"
import { Slider } from "@/components/ui/slider"
import { fonts } from "@/lib/fonts"
import { cn } from "@/lib/utils"
import { SectionTitle } from "./section-title"
export function SettingsDialog() {
const [isOpen, setOpen] = useState(false)
const [renderingModelVendor, setRenderingModelVendor] = useLocalStorage<RenderingModelVendor>(
localStorageKeys.renderingModelVendor,
defaultSettings.renderingModelVendor
)
const [renderingUseTurbo, setRenderingUseTurbo] = useLocalStorage<boolean>(
localStorageKeys.renderingUseTurbo,
defaultSettings.renderingUseTurbo
)
const [llmVendor, setLlmModelVendor] = useLocalStorage<LLMVendor>(
localStorageKeys.llmVendor,
defaultSettings.llmVendor
)
const [huggingfaceApiKey, setHuggingfaceApiKey] = useLocalStorage<string>(
localStorageKeys.huggingfaceApiKey,
defaultSettings.huggingfaceApiKey
)
const [huggingfaceInferenceApiModel, setHuggingfaceInferenceApiModel] = useLocalStorage<string>(
localStorageKeys.huggingfaceInferenceApiModel,
defaultSettings.huggingfaceInferenceApiModel
)
const [huggingfaceInferenceApiModelTrigger, setHuggingfaceInferenceApiModelTrigger] = useLocalStorage<string>(
localStorageKeys.huggingfaceInferenceApiModelTrigger,
defaultSettings.huggingfaceInferenceApiModelTrigger
)
const [huggingfaceInferenceApiFileType, setHuggingfaceInferenceApiFileType] = useLocalStorage<string>(
localStorageKeys.huggingfaceInferenceApiFileType,
defaultSettings.huggingfaceInferenceApiFileType
)
const [replicateApiKey, setReplicateApiKey] = useLocalStorage<string>(
localStorageKeys.replicateApiKey,
defaultSettings.replicateApiKey
)
const [replicateApiModel, setReplicateApiModel] = useLocalStorage<string>(
localStorageKeys.replicateApiModel,
defaultSettings.replicateApiModel
)
const [replicateApiModelVersion, setReplicateApiModelVersion] = useLocalStorage<string>(
localStorageKeys.replicateApiModelVersion,
defaultSettings.replicateApiModelVersion
)
const [replicateApiModelTrigger, setReplicateApiModelTrigger] = useLocalStorage<string>(
localStorageKeys.replicateApiModelTrigger,
defaultSettings.replicateApiModelTrigger
)
const [openaiApiKey, setOpenaiApiKey] = useLocalStorage<string>(
localStorageKeys.openaiApiKey,
defaultSettings.openaiApiKey
)
const [openaiApiModel, setOpenaiApiModel] = useLocalStorage<string>(
localStorageKeys.openaiApiModel,
defaultSettings.openaiApiModel
)
const [openaiApiLanguageModel, setOpenaiApiLanguageModel] = useLocalStorage<string>(
localStorageKeys.openaiApiLanguageModel,
defaultSettings.openaiApiLanguageModel
)
const [groqApiKey, setGroqApiKey] = useLocalStorage<string>(
localStorageKeys.groqApiKey,
defaultSettings.groqApiKey
)
const [groqApiLanguageModel, setGroqApiLanguageModel] = useLocalStorage<string>(
localStorageKeys.groqApiLanguageModel,
defaultSettings.groqApiLanguageModel
)
const [anthropicApiKey, setAnthropicApiKey] = useLocalStorage<string>(
localStorageKeys.anthropicApiKey,
defaultSettings.anthropicApiKey
)
const [anthropicApiLanguageModel, setAnthropicApiLanguageModel] = useLocalStorage<string>(
localStorageKeys.anthropicApiLanguageModel,
defaultSettings.anthropicApiLanguageModel
)
const [userDefinedMaxNumberOfPages, setUserDefinedMaxNumberOfPages] = useLocalStorage<number>(
localStorageKeys.userDefinedMaxNumberOfPages,
defaultSettings.userDefinedMaxNumberOfPages
)
const { config: { maxNbPages }, isConfigReady } = useDynamicConfig()
return (
<Dialog open={isOpen} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button className="space-x-1 md:space-x-2">
<div>
<span className="">Settings</span>
</div>
</Button>
</DialogTrigger>
<DialogContent className="w-full sm:max-w-[500px] md:max-w-[700px] bg-gray-100">
<DialogHeader>
<DialogDescription className="w-full text-center text-2xl font-bold text-stone-800">
AI Comic Factory Settings
</DialogDescription>
</DialogHeader>
<div className="overflow-y-scroll h-[75vh] md:h-[70vh]">
<p className="text-base italic text-zinc-600 w-full text-center">
βΉοΈ Some models can take time to cold-start, or be under heavy traffic.<br/>
π In case of trouble, try again after 5-10 minutes.<br/>
π Your settings are stored inside your browser, not on our servers.
</p>
<SectionTitle>π General options</SectionTitle>
{isConfigReady && <Field>
<Label className="pt-2">Move the slider to set the total expected number of pages: {userDefinedMaxNumberOfPages}</Label>
<Slider
min={1}
max={maxNbPages}
step={1}
onValueChange={(value: any) => {
let numericValue = Number(value[0])
numericValue = !isNaN(value[0]) && isFinite(value[0]) ? numericValue : 0
numericValue = Math.min(maxNbPages, Math.max(1, numericValue))
setUserDefinedMaxNumberOfPages(numericValue)
}}
defaultValue={[userDefinedMaxNumberOfPages]}
value={[userDefinedMaxNumberOfPages]}
/>
</Field>
}
<div className={cn(
`grid gap-2 pt-3 pb-1`,
`text-stone-800`
)}>
{
// renderingModelVendor === "SERVER" && <>
// <Field>
// <Label>Quality over performance ratio (beta, deprecated):</Label>
// <div className="flex flex-row space-x-2 text-zinc-500">
// <Switch
// // checked={renderingUseTurbo}
// // onCheckedChange={setRenderingUseTurbo}
// checked={false}
// disabled
// className="opacity-30 pointer-events-none"
// />
// {/*
// <span
// onClick={() => setRenderingUseTurbo(!renderingUseTurbo)}
// className={cn("cursor-pointer", { "text-zinc-800": renderingUseTurbo })}>
// Use a faster, but lower quality model (you are warned!)
// </span>
// */}
// <span className="text-zinc-500 italic">
// Following feedbacks from users (low rendering quality on comics) the fast renderer has been disabled.
// </span>
// </div>
// </Field>
// </>
}
<SectionTitle>π Panel rendering options</SectionTitle>
<Field>
<Label className={cn(
)}>Image generation - please choose a stable diffusion provider:</Label>
<Select
onValueChange={(value: string) => {
setRenderingModelVendor(value as RenderingModelVendor)
}}
defaultValue={renderingModelVendor}
value={renderingModelVendor}>
<SelectTrigger className="bg-white">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="SERVER">Default Hugging Face server (free but limited capacity, not always online)</SelectItem>
<SelectItem value="HUGGINGFACE">Custom Inference API model (pro hugging face account recommended)</SelectItem>
<SelectItem value="REPLICATE">Custom Replicate model (will bill your own account)</SelectItem>
<SelectItem value="OPENAI">DALLΒ·E 3 by OpenAI (partial support, will bill your own account)</SelectItem>
</SelectContent>
</Select>
</Field>
{renderingModelVendor === "HUGGINGFACE" && <>
<Field>
<Label>Hugging Face API Token (<a className="text-stone-600 underline" href="https://huggingface.co/subscribe/pro" target="_blank">PRO account</a> recommended for higher rate limit):</Label>
<Input
className={fonts.actionman.className}
type="password"
placeholder="Enter your private api token"
onChange={(x) => {
setHuggingfaceApiKey(x.target.value)
}}
value={huggingfaceApiKey}
/>
</Field>
<Field>
<Label>Inference API model (custom SDXL or SDXL LoRA):</Label>
<Input
className={fonts.actionman.className}
placeholder="Name of the Inference API model"
onChange={(x) => {
setHuggingfaceInferenceApiModel(x.target.value)
}}
value={huggingfaceInferenceApiModel}
/>
</Field>
<Field>
<Label>The file type supported by the model (jpg, webp..):</Label>
<Input
className={fonts.actionman.className}
placeholder="Inference API file type"
onChange={(x) => {
setHuggingfaceInferenceApiFileType(x.target.value)
}}
value={huggingfaceInferenceApiFileType}
/>
</Field>
<p className="text-sm text-zinc-700">
Using a LoRA? Don't forget the trigger keyword! Also you will want to use the "Neutral" style.
</p>
<Field>
<Label>LoRA model trigger (optional):</Label>
<Input
className={fonts.actionman.className}
placeholder="Trigger keyword (if you use a LoRA)"
onChange={(x) => {
setHuggingfaceInferenceApiModelTrigger(x.target.value)
}}
value={huggingfaceInferenceApiModelTrigger}
/>
</Field>
</>}
{renderingModelVendor === "OPENAI" && <>
<Field>
<Label>OpenAI API Token (you will be billed based on OpenAI pricing):</Label>
<Input
className={fonts.actionman.className}
type="password"
placeholder="Enter your private api token"
onChange={(x) => {
setOpenaiApiKey(x.target.value)
}}
value={openaiApiKey}
/>
</Field>
<Field>
<Label>OpenAI image model:</Label>
<Input
className={fonts.actionman.className}
placeholder="OpenAI image model"
onChange={(x) => {
setOpenaiApiModel(x.target.value)
}}
value={openaiApiModel}
/>
</Field>
</>}
{renderingModelVendor === "REPLICATE" && <>
<Field>
<Label>Replicate API Token:</Label>
<Input
className={fonts.actionman.className}
type="password"
placeholder="Enter your private api token"
onChange={(x) => {
setReplicateApiKey(x.target.value)
}}
value={replicateApiKey}
/>
</Field>
<Field>
<Label>Replicate model name:</Label>
<Input
className={fonts.actionman.className}
placeholder="Name of the Replicate model"
onChange={(x) => {
setReplicateApiModel(x.target.value)
}}
value={replicateApiModel}
/>
</Field>
<Field>
<Label>Model version:</Label>
<Input
className={fonts.actionman.className}
placeholder="Version of the Replicate model"
onChange={(x) => {
setReplicateApiModelVersion(x.target.value)
}}
value={replicateApiModelVersion}
/>
</Field>
<p className="text-sm text-zinc-700">
Using a LoRA? Don't forget the trigger keyword! Also you will want to use the "Neutral" style.
</p>
<Field>
<Label>LoRA model trigger (optional):</Label>
<Input
className={fonts.actionman.className}
placeholder={'Eg. "In the style of TOK" etc'}
onChange={(x) => {
setReplicateApiModelTrigger(x.target.value)
}}
value={replicateApiModelTrigger}
/>
</Field>
</>}
<SectionTitle>π Story generation options (π§ experimental feature π§)</SectionTitle>
<p>β οΈ Some vendors might be buggy or require tunning, please report issues to Discord.<br/>
β οΈ Billing and privacy depend on your preferred vendor, so please exercice caution.</p>
<Field>
<Label className={cn(
"mt-2"
)}>Story generation - please choose a LLM provider:</Label>
<Select
onValueChange={(value: string) => {
setLlmModelVendor(value as LLMVendor)
}}
defaultValue={llmVendor}
value={llmVendor}>
<SelectTrigger className="bg-white">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="SERVER">Default Hugging Face server (free but limited capacity, not always online)</SelectItem>
<SelectItem value="GROQ">Open-source models on Groq (will bill your own account)</SelectItem>
<SelectItem value="ANTHROPIC">Claude by Anthropic (will bill your own account)</SelectItem>
<SelectItem value="OPENAI">ChatGPT by OpenAI (will bill your own account)</SelectItem>
</SelectContent>
</Select>
</Field>
{llmVendor === "GROQ" && <>
<Field>
<Label>Groq API Token:</Label>
<Input
className={fonts.actionman.className}
type="password"
placeholder="Enter your private api token"
onChange={(x) => {
setGroqApiKey(x.target.value)
}}
value={groqApiKey}
/>
</Field>
<Field>
<Label>Open-source Model ID:</Label>
<Input
className={fonts.actionman.className}
placeholder="Name of the LLM"
onChange={(x) => {
setGroqApiLanguageModel(x.target.value)
}}
value={groqApiLanguageModel}
/>
</Field>
</>}
{llmVendor === "ANTHROPIC" && <>
<Field>
<Label>Anthropic API Token:</Label>
<Input
className={fonts.actionman.className}
type="password"
placeholder="Enter your private api token"
onChange={(x) => {
setAnthropicApiKey(x.target.value)
}}
value={anthropicApiKey}
/>
</Field>
<Field>
<Label>Proprietary Model ID:</Label>
<Input
className={fonts.actionman.className}
placeholder="Name of the LLM"
onChange={(x) => {
setAnthropicApiLanguageModel(x.target.value)
}}
value={anthropicApiLanguageModel}
/>
</Field>
</>}
{llmVendor === "OPENAI" && <>
<Field>
<Label>OpenAI API Token:</Label>
<Input
className={fonts.actionman.className}
type="password"
placeholder="Enter your private api token"
onChange={(x) => {
setOpenaiApiKey(x.target.value)
}}
value={openaiApiKey}
/>
</Field>
<Field>
<Label>Proprietary Model ID:</Label>
<Input
className={fonts.actionman.className}
placeholder="Name of the LLM"
onChange={(x) => {
setOpenaiApiLanguageModel(x.target.value)
}}
value={openaiApiLanguageModel}
/>
</Field>
</>}
</div>
</div>
<DialogFooter>
<Button type="submit" onClick={() => setOpen(false)}>Close</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
} |