From 6d1170386b9530282a282f553c4f056e01a9df9a Mon Sep 17 00:00:00 2001 From: Luis Felix Date: Wed, 4 Sep 2024 23:09:46 -0400 Subject: [PATCH 1/8] OV-144: + initial helper to transofrm payload to text to AI --- .../generate-script-placeholder.tsx | 37 ++++++++++++------- .../generate-script-view.tsx | 18 ++++++++- .../components/menu-body/styles.module.css | 2 +- 3 files changed, 42 insertions(+), 15 deletions(-) diff --git a/frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-placeholder/generate-script-placeholder.tsx b/frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-placeholder/generate-script-placeholder.tsx index 174022892..c4bb7bb4d 100644 --- a/frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-placeholder/generate-script-placeholder.tsx +++ b/frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-placeholder/generate-script-placeholder.tsx @@ -1,27 +1,38 @@ import { Icon, Text, VStack } from '@chakra-ui/react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { useMemo } from '~/bundles/common/hooks/hooks.js'; import { IconName } from '~/bundles/common/icons/icons.js'; -const GenerateScriptPlaceholder: React.FC = () => { +type Properties = { + generatedText: string; +}; + +const GenerateScriptPlaceholder: React.FC = ({ generatedText }) => { + const isGenearatedTextEmpty = useMemo(() => generatedText.length === 0, [generatedText]); + return ( - + {isGenearatedTextEmpty && ( + + )} - Here you will see your generated script + {isGenearatedTextEmpty + ? 'Here you will see your generated script' + : generatedText} ); diff --git a/frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-view/generate-script-view.tsx b/frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-view/generate-script-view.tsx index 697d71b9c..a81de0d10 100644 --- a/frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-view/generate-script-view.tsx +++ b/frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-view/generate-script-view.tsx @@ -14,6 +14,22 @@ import { type GenerateVideoScriptRequestDto } from '~/bundles/video-scripts/vide import { GenerateScriptForm } from '../generate-script-form/generate-script-form.js'; import { GenerateScriptPlaceholder } from '../generate-script-placeholder/generate-script-placeholder.js'; +// eslint-disable-next-line @typescript-eslint/no-unused-vars +const getVideoScriptMessageFromPayload = ( + payload: GenerateVideoScriptRequestDto, +): string => { + const { language, topic, tone, additionalInfo } = payload; + const additionalInfoMessage = + additionalInfo.length > 0 + ? `, to make a better script use this additional information: '${additionalInfo}'` + : ''; + + return `Create the script narration for a video, + divided in scene, generate script on topic '${topic}' + in '${language}' using a '${tone}' tone ${additionalInfoMessage}. + `; +}; + const GenerateScriptView: React.FC = () => { const handleGenerateVideoScriptSubmit = useCallback( // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -60,7 +76,7 @@ const GenerateScriptView: React.FC = () => { - + diff --git a/frontend/src/bundles/studio/components/video-menu/components/menu-body/styles.module.css b/frontend/src/bundles/studio/components/video-menu/components/menu-body/styles.module.css index 5533bae49..8ca5b0eef 100644 --- a/frontend/src/bundles/studio/components/video-menu/components/menu-body/styles.module.css +++ b/frontend/src/bundles/studio/components/video-menu/components/menu-body/styles.module.css @@ -20,5 +20,5 @@ } .menu-body-content::-webkit-scrollbar { - display: none, + display: none; } From 82d80b9b703fb6c3e23b0ea3c27cba69963cadbd Mon Sep 17 00:00:00 2001 From: Luis Felix Date: Thu, 5 Sep 2024 20:57:28 -0400 Subject: [PATCH 2/8] OV-144: + generate text with AI using chat component --- .../bundles/common/components/components.ts | 5 ++ .../generate-script-form.tsx | 29 +++++++++- .../generate-script-placeholder.tsx | 8 ++- .../styles.module.css | 35 +++++++++++ .../generate-script-view.tsx | 58 ++++++++++++++++--- .../components/video-modal/video-modal.tsx | 8 ++- 6 files changed, 130 insertions(+), 13 deletions(-) create mode 100644 frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-placeholder/styles.module.css diff --git a/frontend/src/bundles/common/components/components.ts b/frontend/src/bundles/common/components/components.ts index 94ef376fd..5cf5750ec 100644 --- a/frontend/src/bundles/common/components/components.ts +++ b/frontend/src/bundles/common/components/components.ts @@ -25,6 +25,7 @@ export { FormControl, FormErrorMessage, Heading, + HStack, Icon, IconButton, Image, @@ -37,6 +38,10 @@ export { SimpleGrid, Spacer, Tab, + TabList, + TabPanel, + TabPanels, + Tabs, Text, Tooltip, VStack, diff --git a/frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-form/generate-script-form.tsx b/frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-form/generate-script-form.tsx index 032d2cee7..f9643e142 100644 --- a/frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-form/generate-script-form.tsx +++ b/frontend/src/bundles/common/components/video-modal/components/video-modal-content/components/generate-script-form/generate-script-form.tsx @@ -1,3 +1,4 @@ +import { MessageSender } from '~/bundles/chat/enums/enums.js'; import { Button, FormProvider, @@ -6,7 +7,13 @@ import { Textarea, VStack, } from '~/bundles/common/components/components.js'; -import { useAppForm } from '~/bundles/common/hooks/hooks.js'; +import { DataStatus } from '~/bundles/common/enums/enums.js'; +import { + useAppForm, + useAppSelector, + useCallback, + useMemo, +} from '~/bundles/common/hooks/hooks.js'; import { type GenerateVideoScriptRequestDto, generateVideoScriptValidationSchema, @@ -19,6 +26,12 @@ type Properties = { }; const GenerateScriptForm: React.FC = ({ onSubmit }) => { + const { messages, dataStatus } = useAppSelector(({ chat }) => ({ + messages: chat.messages.filter( + (message) => message.sender === MessageSender.AI, + ), + dataStatus: chat.dataStatus, + })); const form = useAppForm({ initialValues: DEFAULT_GENERATE_SCRIPT_PAYLOAD, validationSchema: generateVideoScriptValidationSchema, @@ -27,6 +40,18 @@ const GenerateScriptForm: React.FC = ({ onSubmit }) => { const { handleSubmit, values } = form; + const isTextGenerated: boolean = useMemo(() => { + return messages && messages.length > 0; + }, [messages]); + + const getButtonLabel = useCallback(() => { + if (dataStatus === DataStatus.PENDING) { + return 'stop'; + } + + return isTextGenerated ? 'Re-Generate' : 'Generate script'; + }, [dataStatus, isTextGenerated]); + return (
@@ -57,7 +82,7 @@ const GenerateScriptForm: React.FC = ({ onSubmit }) => { />