Download apps/web/src/components/CatalogBrowserView.tsx from phucsd/olokaflow: direct link, hf CLI and curl.
- Browser
- Download file 22.1 kB
-
https://huggingface.co/spaces/phucsd/olokaflow/resolve/main/apps/web/src/components/CatalogBrowserView.tsx
- Command line
-
hf download hf://spaces/phucsd/olokaflow/apps/web/src/components/CatalogBrowserView.tsx
-
curl -L -o CatalogBrowserView.tsx https://huggingface.co/spaces/phucsd/olokaflow/resolve/main/apps/web/src/components/CatalogBrowserView.tsx
22.1 kB
| import React, { useState, useRef } from 'react'; | |
| import { | |
| Mic, | |
| Palette, | |
| LayoutTemplate, | |
| Zap, | |
| Box, | |
| Volume2, | |
| Square, | |
| Star, | |
| Sparkles, | |
| Search, | |
| Upload, | |
| Plus, | |
| Trash2, | |
| X, | |
| } from 'lucide-react'; | |
| import { api } from '../api'; | |
| import { Button, Badge } from './ui/primitives'; | |
| interface Props { | |
| catalog: any; | |
| initialSubTab?: 'voices' | 'presets' | 'blueprints' | 'motion' | 'registry'; | |
| onRefreshCatalog?: () => void; | |
| } | |
| export const CatalogBrowserView: React.FC<Props> = ({ | |
| catalog, | |
| initialSubTab = 'voices', | |
| onRefreshCatalog, | |
| }) => { | |
| const [subTab, setSubTab] = useState< | |
| 'voices' | 'presets' | 'blueprints' | 'motion' | 'registry' | |
| >(initialSubTab); | |
| const [search, setSearch] = useState(''); | |
| const audioRef = useRef<HTMLAudioElement | null>(null); | |
| const [playingVoiceUrl, setPlayingVoiceUrl] = useState(''); | |
| // Zero-Shot Voice Cloning Drawer State | |
| const [showCloneDrawer, setShowCloneDrawer] = useState(false); | |
| const [cloneName, setCloneName] = useState(''); | |
| const [cloneGender, setCloneGender] = useState('Nam'); | |
| const [cloneRegion, setCloneRegion] = useState('Nam'); | |
| const [cloneDescription, setCloneDescription] = useState(''); | |
| const [cloneRefText, setCloneRefText] = useState(''); | |
| const [cloneFallbackVoiceId, setCloneFallbackVoiceId] = useState('Hải Đăng'); | |
| const [cloneFile, setCloneFile] = useState<File | null>(null); | |
| const [cloningBusy, setCloningBusy] = useState(false); | |
| React.useEffect(() => { | |
| setSubTab(initialSubTab); | |
| }, [initialSubTab]); | |
| function togglePlaySample(url?: string) { | |
| if (!url || !audioRef.current) return; | |
| if (playingVoiceUrl === url) { | |
| audioRef.current.pause(); | |
| setPlayingVoiceUrl(''); | |
| return; | |
| } | |
| audioRef.current.src = url; | |
| audioRef.current.play().catch(() => {}); | |
| setPlayingVoiceUrl(url); | |
| } | |
| async function handleCloneVoiceSubmit(e: React.FormEvent) { | |
| e.preventDefault(); | |
| if (!cloneFile || !cloneName.trim()) return; | |
| setCloningBusy(true); | |
| try { | |
| await api.cloneCustomVoice({ | |
| file: cloneFile, | |
| name: cloneName.trim(), | |
| gender: cloneGender, | |
| region: cloneRegion, | |
| description: cloneDescription.trim() || undefined, | |
| refText: cloneRefText.trim() || undefined, | |
| fallbackVoiceId: cloneFallbackVoiceId, | |
| }); | |
| setCloneName(''); | |
| setCloneDescription(''); | |
| setCloneRefText(''); | |
| setCloneFile(null); | |
| setShowCloneDrawer(false); | |
| onRefreshCatalog?.(); | |
| } catch (err: any) { | |
| alert(`Lỗi Clone giọng đọc: ${err.message}`); | |
| } finally { | |
| setCloningBusy(false); | |
| } | |
| } | |
| const voices = catalog?.voices || []; | |
| const presets = catalog?.framePresets || []; | |
| const blueprints = catalog?.sceneBlueprints || []; | |
| const motionRules = catalog?.motionRules || []; | |
| const registryItems = catalog?.registryItems || []; | |
| return ( | |
| <div className="space-y-5"> | |
| <audio | |
| ref={audioRef} | |
| onEnded={() => setPlayingVoiceUrl('')} | |
| className="hidden" | |
| /> | |
| {/* Header */} | |
| <div className="fliki-card p-6 bg-white flex flex-wrap items-center justify-between gap-4"> | |
| <div> | |
| <Badge variant="crimson" className="mb-1.5"> | |
| <Sparkles className="w-3 h-3" /> | |
| Kho Giọng Đọc OlokaTTS, Voice Cloning & HyperFrames 4-Tier Catalog | |
| </Badge> | |
| <h2 className="text-xl font-bold tracking-tight text-zinc-900"> | |
| Thư Viện 25 Giọng Đọc AI Tiếng Việt, Clone Giọng Cá Nhân & Kho Hiệu Ứng | |
| </h2> | |
| <p className="text-xs text-zinc-500 mt-0.5"> | |
| Nghe thử trực tiếp 25 giọng đọc tiếng Việt tự nhiên từ https://tts.oloka.net, tải lên file âm thanh mẫu (.wav/.mp3) để Clone giọng riêng và khám phá kho chuyển động HyperFrames. | |
| </p> | |
| </div> | |
| <div className="flex items-center gap-2.5 flex-wrap"> | |
| <div className="relative w-64"> | |
| <Search className="w-3.5 h-3.5 text-zinc-400 absolute left-3.5 top-1/2 -translate-y-1/2" /> | |
| <input | |
| type="text" | |
| value={search} | |
| onChange={(e) => setSearch(e.target.value)} | |
| placeholder="Tìm giọng đọc, Blueprint, hiệu ứng..." | |
| className="w-full bg-zinc-50 border border-zinc-200 rounded-xl pl-9 pr-3.5 py-2 text-xs text-zinc-900 focus:outline-none focus:border-[#E11D48]" | |
| /> | |
| </div> | |
| <Button | |
| type="button" | |
| variant="primary" | |
| onClick={() => { | |
| setSubTab('voices'); | |
| setShowCloneDrawer(!showCloneDrawer); | |
| }} | |
| > | |
| <Plus className="w-3.5 h-3.5" /> | |
| <span> | |
| {showCloneDrawer | |
| ? 'Đóng Khung Clone Giọng' | |
| : 'Clone Giọng Mới (.WAV/.MP3)'} | |
| </span> | |
| </Button> | |
| </div> | |
| </div> | |
| {/* ZERO-SHOT VOICE CLONING STUDIO DRAWER */} | |
| {showCloneDrawer && ( | |
| <form | |
| onSubmit={handleCloneVoiceSubmit} | |
| className="fliki-card p-6 bg-white border-rose-200 space-y-4" | |
| > | |
| <div className="flex items-center justify-between border-b border-zinc-100 pb-3"> | |
| <div> | |
| <h3 className="text-base font-bold text-zinc-900 flex items-center gap-2"> | |
| <Mic className="w-4 h-4 text-[#E11D48]" /> | |
| <span>Zero-Shot Voice Cloning Studio (Tạo Giọng Đọc Cá Nhân Hóa)</span> | |
| </h3> | |
| <p className="text-xs text-zinc-500 mt-0.5"> | |
| Tải lên đoạn thu âm mẫu (5–30 giây, rõ chữ, không tạp âm). Giọng Clone sẽ xuất hiện ngay trong danh sách chọn giọng của Fliki Video Studio & Batch Video Factory. | |
| </p> | |
| </div> | |
| <Button | |
| type="button" | |
| variant="ghost" | |
| size="sm" | |
| onClick={() => setShowCloneDrawer(false)} | |
| > | |
| <X className="w-3.5 h-3.5" /> | |
| <span>Đóng</span> | |
| </Button> | |
| </div> | |
| <div className="grid grid-cols-1 md:grid-cols-12 gap-4"> | |
| <div className="md:col-span-4 space-y-3"> | |
| <div> | |
| <label className="block text-xs font-semibold text-zinc-700 mb-1"> | |
| Tên giọng đọc Clone * | |
| </label> | |
| <input | |
| type="text" | |
| value={cloneName} | |
| onChange={(e) => setCloneName(e.target.value)} | |
| placeholder="VD: Giọng CEO Phúc (Miền Nam)..." | |
| className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2 text-xs text-zinc-900 focus:outline-none focus:border-[#E11D48]" | |
| required | |
| /> | |
| </div> | |
| <div className="grid grid-cols-2 gap-2"> | |
| <div> | |
| <label className="block text-xs font-semibold text-zinc-700 mb-1"> | |
| Giới tính | |
| </label> | |
| <select | |
| value={cloneGender} | |
| onChange={(e) => setCloneGender(e.target.value)} | |
| className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3 py-2 text-xs font-semibold text-zinc-800" | |
| > | |
| <option value="Nam">Nam</option> | |
| <option value="Nữ">Nữ</option> | |
| </select> | |
| </div> | |
| <div> | |
| <label className="block text-xs font-semibold text-zinc-700 mb-1"> | |
| Vùng miền | |
| </label> | |
| <select | |
| value={cloneRegion} | |
| onChange={(e) => setCloneRegion(e.target.value)} | |
| className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3 py-2 text-xs font-semibold text-zinc-800" | |
| > | |
| <option value="Nam">Miền Nam</option> | |
| <option value="Bắc">Miền Bắc</option> | |
| <option value="Trung">Miền Trung</option> | |
| </select> | |
| </div> | |
| </div> | |
| <div> | |
| <label className="block text-xs font-semibold text-zinc-700 mb-1"> | |
| Giọng OlokaTTS đồng điệu dự phòng | |
| </label> | |
| <select | |
| value={cloneFallbackVoiceId} | |
| onChange={(e) => setCloneFallbackVoiceId(e.target.value)} | |
| className="w-full bg-zinc-50 border border-zinc-200 rounded-xl px-3 py-2 text-xs font-semibold text-zinc-800" | |
| > | |
| {voices | |
| .filter((v: any) => v.provider === 'olokatts') | |
| .map((v: any) => ( | |
| <option key={v.id} value={v.voiceId}> | |
| {v.name} | |
| </option> | |
| ))} | |
| </select> | |
| </div> | |
| </div> | |
| <div className="md:col-span-8 space-y-3 flex flex-col justify-between"> | |
| <div className="grid grid-cols-1 sm:grid-cols-2 gap-3"> | |
| <div> | |
| <label className="block text-xs font-semibold text-zinc-700 mb-1"> | |
| Tệp âm thanh mẫu (.WAV, .MP3, .M4A) * | |
| </label> | |
| <label className="flex items-center justify-center gap-2 w-full h-24 rounded-xl border-2 border-dashed border-zinc-300 hover:border-[#E11D48] bg-zinc-50 px-3 text-xs text-zinc-600 cursor-pointer transition-colors"> | |
| <Upload className="w-4 h-4 text-[#E11D48]" /> | |
| <span className="truncate font-semibold"> | |
| {cloneFile | |
| ? `${cloneFile.name} (${(cloneFile.size / 1024).toFixed(0)} KB)` | |
| : 'Bấm để chọn file giọng mẫu (.wav / .mp3)'} | |
| </span> | |
| <input | |
| type="file" | |
| accept="audio/*,.wav,.mp3,.m4a" | |
| onChange={(e) => setCloneFile(e.target.files?.[0] || null)} | |
| className="hidden" | |
| required | |
| /> | |
| </label> | |
| </div> | |
| <div> | |
| <label className="block text-xs font-semibold text-zinc-700 mb-1"> | |
| Nội dung văn bản của file mẫu (Reference Transcript) | |
| </label> | |
| <textarea | |
| rows={3} | |
| value={cloneRefText} | |
| onChange={(e) => setCloneRefText(e.target.value)} | |
| placeholder="Nhập chính xác câu nói trong đoạn ghi âm mẫu để tăng độ chuẩn xác khi Zero-Shot Clone..." | |
| className="w-full bg-zinc-50 border border-zinc-200 rounded-xl p-2.5 text-xs text-zinc-900 focus:outline-none focus:border-[#E11D48]" | |
| /> | |
| </div> | |
| </div> | |
| <div className="flex items-center justify-between gap-3 pt-2"> | |
| <input | |
| type="text" | |
| value={cloneDescription} | |
| onChange={(e) => setCloneDescription(e.target.value)} | |
| placeholder="Mô tả phong cách giọng (VD: Trầm ấm, thuyết trình công nghệ, tốc độ vừa phải)..." | |
| className="flex-1 bg-zinc-50 border border-zinc-200 rounded-xl px-3.5 py-2 text-xs text-zinc-900" | |
| /> | |
| <Button type="submit" variant="primary" disabled={cloningBusy || !cloneFile}> | |
| <Mic className="w-3.5 h-3.5" /> | |
| <span> | |
| {cloningBusy ? 'Đang lưu giọng Clone...' : 'Lưu Giọng Clone Vào Hệ Thống'} | |
| </span> | |
| </Button> | |
| </div> | |
| </div> | |
| </div> | |
| </form> | |
| )} | |
| {/* Sub-navigation Tabs */} | |
| <div className="flex flex-wrap gap-2"> | |
| {[ | |
| { id: 'voices', label: `Kho Giọng Đọc AI (${voices.length})`, Icon: Mic }, | |
| { id: 'presets', label: `Frame Presets (${presets.length})`, Icon: Palette }, | |
| { | |
| id: 'blueprints', | |
| label: `Scene Blueprints (${blueprints.length})`, | |
| Icon: LayoutTemplate, | |
| }, | |
| { | |
| id: 'motion', | |
| label: `Atomic Motion Rules (${motionRules.length})`, | |
| Icon: Zap, | |
| }, | |
| { | |
| id: 'registry', | |
| label: `Registry Blocks (${registryItems.length})`, | |
| Icon: Box, | |
| }, | |
| ].map((t) => { | |
| const Icon = t.Icon; | |
| return ( | |
| <button | |
| key={t.id} | |
| onClick={() => setSubTab(t.id as any)} | |
| className={`px-4 py-2 rounded-xl text-xs font-semibold border transition-all cursor-pointer flex items-center gap-1.5 ${ | |
| subTab === t.id | |
| ? 'bg-[#E11D48] text-white border-[#E11D48] shadow-2xs' | |
| : 'bg-white text-zinc-700 border-zinc-200 hover:border-zinc-300' | |
| }`} | |
| > | |
| <Icon className="w-3.5 h-3.5" /> | |
| <span>{t.label}</span> | |
| </button> | |
| ); | |
| })} | |
| </div> | |
| {/* TAB 1: CUSTOM CLONED VOICES + 25 LIVE OLOKATTS VIETNAMESE VOICES + OPENAI VOICES */} | |
| {subTab === 'voices' && ( | |
| <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> | |
| {voices | |
| .filter((v: any) => | |
| !search | |
| ? true | |
| : `${v.name} ${v.description} ${v.region}` | |
| .toLowerCase() | |
| .includes(search.toLowerCase()) | |
| ) | |
| .map((v: any) => { | |
| const isPlaying = playingVoiceUrl && playingVoiceUrl === v.previewUrl; | |
| const isCloned = v.provider === 'cloned'; | |
| return ( | |
| <div | |
| key={v.id} | |
| className="fliki-card p-4 bg-white flex flex-col justify-between gap-3" | |
| > | |
| <div> | |
| <div className="flex items-start justify-between gap-2"> | |
| <div> | |
| <span className="text-sm font-bold text-zinc-900 flex items-center gap-1.5"> | |
| <Mic className="w-3.5 h-3.5 text-[#E11D48]" /> | |
| {v.name} | |
| </span> | |
| <div className="flex items-center gap-1.5 mt-1.5 flex-wrap"> | |
| <Badge variant={isCloned ? 'emerald' : 'crimson'}> | |
| {isCloned | |
| ? 'Zero-Shot Cloned' | |
| : v.provider === 'olokatts' | |
| ? 'OlokaTTS v3' | |
| : 'OpenAI TTS'} | |
| </Badge> | |
| <Badge variant="default"> | |
| {v.gender} • {v.region} | |
| </Badge> | |
| {v.isEditorsPick && ( | |
| <Badge variant="amber"> | |
| <Star className="w-2.5 h-2.5 fill-current" /> | |
| Đề xuất | |
| </Badge> | |
| )} | |
| </div> | |
| </div> | |
| {isCloned && ( | |
| <button | |
| type="button" | |
| onClick={async () => { | |
| await api.deleteCustomVoice(v.id); | |
| onRefreshCatalog?.(); | |
| }} | |
| className="p-1.5 rounded-lg hover:bg-rose-50 text-zinc-400 hover:text-[#E11D48] cursor-pointer" | |
| title="Xóa giọng Clone này" | |
| > | |
| <Trash2 className="w-3.5 h-3.5" /> | |
| </button> | |
| )} | |
| </div> | |
| <p className="text-xs text-zinc-600 mt-2">{v.description}</p> | |
| </div> | |
| <div className="pt-2 border-t border-zinc-100 flex items-center justify-between"> | |
| <span className="text-[11px] font-mono text-zinc-400"> | |
| ID: {v.voiceId || v.id} | |
| </span> | |
| {v.previewUrl ? ( | |
| <Button | |
| type="button" | |
| variant={isPlaying ? 'primary' : 'outlineCrimson'} | |
| size="sm" | |
| onClick={() => togglePlaySample(v.previewUrl)} | |
| > | |
| {isPlaying ? ( | |
| <> | |
| <Square className="w-3 h-3 fill-current" /> | |
| <span>Đang phát mẫu...</span> | |
| </> | |
| ) : ( | |
| <> | |
| <Volume2 className="w-3.5 h-3.5" /> | |
| <span>Nghe thử giọng</span> | |
| </> | |
| )} | |
| </Button> | |
| ) : ( | |
| <span className="text-[11px] font-mono text-zinc-400"> | |
| Chuẩn OpenAI | |
| </span> | |
| )} | |
| </div> | |
| </div> | |
| ); | |
| })} | |
| </div> | |
| )} | |
| {/* TAB 2: 13 FRAME PRESETS */} | |
| {subTab === 'presets' && ( | |
| <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> | |
| {presets.map((fp: any) => ( | |
| <div key={fp.id} className="fliki-card p-5 bg-white space-y-3"> | |
| <div className="flex items-center justify-between"> | |
| <span className="text-sm font-bold text-zinc-900"> | |
| {fp.name} | |
| </span> | |
| <Badge variant="default">{fp.category}</Badge> | |
| </div> | |
| <p className="text-xs text-zinc-600">{fp.description}</p> | |
| <div className="flex items-center gap-2 pt-2 flex-wrap"> | |
| {Object.entries(fp.colors || {}).map(([k, hex]: [string, any]) => ( | |
| <div key={k} className="flex items-center gap-1 text-[10px] font-mono"> | |
| <span | |
| className="w-5 h-5 rounded-full border border-zinc-300" | |
| style={{ backgroundColor: hex }} | |
| /> | |
| <span className="text-zinc-500">{hex}</span> | |
| </div> | |
| ))} | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| )} | |
| {/* TAB 3: 22 SCENE BLUEPRINTS */} | |
| {subTab === 'blueprints' && ( | |
| <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> | |
| {blueprints.map((bp: any) => ( | |
| <div key={bp.id} className="fliki-card p-5 bg-white space-y-2.5"> | |
| <div className="flex items-center justify-between"> | |
| <span className="text-sm font-bold text-zinc-900 flex items-center gap-1.5"> | |
| <LayoutTemplate className="w-3.5 h-3.5 text-[#E11D48]" /> | |
| {bp.name} | |
| </span> | |
| <span className="font-mono text-[11px] text-[#E11D48] font-bold"> | |
| {bp.id} | |
| </span> | |
| </div> | |
| <p className="text-xs text-zinc-600">{bp.description}</p> | |
| <div className="text-[11px] text-zinc-600 bg-zinc-50 p-2.5 rounded-xl border border-zinc-200 font-mono"> | |
| {bp.layoutPattern} | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| )} | |
| {/* TAB 4: 45+ ATOMIC MOTION RULES */} | |
| {subTab === 'motion' && ( | |
| <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> | |
| {motionRules.map((mr: any) => ( | |
| <div key={mr.id} className="fliki-card p-4 bg-white space-y-2"> | |
| <div className="flex items-center justify-between"> | |
| <span className="text-xs font-bold text-zinc-900 flex items-center gap-1.5"> | |
| <Zap className="w-3.5 h-3.5 text-[#E11D48]" /> | |
| {mr.name} | |
| </span> | |
| <Badge variant="default" mono> | |
| {mr.id} | |
| </Badge> | |
| </div> | |
| <p className="text-xs text-zinc-600">{mr.description}</p> | |
| <pre className="p-2 rounded-xl bg-zinc-950 text-emerald-300 text-[10px] font-mono overflow-x-auto"> | |
| {mr.gsapPattern} | |
| </pre> | |
| </div> | |
| ))} | |
| </div> | |
| )} | |
| {/* TAB 5: REGISTRY BLOCKS */} | |
| {subTab === 'registry' && ( | |
| <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> | |
| {registryItems.map((item: any) => ( | |
| <div key={item.name} className="fliki-card p-4 bg-white space-y-2"> | |
| <div className="flex items-center justify-between"> | |
| <span className="text-xs font-bold text-zinc-900 flex items-center gap-1.5"> | |
| <Box className="w-3.5 h-3.5 text-[#E11D48]" /> | |
| {item.title || item.name} | |
| </span> | |
| <Badge variant="crimson">{item.type}</Badge> | |
| </div> | |
| <p className="text-xs text-zinc-600">{item.description}</p> | |
| <div className="flex flex-wrap gap-1"> | |
| {(item.tags || []).map((tg: string) => ( | |
| <span | |
| key={tg} | |
| className="px-2 py-0.5 rounded-md bg-zinc-100 text-zinc-600 text-[10px] font-mono" | |
| > | |
| #{tg} | |
| </span> | |
| ))} | |
| </div> | |
| </div> | |
| ))} | |
| </div> | |
| )} | |
| </div> | |
| ); | |
| }; | |