Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 9,098 Bytes
f27679f f70dd7e 80ea539 f27679f a40111f 3a944ef 22d3c77 1f122c3 f27679f df83860 d160b97 4c34e70 80ea539 f70dd7e f27679f 80ea539 f62b8d3 f70dd7e a3f1817 1f122c3 9cea1bb a40111f 80ea539 b161bd3 80ea539 9cea1bb a40111f 80ea539 f70dd7e b161bd3 f70dd7e b161bd3 f70dd7e f27679f 9cea1bb 1f122c3 f27679f 1f122c3 f27679f d160b97 f27679f 22d3c77 d160b97 f27679f 22d3c77 4c34e70 22d3c77 f27679f d160b97 a40111f d160b97 f27679f d160b97 f27679f a40111f f27679f a40111f d160b97 a40111f 80ea539 a40111f d160b97 f27679f a40111f d160b97 a40111f d160b97 a40111f 80ea539 a40111f d160b97 a40111f d160b97 a40111f f27679f a40111f d160b97 3a944ef a40111f 3a944ef a40111f f27679f 3a944ef 22d3c77 3a944ef f27679f a40111f d160b97 a40111f f70dd7e a40111f f70dd7e a40111f f27679f d160b97 f27679f d160b97 f27679f 4c34e70 f27679f 1f122c3 f27679f |
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 |
"use client"
import { useEffect, useState, useTransition } from "react"
import dynamic from "next/dynamic"
import { RiCheckboxCircleFill } from "react-icons/ri"
import { PiShareFatLight } from "react-icons/pi"
import CopyToClipboard from "react-copy-to-clipboard"
import { LuCopyCheck } from "react-icons/lu"
import { LuScrollText } from "react-icons/lu"
import { BiCameraMovie } from "react-icons/bi"
import { useStore } from "@/app/state/useStore"
import { cn } from "@/lib/utils"
import { VideoPlayer } from "@/app/interface/video-player"
import { VideoInfo } from "@/types"
import { ActionButton, actionButtonClassName } from "@/app/interface/action-button"
import { RecommendedVideos } from "@/app/interface/recommended-videos"
import { isCertifiedUser } from "@/app/certification"
import { watchVideo } from "@/app/server/actions/stats"
import { formatTimeAgo } from "@/lib/formatTimeAgo"
const DefaultAvatar = dynamic(() => import("../../interface/default-avatar"), {
loading: () => null,
})
export function PublicVideoView() {
const [_pending, startTransition] = useTransition()
const video = useStore(s => s.publicVideo)
const videoId = `${video?.id || ""}`
const [copied, setCopied] = useState<boolean>(false)
const [channelThumbnail, setChannelThumbnail] = useState(`${video?.channel.thumbnail || ""}`)
const setPublicVideo = useStore(s => s.setPublicVideo)
// we inject the current videoId in the URL, if it's not already present
// this is a hack for Hugging Face iframes
useEffect(() => {
const queryString = new URL(location.href).search
const searchParams = new URLSearchParams(queryString)
if (videoId) {
if (searchParams.get("v") !== videoId) {
console.log(`current videoId "${videoId}" isn't set in the URL query params.. TODO we should set it`)
// searchParams.set("v", videoId)
// location.search = searchParams.toString()
}
} else {
// searchParams.delete("v")
// location.search = searchParams.toString()
}
}, [videoId])
useEffect(() => {
if (copied) {
setTimeout(() => {
setCopied(false)
}, 2000)
}
}, [copied])
const handleBadChannelThumbnail = () => {
try {
if (channelThumbnail) {
setChannelThumbnail("")
}
} catch (err) {
}
}
useEffect(() => {
startTransition(async () => {
if (!video || !video.id) {
return
}
const numberOfViews = await watchVideo(videoId)
setPublicVideo({
...video,
numberOfViews
})
})
}, [video?.id])
if (!video) { return null }
return (
<div className={cn(
`w-full`,
`flex flex-row`
)}>
<div className={cn(
`flex-grow`,
`flex flex-col`,
`transition-all duration-200 ease-in-out`,
`px-2 sm:px-0`
)}>
{/** VIDEO PLAYER - HORIZONTAL */}
<VideoPlayer
video={video}
className="mb-4"
/>
{/** VIDEO TITLE - HORIZONTAL */}
<div className={cn(
`flex flew-row space-x-2`,
`transition-all duration-200 ease-in-out`,
`text-lg lg:text-xl text-zinc-100 font-medium mb-0 line-clamp-2`,
`mb-2`,
)}>
<div className="">{video.label}</div>
{/*
<div className={cn(
`flex flex-row`, // `inline-block`,
`bg-neutral-700 text-neutral-300 rounded-lg`,
// `items-center justify-center`,
`text-center`,
`px-1.5 py-0.5`,
`text-xs`
)}>
AI Video Model: {video.model || "HotshotXL"}
</div>
*/}
</div>
{/** VIDEO TOOLBAR - HORIZONTAL */}
<div className={cn(
`flex flex-col space-y-3 xl:space-y-0 xl:flex-row`,
`transition-all duration-200 ease-in-out`,
`items-start xl:items-center`,
`justify-between`,
`mb-4`,
)}>
{/** LEFT PART OF THE TOOLBAR */}
<div className={cn(
`flex flex-row`,
`items-center`
)}>
{/** CHANNEL LOGO - VERTICAL */}
<a
className={cn(
`flex flex-col`,
`mr-3`,
`cursor-pointer`
)}
href={`https://huggingface.co/datasets/${video.channel.datasetUser}/${video.channel.datasetName}`}
target="_blank">
<div className="flex w-10 rounded-full overflow-hidden">
{
channelThumbnail ? <div className="flex flex-col">
<div className="flex w-9 rounded-full overflow-hidden">
<img
src={channelThumbnail}
onError={handleBadChannelThumbnail}
/>
</div>
</div>
: <DefaultAvatar
username={video.channel.datasetUser}
bgColor="#fde047"
textColor="#1c1917"
width={36}
roundShape
/>}
</div>
</a>
{/** CHANNEL INFO - VERTICAL */}
<a className={cn(
`flex flex-row sm:flex-col`,
`transition-all duration-200 ease-in-out`,
`cursor-pointer`,
)}
href={`https://huggingface.co/datasets/${video.channel.datasetUser}/${video.channel.datasetName}`}
target="_blank">
<div className={cn(
`flex flex-row items-center`,
`transition-all duration-200 ease-in-out`,
`text-zinc-100 text-sm lg:text-base font-medium space-x-1`,
)}>
<div>{video.channel.label}</div>
{isCertifiedUser(video.channel.datasetUser) ? <div className="text-sm text-neutral-400"><RiCheckboxCircleFill className="" /></div> : null}
</div>
<div className={cn(
`flex flex-row items-center`,
`text-neutral-400 text-xs font-normal space-x-1`,
)}>
<div>0 followers</div>
<div></div>
</div>
</a>
</div>
{/** RIGHT PART OF THE TOOLBAR */}
<div className={cn(
`flex flex-row`,
`items-center`,
`space-x-2`
)}>
{/* SHARE */}
<div className={cn(
`flex flex-row`,
`items-center`
)}>
<CopyToClipboard
text={`https://huggingface.co/spaces/jbilcke-hf/ai-tube?v=${video.id}`}
onCopy={() => setCopied(true)}>
<div className={actionButtonClassName}>
<div className="flex items-center justify-center">
{
copied ? <LuCopyCheck className="w-4 h-4" />
: <PiShareFatLight className="w-5 h-5" />
}
</div>
<div>
{
copied ? "Link copied!" : "Share video"
}</div>
</div>
</CopyToClipboard>
</div>
<ActionButton
href={
video.model === "LaVie"
? "https://huggingface.co/vdo/LaVie"
: video.model === "SVD"
? "https://huggingface.co/stabilityai/stable-video-diffusion-img2vid"
: "https://huggingface.co/hotshotco/Hotshot-XL"
}
>
<BiCameraMovie />
<span>Made with {video.model}</span>
</ActionButton>
<ActionButton
href={
`https://huggingface.co/datasets/${
video.channel.datasetUser
}/${
video.channel.datasetName
}/raw/main/prompt_${
video.id
}.md`
}
>
<LuScrollText />
<span>See prompt</span>
</ActionButton>
</div>
</div>
{/** VIDEO DESCRIPTION - VERTICAL */}
<div className={cn(
`flex flex-col p-3`,
`transition-all duration-200 ease-in-out`,
`rounded-xl`,
`bg-neutral-700/50`,
`text-sm text-zinc-100`,
)}>
<div className="flex flex-row space-x-2 font-medium mb-1">
<div>{video.numberOfViews} views</div>
<div>{formatTimeAgo(video.updatedAt).replace("about ", "")}</div>
</div>
<p>{video.description}</p>
</div>
</div>
<div className={cn(
`w-40 sm:w-56 md:w-64 lg:w-72 xl:w-[450px]`,
`transition-all duration-200 ease-in-out`,
`hidden sm:flex flex-col`,
`pl-5 pr-1 sm:pr-2 md:pr-3 lg:pr-4 xl:pr-6 2xl:pr-8`,
)}>
<RecommendedVideos video={video} />
</div>
</div>
)
}
|