From b7e54c50e42fc5daec39127f7d4fe117074b9ec6 Mon Sep 17 00:00:00 2001 From: BFlat Date: Fri, 17 Nov 2023 11:33:53 +0700 Subject: [PATCH] voice designer results that link to media page --- ...ssionVoiceDesignerInferenceResultsList.tsx | 341 ++++++++++++++++++ .../VoiceDesignerUseVoicePage.tsx | 4 +- 2 files changed, 343 insertions(+), 2 deletions(-) create mode 100644 packages/fakeyou.com/src/v2/view/_common/SessionVoiceDesignerInferenceResultsList.tsx diff --git a/packages/fakeyou.com/src/v2/view/_common/SessionVoiceDesignerInferenceResultsList.tsx b/packages/fakeyou.com/src/v2/view/_common/SessionVoiceDesignerInferenceResultsList.tsx new file mode 100644 index 0000000000..239baf34cb --- /dev/null +++ b/packages/fakeyou.com/src/v2/view/_common/SessionVoiceDesignerInferenceResultsList.tsx @@ -0,0 +1,341 @@ +import React, { useEffect, useState } from "react"; +import { Link } from "react-router-dom"; +import { TtsInferenceJob } from "../../../App"; +import { BucketConfig } from "@storyteller/components/src/api/BucketConfig"; +import { JobState } from "@storyteller/components/src/jobs/JobStates"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { + faClock, + faLink, + faHeadphonesSimple, +} from "@fortawesome/free-solid-svg-icons"; + +import { SessionSubscriptionsWrapper } from "@storyteller/components/src/session/SessionSubscriptionsWrapper"; +import { Analytics } from "../../../common/Analytics"; +import { SessionTtsAudioPlayer } from "./SessionTtsAudioPlayer"; +import { WebUrl } from "../../../common/WebUrl"; +import { + GetPendingTtsJobCount, + GetPendingTtsJobCountIsOk, + GetPendingTtsJobCountSuccessResponse, +} from "@storyteller/components/src/api/tts/GetPendingTtsJobCount"; +import { InferenceJob } from "@storyteller/components/src/jobs/InferenceJob"; +import { useLocalize } from "hooks"; + +interface Props { + inferenceJobs: Array; + ttsInferenceJobs: Array; + sessionSubscriptionsWrapper: SessionSubscriptionsWrapper; +} + +// TODO: This is duplicated in SessionTtsInferenceResultsList ! +// Default to querying every 15 seconds, but make it configurable serverside +const DEFAULT_QUEUE_REFRESH_INTERVAL_MILLIS = 15000; + +function SessionVoiceDesignerInferenceResultsList(props: Props) { + const { t } = useLocalize("SessionTtsInferenceResultList"); + + const [pendingTtsJobs, setPendingTtsJobs] = + useState({ + success: true, + pending_job_count: 0, + cache_time: new Date(0), // NB: Epoch is used for vector clock's initial state + refresh_interval_millis: DEFAULT_QUEUE_REFRESH_INTERVAL_MILLIS, + }); + + useEffect(() => { + const fetch = async () => { + const response = await GetPendingTtsJobCount(); + if (GetPendingTtsJobCountIsOk(response)) { + if ( + response.cache_time.getTime() > pendingTtsJobs.cache_time.getTime() + ) { + setPendingTtsJobs(response); + } + } + }; + // TODO: We're having an outage and need to lower this. + //const interval = setInterval(async () => fetch(), 15000); + const refreshInterval = Math.max( + DEFAULT_QUEUE_REFRESH_INTERVAL_MILLIS, + pendingTtsJobs.refresh_interval_millis + ); + const interval = setInterval(async () => fetch(), refreshInterval); + fetch(); + return () => clearInterval(interval); + }, [pendingTtsJobs]); + + let results: Array = []; + + // TODO(bt,2023-04-08): Clean this utter garbage duplication up. + + // ============================= GENERIC INFERENCE ============================= + + props.inferenceJobs.forEach((job) => { + if (!job.maybeResultToken) { + let cssStyle = "alert alert-secondary mb-0"; + let stateDescription = "Pending..."; + + switch (job.jobState) { + case JobState.PENDING: + case JobState.UNKNOWN: + stateDescription = + job.maybeExtraStatusDescription == null + ? t("resultsProgressPending") + : job.maybeExtraStatusDescription; + break; + case JobState.STARTED: + cssStyle = "alert alert-success mb-0"; + stateDescription = + job.maybeExtraStatusDescription == null + ? t("resultsProgressStarted") + : job.maybeExtraStatusDescription; + break; + case JobState.ATTEMPT_FAILED: + cssStyle = "alert alert-danger mb-0"; + stateDescription = `${t("resultsProgressFail", { + 0: job.attemptCount || "0", + })}}`; + break; + case JobState.COMPLETE_FAILURE: + case JobState.DEAD: + cssStyle = "alert alert-danger mb-0"; + // TODO(bt,2023-01-23): Translate when I can test it + stateDescription = t("resultsProgressDead"); + break; + case JobState.COMPLETE_SUCCESS: + cssStyle = "message is-success mb-0"; + // Not sure why we're here instead of other branch! + stateDescription = t("resultsProgressSuccess"); + break; + } + + results.push( +
+
+
+
{stateDescription}
+
+
+
+ ); + } else { + let audioLink = new BucketConfig().getGcsUrl( + job.maybeResultPublicBucketMediaPath + ); + let ttsPermalink = `/media/${job.maybeResultToken}`; + + let wavesurfers = ; + + results.push( +
+ {/*
+

{job.title}

+ +
*/} +
+
+
+
{job.maybeModelTitle}
+

{job.maybeRawInferenceText}

+
+ + {/* */} + + {wavesurfers} + +
+ { + Analytics.ttsClickResultLink(); + }} + className="fw-semibold" + > + + {t("resultsAudioShareDownload")} + +
+
+
+
+ ); + } + }); + + // TODO(bt,2023-04-08): Clean this utter garbage duplication up. + + // ============================= LEGACY TTS ============================= + + props.ttsInferenceJobs.forEach((job) => { + if (!job.maybeResultToken) { + let cssStyle = "alert alert-secondary mb-0"; + let stateDescription = "Pending..."; + + switch (job.jobState) { + case JobState.PENDING: + case JobState.UNKNOWN: + stateDescription = + job.maybeExtraStatusDescription == null + ? t("resultsProgressPending") + : job.maybeExtraStatusDescription; + break; + case JobState.STARTED: + cssStyle = "alert alert-success mb-0"; + stateDescription = + job.maybeExtraStatusDescription == null + ? t("resultsProgressStarted") + : job.maybeExtraStatusDescription; + break; + case JobState.ATTEMPT_FAILED: + cssStyle = "alert alert-danger mb-0"; + stateDescription = `${t("resultsProgressFail", { + 0: job.attemptCount || "0", + })}}`; + break; + case JobState.COMPLETE_FAILURE: + case JobState.DEAD: + cssStyle = "alert alert-danger mb-0"; + // TODO(bt,2023-01-23): Translate when I can test it + stateDescription = t("resultsProgressDead"); + break; + case JobState.COMPLETE_SUCCESS: + cssStyle = "message is-success mb-0"; + // Not sure why we're here instead of other branch! + stateDescription = t("resultsProgressSuccess"); + break; + } + + results.push( +
+
+
+
{stateDescription}
+
+
+
+ ); + } else { + let audioLink = new BucketConfig().getGcsUrl( + job.maybePublicBucketWavAudioPath + ); + let ttsPermalink = `/tts/result/${job.maybeResultToken}`; + + let wavesurfers = ; + + results.push( +
+ {/*
+

{job.title}

+ +
*/} +
+
+
+
{job.title}
+

{job.rawInferenceText}

+
+ + {/* */} + + {wavesurfers} + +
+ { + Analytics.ttsClickResultLink(); + }} + className="fw-semibold" + > + + {t("resultsAudioShareDownload")} + +
+
+
+
+ ); + } + }); + + // ============================= END LEGACY TTS ============================= + + let noResultsSection = ( +
+
+ +
{t("resultsBlankText")}
+

