Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tmoroney committed Dec 26, 2024
1 parent 685cc56 commit 62ce4de
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 52 deletions.
6 changes: 3 additions & 3 deletions AutoSubs-App/src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"path": "$APPCACHE/transcripts/**"
},
{
"path": "$CACHE/transcripts/**"
"path": "$CACHE/AutoSubs-Cache/Cache/transcripts/**"
}
]
},
Expand All @@ -44,7 +44,7 @@
"path": "$APPCACHE/transcripts/**"
},
{
"path": "$CACHE/transcripts/**"
"path": "$CACHE/AutoSubs-Cache/Cache/transcripts/**"
}
]
},
Expand All @@ -55,7 +55,7 @@
"path": "$APPCACHE/transcripts/**"
},
{
"path": "$CACHE/transcripts/**"
"path": "$CACHE/AutoSubs-Cache/Cache/transcripts/**"
}
]
},
Expand Down
41 changes: 21 additions & 20 deletions AutoSubs-App/src/GlobalContext.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, createContext, useState, useContext, useRef } from 'react';
import { fetch } from '@tauri-apps/plugin-http';
import { BaseDirectory, readTextFile, exists, writeTextFile } from '@tauri-apps/plugin-fs';
import { readTextFile, exists, writeTextFile } from '@tauri-apps/plugin-fs';
import { join, downloadDir, appCacheDir, cacheDir } from '@tauri-apps/api/path';
import { open, save } from '@tauri-apps/plugin-dialog';
import { Subtitle, Speaker, TopSpeaker, EnabeledSteps, ErrorMsg, TimelineInfo } from "@/types/interfaces";
Expand All @@ -11,10 +11,12 @@ import { exit } from '@tauri-apps/plugin-process';
import { platform } from '@tauri-apps/plugin-os';

