mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-11 04:16:55 +00:00
lora uploads enqueue
This commit is contained in:
1 parent
b7e8c97c93
commit
98cbd2abb9
5 files changed
+138
-98
No files matched your search
@@ -5,6 +5,7 @@ import { InferenceJobsContext } from 'context';
|
||||
|
||||
export default function useInferenceJobs(jobType: FrontendInferenceJobType) {
|
||||
const { byCategory, enqueue } = useContext(InferenceJobsContext);
|
||||
|
||||
return {
|
||||
enqueue,
|
||||
inferenceJobs: (byCategory?.get(jobType) || []),
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { useState } from "react";
|
||||
import { UploadModel } from "@storyteller/components/src/api/image_generation/UploadModel";
|
||||
import { FetchStatus } from "@storyteller/components/src/api/_common/SharedFetchTypes";
|
||||
import { useCoverImgUpload } from "hooks";
|
||||
import { useCoverImgUpload, useInferenceJobs } from "hooks";
|
||||
import { FrontendInferenceJobType } from "@storyteller/components/src/jobs/InferenceJob";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
// this hook is mostly for organizational purposes while I work -V
|
||||
@@ -13,6 +14,7 @@ export default function useLoraUpload() {
|
||||
const [descriptionMD, descriptionMDSet] = useState("");
|
||||
const [writeStatus, writeStatusSet] = useState(FetchStatus.paused);
|
||||
const coverImg = useCoverImgUpload();
|
||||
const { enqueue } = useInferenceJobs(FrontendInferenceJobType.ImageGeneration);
|
||||
|
||||
const onChange = ({ target }: { target: { name: string; value: any } }) => {
|
||||
const todo: { [key: string]: (x: any) => void } = {
|
||||
@@ -38,9 +40,11 @@ export default function useLoraUpload() {
|
||||
visibility,
|
||||
})
|
||||
.then((res: any) => {
|
||||
writeStatusSet(FetchStatus.success);
|
||||
console.log("🌠", res);
|
||||
// history.replace(`/weight/${token}`);
|
||||
if (res.success && res.inference_job_token) {
|
||||
console.log("🌠", res);
|
||||
writeStatusSet(FetchStatus.success);
|
||||
enqueue(res.inference_job_token, FrontendInferenceJobType.ImageGeneration);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
writeStatusSet(FetchStatus.error);
|
||||
|
||||
@@ -71,17 +71,16 @@ export default function useWeightFetch({ onRemove = n, onSuccess = n, token }: P
|
||||
statusSet(FetchStatus.in_progress);
|
||||
GetWeight(token, {})
|
||||
.then((res: any) => {
|
||||
let {
|
||||
creator_set_visibility,
|
||||
description_markdown,
|
||||
title: resTitle,
|
||||
} = res;
|
||||
statusSet(FetchStatus.success);
|
||||
titleSet(resTitle);
|
||||
descriptionMDSet(description_markdown);
|
||||
visibilitySet(creator_set_visibility);
|
||||
onSuccess(res);
|
||||
setData(res);
|
||||
if (res.success) {
|
||||
let { creator_set_visibility, description_markdown, title: resTitle } = res;
|
||||
|
||||
statusSet(FetchStatus.success);
|
||||
titleSet(resTitle);
|
||||
descriptionMDSet(description_markdown);
|
||||
visibilitySet(creator_set_visibility);
|
||||
onSuccess(res);
|
||||
setData(res);
|
||||
} else { statusSet(FetchStatus.error); }
|
||||
})
|
||||
.catch(err => {
|
||||
statusSet(FetchStatus.error);
|
||||
|
||||
@@ -15,6 +15,8 @@ import {
|
||||
TempSelect,
|
||||
TempTextArea,
|
||||
} from "components/common";
|
||||
import { FrontendInferenceJobType } from "@storyteller/components/src/jobs/InferenceJob";
|
||||
import InferenceJobsList from "components/layout/InferenceJobsList";
|
||||
import { SessionWrapper } from "@storyteller/components/src/session/SessionWrapper";
|
||||
import useLoraUpload from "hooks/useLoraUpload";
|
||||
|
||||
@@ -32,6 +34,14 @@ export default function UploadLoraWeightPage({
|
||||
{ label: "Private", value: "private" },
|
||||
];
|
||||
|
||||
|
||||
const failures = (fail = "") => {
|
||||
switch (fail) {
|
||||
default:
|
||||
return "Uknown failure";
|
||||
}
|
||||
};
|
||||
|
||||
const {
|
||||
coverImg,
|
||||
descriptionMD,
|
||||
@@ -66,6 +76,12 @@ export default function UploadLoraWeightPage({
|
||||
|
||||
return (
|
||||
<Container type="panel">
|
||||
<InferenceJobsList
|
||||
{...{
|
||||
failures,
|
||||
jobType: FrontendInferenceJobType.ImageGeneration,
|
||||
}}
|
||||
/>
|
||||
<PageHeader
|
||||
title="Upload LoRA Weight"
|
||||
titleIcon={faWaveform}
|
||||
|
||||
@@ -48,10 +48,11 @@ export default function WeightEditPage({
|
||||
update,
|
||||
visibility,
|
||||
writeStatus,
|
||||
// status
|
||||
} = useWeightFetch({ token: weight_token });
|
||||
|
||||
const basePath =
|
||||
weight?.cover_image.maybe_cover_image_public_bucket_path || "";
|
||||
weight?.cover_image?.maybe_cover_image_public_bucket_path || "";
|
||||
const currentPath = basePath ? new BucketConfig().getGcsUrl(basePath) : "";
|
||||
|
||||
usePrefixedDocumentTitle("Edit Voice");
|
||||
@@ -63,7 +64,21 @@ export default function WeightEditPage({
|
||||
|
||||
let weightToken = weight?.creator?.user_token;
|
||||
|
||||
if (!weightToken || !canEditTtsModel(user?.user_token || "")) {
|
||||
if (isLoading) {
|
||||
return <Panel padding={true}>
|
||||
<div className="d-flex flex-column gap-3">
|
||||
<Skeleton type="short" />
|
||||
<Skeleton height="40px" />
|
||||
<Skeleton type="short" />
|
||||
<Skeleton height="40px" />
|
||||
<div className="d-flex justify-content-end mt-3 gap-2">
|
||||
<Skeleton height="40px" width="120px" />
|
||||
<Skeleton height="40px" width="120px" />
|
||||
</div>
|
||||
</div>
|
||||
</Panel>;
|
||||
} else {
|
||||
if (!weightToken) {
|
||||
return (
|
||||
<Container type="panel">
|
||||
<PageHeader
|
||||
@@ -85,6 +100,28 @@ export default function WeightEditPage({
|
||||
);
|
||||
}
|
||||
|
||||
if (!canEditTtsModel(user?.user_token || "")) {
|
||||
return (
|
||||
<Container type="panel">
|
||||
<PageHeader
|
||||
titleIcon={faCircleExclamation}
|
||||
title="Access Denied"
|
||||
subText="You do not have permission to edit this model."
|
||||
panel={true}
|
||||
extension={
|
||||
<div className="d-flex">
|
||||
<Button
|
||||
label="Back to homepage"
|
||||
to={`/weight/{}`}
|
||||
className="d-flex"
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container type="panel" className="mb-5">
|
||||
<PageHeader
|
||||
@@ -96,89 +133,72 @@ export default function WeightEditPage({
|
||||
backbuttonLabel="Back"
|
||||
backbuttonTo={`/weight/${weight_token}`}
|
||||
/>
|
||||
|
||||
<>
|
||||
{isLoading ? (
|
||||
<Panel padding={true}>
|
||||
<div className="d-flex flex-column gap-3">
|
||||
<Skeleton type="short" />
|
||||
<Skeleton height="40px" />
|
||||
<Skeleton type="short" />
|
||||
<Skeleton height="40px" />
|
||||
<div className="d-flex justify-content-end mt-3 gap-2">
|
||||
<Skeleton height="40px" width="120px" />
|
||||
<Skeleton height="40px" width="120px" />
|
||||
<SplitPanel {...{ busy: writeStatus > 0, dividerFooter: true }}>
|
||||
<SplitPanel.Body padding={true}>
|
||||
<div {...{ className: "weight-editor row gy-3 gx-4" }}>
|
||||
<div {...{ className: "col-12 col-lg-5" }}>
|
||||
<label className="sub-title">Cover Image</label>
|
||||
<CoverImageInput
|
||||
{...{
|
||||
currentPath,
|
||||
onClick: coverImg.upload,
|
||||
status: coverImg.status,
|
||||
...coverImg.fileProps,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div {...{ className: "col-lg-7 order-first order-lg-last" }}>
|
||||
<TempInput
|
||||
{...{
|
||||
label: "Title",
|
||||
name: "title",
|
||||
onChange,
|
||||
placeholder: "Title",
|
||||
value: title,
|
||||
}}
|
||||
/>
|
||||
<TempSelect
|
||||
{...{
|
||||
icon: faEye,
|
||||
label: "Visibility",
|
||||
name: "visibility",
|
||||
options: visibilityOptions,
|
||||
onChange,
|
||||
placeholder: "Voice name",
|
||||
value: visibility,
|
||||
}}
|
||||
/>
|
||||
<TempTextArea
|
||||
{...{
|
||||
label: "Description",
|
||||
name: "descriptionMD",
|
||||
onChange,
|
||||
placeholder: "Description",
|
||||
value: descriptionMD,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Panel>
|
||||
) : (
|
||||
<SplitPanel {...{ busy: writeStatus > 0, dividerFooter: true }}>
|
||||
<SplitPanel.Body padding={true}>
|
||||
<div {...{ className: "weight-editor row gy-3 gx-4" }}>
|
||||
<div {...{ className: "col-12 col-lg-5" }}>
|
||||
<label className="sub-title">Cover Image</label>
|
||||
<CoverImageInput
|
||||
{...{
|
||||
currentPath,
|
||||
onClick: coverImg.upload,
|
||||
status: coverImg.status,
|
||||
...coverImg.fileProps,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div {...{ className: "col-lg-7 order-first order-lg-last" }}>
|
||||
<TempInput
|
||||
{...{
|
||||
label: "Title",
|
||||
name: "title",
|
||||
onChange,
|
||||
placeholder: "Title",
|
||||
value: title,
|
||||
}}
|
||||
/>
|
||||
<TempSelect
|
||||
{...{
|
||||
icon: faEye,
|
||||
label: "Visibility",
|
||||
name: "visibility",
|
||||
options: visibilityOptions,
|
||||
onChange,
|
||||
placeholder: "Voice name",
|
||||
value: visibility,
|
||||
}}
|
||||
/>
|
||||
<TempTextArea
|
||||
{...{
|
||||
label: "Description",
|
||||
name: "descriptionMD",
|
||||
onChange,
|
||||
placeholder: "Description",
|
||||
value: descriptionMD,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</SplitPanel.Body>
|
||||
<SplitPanel.Footer padding={true}>
|
||||
<div className="d-flex gap-2 justify-content-end">
|
||||
<Button
|
||||
{...{
|
||||
label: "Cancel",
|
||||
to: `/weight/${weight_token}`,
|
||||
variant: "secondary",
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
{...{
|
||||
label: "Save Changes",
|
||||
onClick: update,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</SplitPanel.Footer>
|
||||
</SplitPanel>
|
||||
)}
|
||||
</>
|
||||
</SplitPanel.Body>
|
||||
<SplitPanel.Footer padding={true}>
|
||||
<div className="d-flex gap-2 justify-content-end">
|
||||
<Button
|
||||
{...{
|
||||
label: "Cancel",
|
||||
to: `/weight/${weight_token}`,
|
||||
variant: "secondary",
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
{...{
|
||||
label: "Save Changes",
|
||||
onClick: update,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</SplitPanel.Footer>
|
||||
</SplitPanel>
|
||||
</Container>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user