Spaces:
Running
Running
File size: 8,547 Bytes
f27679f f62b8d3 4c34e70 851546d f62b8d3 df83860 f62b8d3 851546d f27679f a3f1817 4c34e70 d160b97 f62b8d3 4c34e70 f62b8d3 f27679f f62b8d3 4c34e70 f27679f f62b8d3 4c34e70 a3f1817 f62b8d3 a3f1817 f62b8d3 f27679f a3f1817 f62b8d3 f27679f a3f1817 f62b8d3 a3f1817 f62b8d3 a3f1817 f62b8d3 a3f1817 f62b8d3 f27679f 851546d 4c34e70 f27679f f62b8d3 a3f1817 f62b8d3 f27679f f62b8d3 4c34e70 f62b8d3 851546d f62b8d3 851546d f62b8d3 f27679f f62b8d3 f27679f f62b8d3 f27679f 4c34e70 f27679f f62b8d3 f27679f a3f1817 f27679f f62b8d3 |
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 |
"use client"
import { useEffect, useState, useTransition } from "react"
import { useStore } from "@/app/state/useStore"
import { cn } from "@/lib/utils"
import { VideoGenerationModel, VideoInfo } from "@/types"
import { useLocalStorage } from "usehooks-ts"
import { localStorageKeys } from "@/app/state/localStorageKeys"
import { defaultSettings } from "@/app/state/defaultSettings"
import { Input } from "@/components/ui/input"
import { Textarea } from "@/components/ui/textarea"
import { Button } from "@/components/ui/button"
import { submitVideoRequest } from "@/app/server/actions/submitVideoRequest"
import { PendingVideoList } from "@/app/interface/pending-video-list"
import { getChannelVideos } from "@/app/server/actions/ai-tube-hf/getChannelVideos"
import { parseVideoModelName } from "@/app/server/actions/utils/parseVideoModelName"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { defaultVideoModel, defaultVoice } from "@/app/config"
export function UserChannelView() {
const [_isPending, startTransition] = useTransition()
const [huggingfaceApiKey, setHuggingfaceApiKey] = useLocalStorage<string>(
localStorageKeys.huggingfaceApiKey,
defaultSettings.huggingfaceApiKey
)
const [titleDraft, setTitleDraft] = useState("")
const [descriptionDraft, setDescriptionDraft] = useState("")
const [tagsDraft, setTagsDraft] = useState("")
const [promptDraft, setPromptDraft] = useState("")
const [modelDraft, setModelDraft] = useState<VideoGenerationModel>(defaultVideoModel)
const [loraDraft, setLoraDraft] = useState("")
const [styleDraft, setStyleDraft] = useState("")
const [voiceDraft, setVoiceDraft] = useState(defaultVoice)
const [musicDraft, setMusicDraft] = useState("")
// we do not include the tags in the list of required fields
const missingFields = !titleDraft || !descriptionDraft || !promptDraft
const [isSubmitting, setIsSubmitting] = useState(false)
const userChannel = useStore(s => s.userChannel)
const userChannels = useStore(s => s.userChannels)
const userVideos = useStore(s => s.userVideos)
const setUserChannel = useStore(s => s.setUserChannel)
const setUserChannels = useStore(s => s.setUserChannels)
const setUserVideos = useStore(s => s.setUserVideos)
useEffect(() => {
if (!userChannel) {
return
}
startTransition(async () => {
const videos = await getChannelVideos({
channel: userChannel,
// status: undefined, // we want *all* status
})
console.log("setCurrentVideos:", videos)
setUserVideos(videos)
})
}, [huggingfaceApiKey, userChannel, userChannel?.id])
const handleSubmit = () => {
if (!userChannel) {
return
}
if (!titleDraft || !promptDraft) {
console.log("missing title or prompt")
return
}
setIsSubmitting(true)
startTransition(async () => {
try {
const newVideo = await submitVideoRequest({
channel: userChannel,
apiKey: huggingfaceApiKey,
title: titleDraft,
description: descriptionDraft,
prompt: promptDraft,
model: modelDraft,
lora: loraDraft,
style: styleDraft,
voice: voiceDraft,
music: musicDraft,
tags: tagsDraft.trim().split(",").map(x => x.trim()).filter(x => x),
})
// in case of success we update the frontend immediately
// with our draft video
setUserVideos([newVideo, ...userVideos])
setPromptDraft("")
setDescriptionDraft("")
setTagsDraft("")
setTitleDraft("")
setModelDraft(defaultVideoModel)
setVoiceDraft(defaultVoice)
setMusicDraft("")
setLoraDraft("")
setStyleDraft("")
// also renew the cache on Next's side
/*
await getChannelVideos({
channel: currentChannel,
apiKey: huggingfaceApiKey,
renewCache: true,
})
*/
} catch (err) {
console.error(err)
} finally {
setIsSubmitting(false)
}
})
}
const handleDelete = (video: VideoInfo) => {
// step 1: delete it from the dataset
// step 2: if the video has already been generated,
// we ask the robot to delete it from the index
}
return (
<div className={cn(
`flex flex-col space-y-8`
)}>
<div className="flex flex-col space-y-8 max-w-4xl">
<h2 className="text-3xl font-bold">Robot channel settings:</h2>
<p>TODO</p>
<h2 className="text-3xl font-bold">Create a new AI video:</h2>
<div className="flex flex-row space-x-2 items-start">
<label className="flex w-24 pt-1">Title (required):</label>
<div className="flex flex-col space-y-2 flex-grow">
<Input
placeholder="Title"
className="font-mono"
onChange={(x) => {
setTitleDraft(x.target.value)
}}
value={titleDraft}
/>
</div>
</div>
<div className="flex flex-row space-x-2 items-start">
<label className="flex w-24 pt-1">Description (required):</label>
<div className="flex flex-col space-y-2 flex-grow">
<Textarea
placeholder="Description"
className="font-mono"
rows={2}
onChange={(x) => {
setDescriptionDraft(x.target.value)
}}
value={descriptionDraft}
/>
<p className="text-neutral-100/70">
Short description (visible to humans, and used as context by the AI).
</p>
</div>
</div>
<div className="flex flex-row space-x-2 items-start">
<label className="flex w-24 pt-1">Prompt (required):</label>
<div className="flex flex-col space-y-2 flex-grow">
<Textarea
placeholder="Prompt"
className="font-mono"
rows={6}
onChange={(x) => {
setPromptDraft(x.target.value)
}}
value={promptDraft}
/>
<p className="text-neutral-100/70">
Describe your video content, in a synthetic way.
</p>
</div>
</div>
<div className="flex flex-row space-x-2 items-start">
<label className="flex w-24 pt-1">Video model:</label>
<div className="flex flex-col space-y-2 flex-grow">
<Select
onValueChange={(value: string) => {
setModelDraft(parseVideoModelName(value, defaultVideoModel))
}}
defaultValue={defaultVideoModel}>
<SelectTrigger className="">
<SelectValue placeholder="Video model" />
</SelectTrigger>
<SelectContent>
<SelectItem value="SVD">SVD</SelectItem>
<SelectItem value="HotshotXL">HotshotXL</SelectItem>
<SelectItem value="LaVie">LaVie</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<div className="flex flex-row space-x-2 items-start">
<label className="flex w-24 pt-1">Tags (optional):</label>
<div className="flex flex-col space-y-2 flex-grow">
<Input
placeholder="Tags"
className="font-mono"
onChange={(x) => {
setTagsDraft(x.target.value)
}}
value={tagsDraft}
/>
<p className="text-neutral-100/70">
Comma-separated tags (eg. "Education, Sports")
</p>
</div>
</div>
<div className="flex flex-row space-x-2 items-center justify-between">
<Button
onClick={handleSubmit}
disabled={isSubmitting}
className={cn(
isSubmitting || missingFields ? `opacity-50` : `opacity-100`
)}
>
{missingFields ? 'Please fill the form' : isSubmitting ? 'Adding to the queue..' : 'Add prompt to the queue'}
</Button>
<p>Note: It can take a few hours for the video to be generated.</p>
</div>
</div>
<h2 className="text-3xl font-bold">Current video prompts:</h2>
<PendingVideoList
videos={userVideos}
onDelete={handleDelete}
/>
</div>
)
} |