From e9ba840cb5646eddd808e625cee43c80caab499a Mon Sep 17 00:00:00 2001 From: preston176 Date: Wed, 29 May 2024 21:37:26 +0300 Subject: [PATCH] feat: Add link to Summarize page in AiServices.jsx --- src/Pages/AiServices.jsx | 1 + src/Pages/Summarize.jsx | 63 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/Pages/Summarize.jsx diff --git a/src/Pages/AiServices.jsx b/src/Pages/AiServices.jsx index 19a2fe2..b82cd62 100644 --- a/src/Pages/AiServices.jsx +++ b/src/Pages/AiServices.jsx @@ -31,6 +31,7 @@ const AiServices = ({ isDarkMode }) => { icon: , title: "Summarization", description: "Summarize long documents, articles, or reports into concise overviews.", + link: '/services/summarize' }, ] //TODO: To be implemented diff --git a/src/Pages/Summarize.jsx b/src/Pages/Summarize.jsx new file mode 100644 index 0000000..855b2a3 --- /dev/null +++ b/src/Pages/Summarize.jsx @@ -0,0 +1,63 @@ +import { useRef, useState } from 'react'; +import axios from 'axios'; +import '../Components/ImageGenerator/ImageGenerator.css'; +import Swal from 'sweetalert2'; + +const Summarize = ({ isDarkMode }) => { + const [summary, setSummary] = useState(''); + const [loading, setLoading] = useState(false); + const inputReference = useRef(null); + + const handleSummarize = async () => { + if (inputReference.current.value === '') { + // alert('Please enter some text to summarize.'); + Swal.fire({ + icon: 'error', + title: 'Oops...', + text: "Please enter some text to summarize", + }); + return; + } + setLoading(true); + try { + const response = await axios.post('YOUR_OPENAI_API_ENDPOINT', { + text: inputReference.current.value + }, { + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${process.env.OPENAI_API_KEY}` + } + }); + + setSummary(response.data.summary); + setLoading(false); + } catch (error) { + console.error('Error generating summary:', error); + Swal.fire({ + icon: 'error', + title: 'Oops...', + text: 'Failed to generate summary. Please try again later.' + }); + setLoading(false); + } + }; + + return ( +
+
Text Summarization
+
+