const DEFAULT_SETTINGS = {
inputTrack: "0",
outputTrack: "0",
model: "small",
language: "auto",
translate: false,
maxWords: 6,
maxWords: 5,
maxChars: 25,
textFormat: "normal",
removePunctuation: false,
Expand Down Expand Up @@ -87,7 +89,6 @@ interface GlobalContextProps {
populateSubtitles: (timelineId: string) => Promise<void>;
addSubtitles: (filePath?: string) => Promise<void>;
exportSubtitles: () => Promise<void>;
initialize: () => void;
jumpToTime: (start: number) => Promise<void>;
}

Expand Down Expand Up @@ -154,8 +155,8 @@ export function GlobalProvider({ children }: React.PropsWithChildren<{}>) {
setModel(DEFAULT_SETTINGS.model);
setLanguage(DEFAULT_SETTINGS.language);
setTemplate("");
setOutputTrack("");
setInputTrack("");
setInputTrack(DEFAULT_SETTINGS.inputTrack);
setOutputTrack(DEFAULT_SETTINGS.outputTrack);
setTranslate(DEFAULT_SETTINGS.translate);
setMaxWords(DEFAULT_SETTINGS.maxWords);
setMaxChars(DEFAULT_SETTINGS.maxChars);
Expand All @@ -177,8 +178,8 @@ export function GlobalProvider({ children }: React.PropsWithChildren<{}>) {
setModel(await store.get<string>('model') || DEFAULT_SETTINGS.model);
setLanguage(await store.get<string>('currentLanguage') || DEFAULT_SETTINGS.language);
setTemplate(await store.get<string>('currentTemplate') || "");
setInputTrack(await store.get<string>('inputTrack') || "all");
setOutputTrack(await store.get<string>('currentTrack') || "");
setInputTrack(await store.get<string>('inputTrack') || DEFAULT_SETTINGS.inputTrack);
setOutputTrack(await store.get<string>('outputTrack') || DEFAULT_SETTINGS.outputTrack);
setTranslate(await store.get<boolean>('translate') || DEFAULT_SETTINGS.translate);
setMaxWords(await store.get<number>('maxWords') || DEFAULT_SETTINGS.maxWords);
setMaxChars(await store.get<number>('maxChars') || DEFAULT_SETTINGS.maxChars);
Expand Down Expand Up @@ -395,7 +396,7 @@ export function GlobalProvider({ children }: React.PropsWithChildren<{}>) {
}

setProgress(90);
setCurrentStep(5);
setCurrentStep(6);

// If the response is successful, parse the JSON data
const data = await response.json();
Expand Down Expand Up @@ -560,7 +561,7 @@ export function GlobalProvider({ children }: React.PropsWithChildren<{}>) {

try {
// Check if the file exists
const fileExists = await exists(filePath, { baseDir: BaseDirectory.Document });
const fileExists = await exists(filePath);

if (!fileExists) {
console.log("Transcript file does not exist for this timeline.");
Expand All @@ -569,19 +570,20 @@ export function GlobalProvider({ children }: React.PropsWithChildren<{}>) {

// Read JSON file
console.log("Reading json file...");
const contents = await readTextFile(filePath, { baseDir: BaseDirectory.Document });
const contents = await readTextFile(filePath);
let transcript = JSON.parse(contents);
return transcript;
} catch (error) {
setError({
title: "Error reading transcript",
desc: "Failed to read the transcript file. Please try again."
desc: "Failed to read the transcript file:" + error
})
}
}

async function populateSubtitles(timeLineId: string) {
let transcript = await readTranscript(timeLineId);
async function populateSubtitles(timelineId: string) {
console.log("Populating subtitles...", timelineId);
let transcript = await readTranscript(timelineId);
if (transcript) {
setMarkIn(transcript.mark_in)
setSubtitles(transcript.segments);
Expand Down Expand Up @@ -739,11 +741,11 @@ export function GlobalProvider({ children }: React.PropsWithChildren<{}>) {
await updateTranscript(newSpeakers, newTopSpeaker); // Use updated newTopSpeaker
}


async function initialize() {
let timelineId = await getTimelineInfo()
await populateSubtitles(timelineId);
}
useEffect(() => {
if (timelineInfo.timelineId !== "" && timelineInfo.timelineId !== undefined) {
populateSubtitles(timelineInfo.timelineId);
}
}, [timelineInfo]);

const hasInitialized = useRef(false);

Expand All @@ -758,7 +760,7 @@ export function GlobalProvider({ children }: React.PropsWithChildren<{}>) {

initializeStore();

initialize();
getTimelineInfo();

getCurrentWindow().once("tauri://close-requested", async () => {
try {
Expand Down Expand Up @@ -829,7 +831,6 @@ export function GlobalProvider({ children }: React.PropsWithChildren<{}>) {
setLanguage,
setInputTrack,
setOutputTrack,
initialize,
fetchTranscription,
setSpeakers,
updateSpeaker,
Expand Down
41 changes: 18 additions & 23 deletions AutoSubs-App/src/pages/diarize-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export function DiarizePage() {
type="button"
size="sm"
className="gap-1.5 text-sm"
onClick={async() => await updateSpeaker(index, currentLabel, currentColor, currentStyle)}
onClick={async () => await updateSpeaker(index, currentLabel, currentColor, currentStyle)}
>
Save Changes
</Button>
Expand All @@ -223,7 +223,20 @@ export function DiarizePage() {
</div>
))}
</CardContent>
<CardFooter>
<Button
type="button"
variant={"secondary"}
size="sm"
className="gap-1.5 text-sm w-full"
onClick={async () => { addSubtitles() }}
>
<RefreshCw className="size-4" />
Update Speakers
</Button>
</CardFooter>
</Card>

<Card>
<CardHeader className="pb-4">
<CardTitle>Update Subtitles</CardTitle>
Expand Down Expand Up @@ -334,21 +347,21 @@ export function DiarizePage() {
>
<ToggleGroupItem
value="normal"
className="h-full flex flex-col items-center justify-center border-2 bg-transparent hover:text-accent-foreground"
className={`h-full flex flex-col items-center justify-center border-2 bg-transparent hover:text-accent-foreground data-[state=on]:border-primary data-[state=on]:bg-card`}
>
<PencilOff />
<span className="text-xs">None</span>
</ToggleGroupItem>
<ToggleGroupItem
value="lowercase"
className="h-full flex flex-col items-center justify-center border-2 bg-transparent hover:text-accent-foreground"
className={`h-full flex flex-col items-center justify-center border-2 bg-transparent hover:text-accent-foreground data-[state=on]:border-primary data-[state=on]:bg-card`}
>
<CaseLower />
<span className="text-xs">Lower</span>
</ToggleGroupItem>
<ToggleGroupItem
value="uppercase"
className="h-full flex flex-col items-center justify-center border-2 bg-transparent hover:text-accent-foreground"
className={`h-full flex flex-col items-center justify-center border-2 bg-transparent hover:text-accent-foreground data-[state=on]:border-primary data-[state=on]:bg-card`}
>
<CaseUpper />
<span className="text-xs">Upper</span>
Expand All @@ -364,24 +377,6 @@ export function DiarizePage() {
</div>
<Switch checked={removePunctuation} onCheckedChange={(checked) => setRemovePunctuation(checked)} />
</div>
{/* <div className="grid gap-3">
<Label htmlFor="sensitiveWords">Sensored Words</Label>
<Input value={sensitiveWords} id="sensitiveWords" type="string" placeholder="bomb, gun, kill" onChange={(e) => setSensitiveWords(e.target.value)} />
</div> */}

{/* <div className="grid gap-3">
<div className="grid grid-cols-2 gap-4">
<div className="grid gap-3">
<Label htmlFor="top-p">Min speakers</Label>
<Input id="top-p" type="number" placeholder="1" />
</div>
<div className="grid gap-3">
<Label htmlFor="top-k">Max speakers</Label>
<Input id="top-k" type="number" placeholder="3" />
</div>
</div>
</div> */}
</CardContent>
<CardFooter>
<Button
Expand All @@ -394,7 +389,7 @@ export function DiarizePage() {
Update Subtitles
</Button>
</CardFooter>
</Card>
</Card>

</div>
</div>
Expand Down
12 changes: 6 additions & 6 deletions AutoSubs-App/src/pages/home-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -867,21 +867,21 @@ export function HomePage() {
</div>

<div className="grid gap-2.5">
<Label htmlFor="numSpeakers">Find Speakers</Label>
<Label htmlFor="numSpeakers">Speaker Detection Mode</Label>
<Select value={diarizeMode} onValueChange={(value) => setDiarizeMode(value)}>
<SelectTrigger className="w-full">
<SelectValue placeholder="Select an option" />
<SelectValue placeholder="Choose detection mode" />
</SelectTrigger>
<SelectContent>
<SelectItem value="auto">Auto-detect number of speakers</SelectItem>
<SelectItem value="specific">Specify exact number of speakers</SelectItem>
<SelectItem value="auto">Auto detect speakers</SelectItem>
<SelectItem value="specific">Specify number of speakers</SelectItem>
</SelectContent>
</Select>
</div>
{diarizeMode !== "auto" && (
<div className="grid gap-3">
<Label htmlFor="speakerCount">Specify speaker count</Label>
<Input value={diarizeSpeakerCount} id="speakerCount" type="number" placeholder="2" onChange={(e) => setDiarizeSpeakerCount(Math.abs(Number.parseInt(e.target.value)))} />
<Label htmlFor="speakerCount">Number of Speakers</Label>
<Input value={diarizeSpeakerCount} id="speakerCount" type="number" placeholder="Enter number of speakers" onChange={(e) => setDiarizeSpeakerCount(Math.abs(Number.parseInt(e.target.value)))} />
</div>
)}
</CardContent>
Expand Down

0 comments on commit 62ce4de

Please sign in to comment.