removed utterance system atm
This commit is contained in:
@@ -11,7 +11,6 @@ interface FilterParams {
|
||||
modelName?: string;
|
||||
dialect?: string;
|
||||
iteration?: number;
|
||||
utteranceId?: string;
|
||||
}
|
||||
|
||||
export async function getDatasetEntries(
|
||||
@@ -40,10 +39,6 @@ export async function getDatasetEntries(
|
||||
conditions.push(eq(dataset_entry.iteration, filters.iteration));
|
||||
}
|
||||
|
||||
if (filters?.utteranceId) {
|
||||
conditions.push(eq(dataset_entry.utteranceId, filters.utteranceId));
|
||||
}
|
||||
|
||||
const whereClause = and(...conditions);
|
||||
|
||||
const entries = await db
|
||||
|
||||
@@ -15,13 +15,11 @@ export async function getFilterOptions(datasetId: number) {
|
||||
const modelNames = [...new Set(entries.map(e => e.modelName))].sort();
|
||||
const dialects = [...new Set(entries.map(e => e.dialect))].sort();
|
||||
const iterations = [...new Set(entries.map(e => e.iteration))].sort((a, b) => a - b);
|
||||
const utteranceIds = [...new Set(entries.map(e => e.utteranceId).filter(Boolean))].sort();
|
||||
|
||||
return {
|
||||
speakerIds,
|
||||
modelNames,
|
||||
dialects,
|
||||
iterations,
|
||||
utteranceIds,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
'use server';
|
||||
|
||||
import db from '@/lib/db';
|
||||
import { dataset_utterance } from '@/lib/model/utterance';
|
||||
import { eq, and } from 'drizzle-orm';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
|
||||
export async function uploadDatasetUtterances(
|
||||
datasetId: number,
|
||||
formData: FormData
|
||||
) {
|
||||
const file = formData.get('file') as File;
|
||||
|
||||
if (!file) {
|
||||
throw new Error('No file provided');
|
||||
}
|
||||
|
||||
if (!file.name.endsWith('.csv')) {
|
||||
throw new Error('File must be a CSV file');
|
||||
}
|
||||
|
||||
try {
|
||||
const csvContent = await file.text();
|
||||
const lines = csvContent.split('\n').filter((line) => line.trim());
|
||||
|
||||
if (lines.length < 2) {
|
||||
throw new Error('CSV is empty or invalid');
|
||||
}
|
||||
|
||||
// Parse CSV header
|
||||
const headers = lines[0].split(',').map((h) => h.trim());
|
||||
|
||||
if (!headers.includes('id') || !headers.includes('text')) {
|
||||
throw new Error('CSV must have "id" and "text" columns');
|
||||
}
|
||||
|
||||
// Get indices of id and text columns
|
||||
const idIndex = headers.indexOf('id');
|
||||
const textIndex = headers.indexOf('text');
|
||||
|
||||
// Parse utterances
|
||||
const utterances: typeof dataset_utterance.$inferInsert[] = [];
|
||||
|
||||
for (let i = 1; i < lines.length; i++) {
|
||||
// Handle CSV parsing with quotes
|
||||
const line = lines[i];
|
||||
const parts: string[] = [];
|
||||
let current = '';
|
||||
let inQuotes = false;
|
||||
|
||||
for (let j = 0; j < line.length; j++) {
|
||||
const char = line[j];
|
||||
const nextChar = line[j + 1];
|
||||
|
||||
if (char === '"') {
|
||||
if (inQuotes && nextChar === '"') {
|
||||
current += '"';
|
||||
j++; // Skip next quote
|
||||
} else {
|
||||
inQuotes = !inQuotes;
|
||||
}
|
||||
} else if (char === ',' && !inQuotes) {
|
||||
parts.push(current.trim());
|
||||
current = '';
|
||||
} else {
|
||||
current += char;
|
||||
}
|
||||
}
|
||||
parts.push(current.trim());
|
||||
|
||||
if (parts.length > Math.max(idIndex, textIndex)) {
|
||||
const id = parts[idIndex]?.trim();
|
||||
const text = parts[textIndex]?.trim();
|
||||
|
||||
if (id && text) {
|
||||
utterances.push({
|
||||
datasetId,
|
||||
id,
|
||||
text,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (utterances.length === 0) {
|
||||
throw new Error('No valid utterances found in CSV');
|
||||
}
|
||||
|
||||
// Check for existing utterances to avoid duplicates
|
||||
const existingUtterances = await db
|
||||
.select({ id: dataset_utterance.id })
|
||||
.from(dataset_utterance)
|
||||
.where(eq(dataset_utterance.datasetId, datasetId));
|
||||
|
||||
const existingIds = new Set(existingUtterances.map((u) => u.id));
|
||||
|
||||
// Filter out duplicates
|
||||
const newUtterances = utterances.filter((u) => !existingIds.has(u.id));
|
||||
|
||||
if (newUtterances.length === 0) {
|
||||
throw new Error('All utterances already exist in the dataset');
|
||||
}
|
||||
|
||||
// Insert new utterances into database
|
||||
await db.insert(dataset_utterance).values(newUtterances);
|
||||
|
||||
revalidatePath(`/admin/datasets/${datasetId}`);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
utterancesCreated: newUtterances.length,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error uploading utterances:', error);
|
||||
throw new Error(
|
||||
error instanceof Error ? error.message : 'Failed to upload utterances'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import db from '@/lib/db';
|
||||
import { dataset_entry } from '@/lib/model/dataset_entry';
|
||||
import { dataset_utterance } from '@/lib/model/utterance';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { writeFile, mkdir, readFile, rm, readdir } from 'fs/promises';
|
||||
@@ -14,7 +13,6 @@ interface DatasetEntryInput {
|
||||
id: string;
|
||||
audio_file: string;
|
||||
duration_ms: string;
|
||||
utt_id: string;
|
||||
speaker: string;
|
||||
model: string;
|
||||
dialect: string;
|
||||
@@ -104,7 +102,6 @@ export async function uploadDatasetEntries(
|
||||
speakerId: row.speaker,
|
||||
modelName: row.model,
|
||||
fileName: relativePath,
|
||||
utteranceId: row.utt_id || undefined,
|
||||
dialect: row.dialect,
|
||||
iteration: parseInt(row.iteration, 10),
|
||||
});
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import Link from 'next/link';
|
||||
import db from '@/lib/db';
|
||||
import { dataset_entry } from '@/lib/model/dataset_entry';
|
||||
import { dataset_utterance } from '@/lib/model/utterance';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import AudioPlayer from '@/components/AudioPlayer';
|
||||
|
||||
@@ -42,17 +41,6 @@ export default async function DatasetEntryPage({ params }: DatasetEntryPageProps
|
||||
|
||||
const entry = entries[0];
|
||||
|
||||
// Fetch utterance if utteranceId is present
|
||||
let utterance = null;
|
||||
if (entry.utteranceId) {
|
||||
const utterances = await db
|
||||
.select()
|
||||
.from(dataset_utterance)
|
||||
.where(eq(dataset_utterance.id, entry.utteranceId));
|
||||
|
||||
utterance = utterances.length > 0 ? utterances[0] : null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-8">
|
||||
@@ -107,13 +95,6 @@ export default async function DatasetEntryPage({ params }: DatasetEntryPageProps
|
||||
<AudioPlayer datasetId={datasetIdNum} fileName={entry.fileName} externalId={entry.externalId} />
|
||||
</div>
|
||||
|
||||
{utterance && (
|
||||
<div className="col-span-2 bg-blue-50 p-4 rounded-lg border border-blue-200">
|
||||
<p className="text-sm font-semibold text-gray-700 mb-2">Utterance {entry.utteranceId}</p>
|
||||
<p className="text-lg text-gray-800 leading-relaxed">{utterance.text}</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="bg-white border border-gray-200 p-4 rounded-lg">
|
||||
<p className="text-sm text-gray-600 mb-1">Created</p>
|
||||
<p className="text-lg font-semibold">
|
||||
|
||||
@@ -5,7 +5,6 @@ import { eq } from 'drizzle-orm';
|
||||
import EditableDatasetHeader from '@/components/EditableDatasetHeader';
|
||||
import DatasetEntriesList from '@/components/DatasetEntriesList';
|
||||
import UploadDatasetEntriesModal from '@/components/UploadDatasetEntriesModal';
|
||||
import UploadUtterancesModal from '@/components/UploadUtterancesModal';
|
||||
import RemoveAllEntriesButton from '@/components/RemoveAllEntriesButton';
|
||||
|
||||
interface DatasetPageProps {
|
||||
@@ -57,7 +56,6 @@ export default async function DatasetPage({ params }: DatasetPageProps) {
|
||||
|
||||
<div className="flex gap-3 mb-6">
|
||||
<UploadDatasetEntriesModal datasetId={datasetId} />
|
||||
<UploadUtterancesModal datasetId={datasetId} />
|
||||
<RemoveAllEntriesButton datasetId={datasetId} />
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user