{t("resultsBlankSubText")}

+
+
+ ); + + if (results.length === 0) { + return <>{noResultsSection}; + } + + let upgradeNotice = <>; + + // Ask non-premium users to upgrade + if ( + results.length !== 0 && + !props.sessionSubscriptionsWrapper.hasPaidFeatures() + ) { + upgradeNotice = ( +
+
+ + {t("resultsUpgradeNotice")}{" "} + { + Analytics.ttsTooSlowUpgradePremium(); + }} + className="alert-link fw-semibold" + > + {t("resultsUpgradeLinkText")} + {" "} + ({t("resultsTtsQueued")}{" "} + ~{pendingTtsJobs.pending_job_count}) +
+
+ ); + } + + // Users have requested reverse chronological results + results.reverse(); + + return ( +
+
+
+ {upgradeNotice} +
{results}
+
+
+
+ ); +} + +export { SessionVoiceDesignerInferenceResultsList }; diff --git a/packages/fakeyou.com/src/v2/view/pages/voice_designer/VoiceDesignerUseVoicePage.tsx b/packages/fakeyou.com/src/v2/view/pages/voice_designer/VoiceDesignerUseVoicePage.tsx index 9d8bec8723..f66555a637 100644 --- a/packages/fakeyou.com/src/v2/view/pages/voice_designer/VoiceDesignerUseVoicePage.tsx +++ b/packages/fakeyou.com/src/v2/view/pages/voice_designer/VoiceDesignerUseVoicePage.tsx @@ -19,7 +19,7 @@ import { SessionWrapper } from "@storyteller/components/src/session/SessionWrapp import Container from "components/common/Container/Container"; import TextArea from "components/common/TextArea"; import { Button } from "components/common"; -import { SessionTtsInferenceResultList } from "v2/view/_common/SessionTtsInferenceResultsList"; +import { SessionVoiceDesignerInferenceResultsList } from "v2/view/_common/SessionVoiceDesignerInferenceResultsList"; import { FrontendInferenceJobType, InferenceJob, @@ -230,7 +230,7 @@ export default function VoiceDesignerUseVoicePage( Session TTS Results
-