Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 2,369 Bytes
f62b8d3 4c34e70 f27679f f62b8d3 f27679f f62b8d3 4c34e70 f62b8d3 4c34e70 f62b8d3 f27679f f62b8d3 4c34e70 f62b8d3 4c34e70 f62b8d3 4c34e70 f62b8d3 f27679f f62b8d3 f27679f f62b8d3 4c34e70 93f8352 f62b8d3 f27679f f62b8d3 f27679f f62b8d3 851546d f62b8d3 4c34e70 93f8352 f62b8d3 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 |
"use server"
import { Blob } from "buffer"
import { Credentials, uploadFile, whoAmI } from "@/huggingface/hub/src"
import { ChannelInfo, VideoGenerationModel, VideoInfo, VideoRequest } from "@/types"
import { formatPromptFileName } from "../utils/formatPromptFileName"
/**
* 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,
}: {
channel: ChannelInfo
apiKey: string
title: string
description: string
prompt: string
model: VideoGenerationModel
lora: string
style: string
voice: string
music: string
tags: string[]
}): 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}
# 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,
updatedAt: new Date().toISOString(),
tags,
channel,
}
const newVideo: VideoInfo = {
id,
status: "submitted",
label: title,
description,
prompt,
model,
style,
lora,
voice,
music,
thumbnailUrl: channel.thumbnail, // will be generated in async
assetUrl: "", // will be generated in async
numberOfViews: 0,
numberOfLikes: 0,
updatedAt: new Date().toISOString(),
tags,
channel,
}
return {
videoRequest: newVideoRequest,
videoInfo: newVideo
}
}
|