File size: 3,190 Bytes
f62b8d3
 
 
 
 
1185ec1
f27679f
1f1caeb
f62b8d3
 
 
f27679f
f62b8d3
 
 
 
 
 
 
4c34e70
 
 
 
 
f62b8d3
0f35d4c
 
f62b8d3
 
 
 
 
 
4c34e70
 
 
 
 
f62b8d3
0f35d4c
 
f62b8d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f27679f
f62b8d3
 
 
 
4c34e70
f62b8d3
 
 
4c34e70
f62b8d3
 
4c34e70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0f35d4c
 
 
 
 
 
 
 
f62b8d3
 
f27679f
f62b8d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f27679f
f62b8d3
 
 
4c34e70
 
 
 
 
93f8352
1185ec1
 
 
 
f62b8d3
f27679f
f62b8d3
0f35d4c
1f1caeb
 
 
 
 
f62b8d3
 
 
f27679f
f62b8d3
 
851546d
f62b8d3
4c34e70
 
 
 
 
93f8352
1185ec1
 
 
 
f62b8d3
1185ec1
f62b8d3
 
8f2b05f
f62b8d3
f27679f
f62b8d3
0f35d4c
1f1caeb
 
 
 
 
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
"use server"

import { Blob } from "buffer"

import { Credentials, uploadFile, whoAmI } from "@/huggingface/hub/src"
import { ChannelInfo, VideoGenerationModel, VideoInfo, VideoOrientation, VideoRequest } from "@/types/general"
import { formatPromptFileName } from "../utils/formatPromptFileName"
import { computeOrientationProjectionWidthHeight } from "../utils/computeOrientationProjectionWidthHeight"

/**
 * Save the video request to the user's own dataset
 *
 */
export async function uploadVideoRequestToDataset({
  channel,
  apiKey,
  title,
  description,
  prompt,
  model,
  lora,
  style,
  voice,
  music,
  tags,
  duration,
  orientation,
}: {
  channel: ChannelInfo
  apiKey: string
  title: string
  description: string
  prompt: string
  model: VideoGenerationModel
  lora: string
  style: string
  voice: string
  music: string
  tags: string[]
  duration: number
  orientation: VideoOrientation
}): Promise<{
  videoRequest: VideoRequest
  videoInfo: VideoInfo
}> {
  if (!apiKey) {
    throw new Error(`the apiKey is required`)
  }

  let credentials: Credentials = { accessToken: apiKey }

  const { name: username } = await whoAmI({ credentials })
  if (!username) {
    throw new Error(`couldn't get the username`)
  }

  const { id, fileName } = formatPromptFileName()

  // Convert string to a Buffer
  const blob = new Blob([`
# Title

${title}

# Description

${description}

# Model

${model}

# LoRA

${lora}

# Style

${style}

# Voice

${voice}

# Music

${music}

# Duration

${duration}

# Orientation

${orientation}

# Tags

${tags.map(tag => `- ${tag}`).join("\n")}

# Prompt
${prompt}
`]);


  await uploadFile({
	  credentials,
    repo: `datasets/${channel.datasetUser}/${channel.datasetName}`,
    file: {
      path: fileName,
      content: blob as any,
    },
    commitTitle: "Add new video prompt",
  })

  // TODO: now we ping the robot to come read our prompt

  const newVideoRequest: VideoRequest = {
    id,
    label: title,
    description,
    prompt,
    model,
    style,
    lora,
    voice,
    music,
    thumbnailUrl: channel.thumbnail,

    // for now AI Tube doesn't support upload of clap files
    clapUrl: "",

    updatedAt: new Date().toISOString(),
    tags,
    channel,
    duration: 0,
    ...computeOrientationProjectionWidthHeight({
      lora,
      orientation,
      // projection, // <- will be extrapolated from the LoRA for now
    }),
  }

  const newVideo: VideoInfo = {
    id,
    status: "submitted",
    label: title,
    description,
    prompt,
    model,
    style,
    lora,
    voice,
    music,
    thumbnailUrl: channel.thumbnail, // will be generated in async

    // for now AI Tube doesn't support upload of clap files
    clapUrl: "",
    
    assetUrl: "", // will be generated in async
    assetUrlHd: "",
    numberOfViews: 0,
    numberOfLikes: 0,
    numberOfDislikes: 0,
    updatedAt: new Date().toISOString(),
    tags,
    channel,
    duration,
    ...computeOrientationProjectionWidthHeight({
      lora,
      orientation,
      // projection, // <- will be extrapolated from the LoRA for now
    }),
  }

  return {
    videoRequest: newVideoRequest,
    videoInfo: newVideo
  }
}