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),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user