From 3149b94cc31d7e2e2455046a714610d2e5d3517b Mon Sep 17 00:00:00 2001 From: agatha197 Date: Mon, 6 Jan 2025 11:26:24 +0900 Subject: [PATCH] [FR-315] feat: integrate image generation model --- .../lablupTalkativotUI/LLMChatCard.tsx | 161 ++++++++++++++---- resources/i18n/de.json | 3 +- resources/i18n/el.json | 3 +- resources/i18n/en.json | 3 +- resources/i18n/es.json | 3 +- resources/i18n/fi.json | 3 +- resources/i18n/fr.json | 3 +- resources/i18n/id.json | 3 +- resources/i18n/it.json | 3 +- resources/i18n/ja.json | 3 +- resources/i18n/ko.json | 3 +- resources/i18n/mn.json | 3 +- resources/i18n/ms.json | 3 +- resources/i18n/pl.json | 3 +- resources/i18n/pt-BR.json | 3 +- resources/i18n/pt.json | 3 +- resources/i18n/ru.json | 3 +- resources/i18n/th.json | 3 +- resources/i18n/tr.json | 3 +- resources/i18n/vi.json | 3 +- resources/i18n/zh-CN.json | 3 +- resources/i18n/zh-TW.json | 3 +- 22 files changed, 166 insertions(+), 58 deletions(-) diff --git a/react/src/components/lablupTalkativotUI/LLMChatCard.tsx b/react/src/components/lablupTalkativotUI/LLMChatCard.tsx index 2d545c99c8..473d602688 100644 --- a/react/src/components/lablupTalkativotUI/LLMChatCard.tsx +++ b/react/src/components/lablupTalkativotUI/LLMChatCard.tsx @@ -13,6 +13,7 @@ import { DeleteOutlined, LinkOutlined, MoreOutlined, + PictureOutlined, RocketOutlined, } from '@ant-design/icons'; import { Attachments, AttachmentsProps, Sender } from '@ant-design/x'; @@ -31,6 +32,7 @@ import { MenuProps, Tag, theme, + Tooltip, Typography, } from 'antd'; import _ from 'lodash'; @@ -92,6 +94,8 @@ const LLMChatCard: React.FC = ({ }) => { const webuiNavigate = useWebUINavigate(); const [isOpenAttachments, setIsOpenAttachments] = useState(false); + const [isImageGeneration, setIsImageGeneration] = useState(false); + const [loadingImageGeneration, setLoadingImageGeneration] = useState(false); const [modelId, setModelId] = useControllableValue(cardProps, { valuePropName: 'modelId', @@ -214,6 +218,34 @@ const LLMChatCard: React.FC = ({ }, ]); + const generateImage = async (prompt: string, accessKey: string) => { + setLoadingImageGeneration(true); + try { + const response = await fetch( + 'https://flux-inference.asia03.app.backend.ai/generate-flux-image', + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + prompt: prompt, + access_key: accessKey, + }), + }, + ); + + if (response.ok) { + const responseData = await response.json(); + return responseData.image_base64; + } else { + throw new Error('Error generating image'); + } + } finally { + setLoadingImageGeneration(false); + } + }; + return ( = ({ value={modelId} onChange={setModelId} allowCustomModel={allowCustomModel} + disabled={isImageGeneration} />