File size: 9,958 Bytes
f27679f
 
f62b8d3
 
 
f42b4a1
ac7030c
851546d
f62b8d3
df83860
f62b8d3
 
 
 
3d4392e
f42b4a1
3d4392e
 
4c34e70
0f35d4c
3d4392e
f62b8d3
 
 
 
 
 
 
4c34e70
0f35d4c
 
 
 
 
 
 
 
 
 
 
4c34e70
f27679f
0f35d4c
f27679f
f62b8d3
 
4c34e70
a3f1817
 
 
 
 
 
 
f62b8d3
 
a3f1817
f62b8d3
 
 
 
f27679f
a3f1817
 
 
f62b8d3
f27679f
 
 
a3f1817
f62b8d3
 
a3f1817
f62b8d3
 
a3f1817
f62b8d3
 
0f35d4c
f62b8d3
 
 
 
 
 
 
 
 
a3f1817
f62b8d3
0f35d4c
 
 
 
 
 
 
 
 
 
 
f62b8d3
 
 
0f35d4c
a3f1817
0f35d4c
 
 
 
 
 
 
 
 
4c34e70
f62b8d3
851546d
f62b8d3
 
 
 
 
851546d
f62b8d3
 
 
 
 
 
 
 
ac7030c
f27679f
 
 
 
 
 
 
 
f62b8d3
 
 
 
f27679f
 
 
 
 
 
 
 
 
 
 
 
 
0f35d4c
f27679f
0f35d4c
f27679f
 
f62b8d3
 
f27679f
 
 
 
 
 
 
 
 
0f35d4c
f27679f
0f35d4c
f27679f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f35d4c
f27679f
0f35d4c
f27679f
 
 
 
 
 
 
4c34e70
 
 
 
 
0f35d4c
4c34e70
 
 
 
 
 
0f35d4c
4c34e70
 
 
 
 
 
0f35d4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4c34e70
f27679f
 
 
 
 
 
 
0f35d4c
f27679f
0f35d4c
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
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
"use client"

import { useEffect, useState, useTransition } from "react"

import { useStore } from "@/app/state/useStore"
import { cn } from "@/lib/utils/cn"
import { VideoGenerationModel, MediaInfo } from "@/types/general"

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/api/actions/submitVideoRequest"
import { PendingVideoList } from "@/components/interface/pending-video-list"
import { getChannelVideos } from "@/app/api/actions/ai-tube-hf/getChannelVideos"
import { parseVideoModelName } from "@/app/api/utils/parseVideoModelName"
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
import { defaultVideoModel, defaultVideoOrientation, defaultVoice } from "@/app/config"
import { parseVideoOrientation } from "@/app/api/utils/parseVideoOrientation"

export function UserChannelView() {
  const [_isPending, startTransition] = useTransition()
  const [huggingfaceApiKey, setHuggingfaceApiKey] = useLocalStorage<string>(
    localStorageKeys.huggingfaceApiKey,
    defaultSettings.huggingfaceApiKey
  )
  
  const [title, setTitle] = useState("")
  const [description, setDescription] = useState("")
  const [tags, setTags] = useState("")
  const [prompt, setPrompt] = useState("")
  const [model, setModel] = useState<VideoGenerationModel>(defaultVideoModel)
  const [lora, setLora] = useState("")
  const [style, setStyle] = useState("")
  const [voice, setVoice] = useState(defaultVoice)
  const [music, setMusic] = useState("")
  const [duration, setDuration] = useState(0)
  const [orientation, setOrientation] = useState(defaultVideoOrientation)

  // we do not include the tags in the list of required fields
  const missingFields = !title || !description || !prompt

  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 (!title || !prompt) {
      console.log("missing title or prompt")
      return
    }

    setIsSubmitting(true)

    startTransition(async () => {
      try {
        const newVideo = await submitVideoRequest({
          channel: userChannel,
          apiKey: huggingfaceApiKey,
          title,
          description,
          prompt,
          model,
          lora,
          style,
          voice,
          music,
          tags: tags.trim().split(",").map(x => x.trim()).filter(x => x),
          duration,
          orientation
        })

        // in case of success we update the frontend immediately
        // with our  video
        setUserVideos([newVideo, ...userVideos])
        setPrompt("")
        setDescription("")
        setTags("")
        setTitle("")
        setModel(defaultVideoModel)
        setVoice(defaultVoice)
        setMusic("")
        setLora("")
        setStyle("")

        // 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: MediaInfo) => {
    // 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) => {
                setTitle(x.target.value)
              }}
              value={title}
            />
          </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) => {
                setDescription(x.target.value)
              }}
              value={description}
            />
            <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) => {
                setPrompt(x.target.value)
              }}
              value={prompt}
            />
            <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) => {
                setModel(parseVideoModelName(value, defaultVideoModel))
              }}
              defaultValue={defaultVideoModel}>
              <SelectTrigger className="">
                <SelectValue placeholder="Video model" />
              </SelectTrigger>
              <SelectContent>
                <SelectItem value="SVD">SVD (default)</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">Video duration:</label>
          <div className="flex flex-col space-y-2 flex-grow">
            <Input
              placeholder="Duration"
              className="font-mono"
              onChange={(x) => {
                // TODO: clamp the value here + on server side
                setDuration(parseInt(x.target.value))
              }}
              value={title}
            />
          </div>
        </div>
        */}
        
        <div className="flex flex-row space-x-2 items-start">
          <label className="flex w-24 pt-1">Video orientation:</label>
          <div className="flex flex-col space-y-2 flex-grow">
            <Select
              onValueChange={(value: string) => {
                setOrientation(parseVideoOrientation(value, defaultVideoOrientation))
              }}
              defaultValue={defaultVideoOrientation}>
              <SelectTrigger className="">
                <SelectValue placeholder="Video orientation" />
              </SelectTrigger>
              <SelectContent>
                <SelectItem value="Landscape">Landscape (default)</SelectItem>
                <SelectItem value="Portrait">Portrait</SelectItem>
                {/* <SelectItem value="LaVie">Square</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) => {
                setTags(x.target.value)
              }}
              value={tags}
            />
            <p className="text-neutral-100/70">
            Comma-separated tags (eg. &quot;Education, Sports&quot;)
            </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>
  )
}