gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
Пожалуйста, сформируй полный HTML-код (ничего не пропускай), выделив его обратными…
- User
Пожалуйста, сформируй полный HTML-код (ничего не пропускай), выделив его обратными тройными кавычками, для следующего запроса: "Изначально блок с id continue-container скрыт и появляется, когда заканчивается анимация ввода текста, но после продолжения истории этот блок должен снова исчезнуть, пока не закончится анимация вывода текста. Также перемести иконку домика в левый верхний угол". В прошлой итерации код выглядел следующим образом: "
body, html { width: 100%; height: 100%; font-family: 'Arial', sans-serif; background-color: #f0f4f8; color: #333; overflow: hidden; } /* Language Switcher */ .language-switcher { position: fixed; top: 20px; right: 20px; display: flex; gap: 10px; z-index: 1000; } .language-switcher button { background: #fff; border: 1px solid #ccc; border-radius: 5px; padding: 5px 10px; cursor: pointer; transition: background 0.3s; } .language-switcher button.active { background: #007bff; color: #fff; border-color: #007bff; } /* Main Section */ .main-section, .story-section { display: none; flex-direction: column; align-items: center; justify-content: center; height: 100vh; width: 100%; padding: 20px; text-align: center; } .main-section.active, .story-section.active { display: flex; } .main-section h1 { font-size: 3em; margin-bottom: 20px; color: #007bff; } .input-container { position: relative; width: 100%; max-width: 500px; margin-bottom: 20px; } .input-container input { width: 100%; padding: 15px 50px 15px 15px; border: 2px solid #ccc; border-radius: 5px; font-size: 1em; transition: border-color 0.3s; } .input-container input:focus { border-color: #007bff; outline: none; } .input-container .icon-button { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: #007bff; font-size: 1.2em; transition: color 0.3s; } .input-container .icon-button:hover { color: #0056b3; } .main-section button, .story-section button { padding: 15px 30px; font-size: 1em; color: #fff; background-color: #007bff; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s; } .main-section button:hover, .story-section button:hover { background-color: #0056b3; } /* Loading Animation */ .loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(240, 244, 248, 0.9); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1001; display: none; } .loading-overlay.active { display: flex; } .spinner { border: 8px solid #f3f3f3; border-top: 8px solid #007bff; border-radius: 50%; width: 60px; height: 60px; animation: spin 1s linear infinite; margin-bottom: 20px; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .loading-overlay p { font-size: 1.2em; color: #333; } /* Story Section */ .story-text { max-width: 800px; background: rgba(255, 255, 255, 0.8); padding: 20px; border-radius: 10px; font-size: 1.2em; line-height: 1.6; animation: fadeIn 1s forwards; opacity: 0; } @keyframes fadeIn { to { opacity: 1; } } .story-section .input-container { margin-top: 20px; } /* Modal */ .modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); display: none; align-items: center; justify-content: center; z-index: 1002; } .modal.active { display: flex; } .modal-content { background: #fff; padding: 30px; border-radius: 10px; text-align: center; max-width: 400px; width: 90%; } .modal-content p { margin-bottom: 20px; font-size: 1.1em; } .modal-content button { padding: 10px 20px; margin: 0 10px; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; transition: background-color 0.3s; } .modal-content .confirm { background-color: #007bff; color: #fff; } .modal-content .confirm:hover { background-color: #0056b3; } .modal-content .cancel { background-color: #ccc; color: #333; } .modal-content .cancel:hover { background-color: #999; } /* Responsive Design */ @media (max-width: 600px) { .main-section h1 { font-size: 2em; } .input-container input { padding: 10px 40px 10px 10px; font-size: 0.9em; } .main-section button, .story-section button { padding: 10px 20px; font-size: 0.9em; } .story-text { font-size: 1em; padding: 15px; } } - Assistant
Конечно! Вот обновленный полный HTML-код с требуемыми изменениями:
<!DOCTYPE html> <html lang="ru"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no"> <title>AI Stories</title> <!-- Font Awesome CDN --> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-pzw1XyV7aN1H1Oq+oC5GYoPZ4IU/w7y0VbYKV2UoRIqDzx5VbLkGnDypEyu0J66Mf4tV6nLrBtf9M0Ew5P1qYQ==" crossorigin="anonymous" referrerpolicy="no-referrer" /> <style> /* Reset and basic styles */ * { margin: 0; padding: 0; box-sizing: border-box; } body, html { width: 100%; height: 100%; font-family: 'Arial', sans-serif; background-color: #f0f4f8; color: #333; overflow: hidden; } /* Language Switcher */ .language-switcher { position: fixed; top: 20px; right: 20px; display: flex; gap: 10px; z-index: 1000; } .language-switcher button { background: #fff; border: 1px solid #ccc; border-radius: 5px; padding: 5px 10px; cursor: pointer; transition: background 0.3s; } .language-switcher button.active { background: #007bff; color: #fff; border-color: #007bff; } /* Main Section */ .main-section, .story-section { display: none; flex-direction: column; align-items: center; justify-content: center; height: 100vh; width: 100%; padding: 20px; text-align: center; } .main-section.active, .story-section.active { display: flex; } .main-section h1 { font-size: 3em; margin-bottom: 20px; color: #007bff; } .input-container { position: relative; width: 100%; max-width: 500px; margin-bottom: 20px; } .input-container input { width: 100%; padding: 15px 50px 15px 15px; border: 2px solid #ccc; border-radius: 5px; font-size: 1em; transition: border-color 0.3s; } .input-container input:focus { border-color: #007bff; outline: none; } .input-container .icon-button { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: #007bff; font-size: 1.2em; transition: color 0.3s; } .input-container .icon-button:hover { color: #0056b3; } .main-section button, .story-section button { padding: 15px 30px; font-size: 1em; color: #fff; background-color: #007bff; border: none; border-radius: 5px; cursor: pointer; transition: background-color 0.3s; } .main-section button:hover, .story-section button:hover { background-color: #0056b3; } /* Loading Animation */ .loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(240, 244, 248, 0.9); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1001; display: none; } .loading-overlay.active { display: flex; } .spinner { border: 8px solid #f3f3f3; border-top: 8px solid #007bff; border-radius: 50%; width: 60px; height: 60px; animation: spin 1s linear infinite; margin-bottom: 20px; } @keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .loading-overlay p { font-size: 1.2em; color: #333; } /* Story Section */ .story-text { max-width: 800px; background: rgba(255, 255, 255, 0.8); padding: 20px; border-radius: 10px; font-size: 1.2em; line-height: 1.6; animation: fadeIn 1s forwards; opacity: 0; } @keyframes fadeIn { to { opacity: 1; } } .story-section .input-container { margin-top: 20px; } /* Modal */ .modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0, 0, 0, 0.5); display: none; align-items: center; justify-content: center; z-index: 1002; } .modal.active { display: flex; } .modal-content { background: #fff; padding: 30px; border-radius: 10px; text-align: center; max-width: 400px; width: 90%; } .modal-content p { margin-bottom: 20px; font-size: 1.1em; } .modal-content button { padding: 10px 20px; margin: 0 10px; border: none; border-radius: 5px; cursor: pointer; font-size: 1em; transition: background-color 0.3s; } .modal-content .confirm { background-color: #007bff; color: #fff; } .modal-content .confirm:hover { background-color: #0056b3; } .modal-content .cancel { background-color: #ccc; color: #333; } .modal-content .cancel:hover { background-color: #999; } /* Responsive Design */ @media (max-width: 600px) { .main-section h1 { font-size: 2em; } .input-container input { padding: 10px 40px 10px 10px; font-size: 0.9em; } .main-section button, .story-section button { padding: 10px 20px; font-size: 0.9em; } .story-text { font-size: 1em; padding: 15px; } } /* Home Button */ #home-button { position: fixed; top: 20px; left: 20px; background: none; border: none; cursor: pointer; color: #007bff; font-size: 1.5em; } #home-button:hover { color: #0056b3; } </style> </head> <body> <!-- Language Switcher --> <div class="language-switcher"> <button id="lang-ru" class="active">RU</button> <button id="lang-en">EN</button> </div> <!-- Main Section --> <section class="main-section active" id="main-section"> <h1 data-translate="appTitle">AI Stories</h1> <div class="input-container"> <input type="text" id="story-input" placeholder="Введите начало истории" /> <button class="icon-button" id="random-story-button" title="Случайная история"> <i class="fas fa-magic"></i> </button> </div> <button id="start-story-button" data-translate="startButton">Начать историю</button> </section> <!-- Story Section --> <section class="story-section" id="story-section"> <div class="story-text" id="story-text"></div> <button id="home-button" title="Домик"> <i class="fas fa-house"></i> </button> <div class="input-container" id="continue-container" style="display: none;"> <input type="text" id="continue-input" placeholder="Введите продолжение истории" /> <button id="continue-story-button" data-translate="continueButton">Продолжить</button> </div> </section> <!-- Loading Overlay --> <div class="loading-overlay" id="loading-overlay"> <div class="spinner"></div> <p id="loading-text">Создание истории...</p> </div> <!-- Modal --> <div class="modal" id="modal"> <div class="modal-content"> <p data-translate="modalQuestion">Вы уверены, что хотите вернуться на главную?</p> <button class="confirm" id="modal-confirm" data-translate="confirm">Да</button> <button class="cancel" id="modal-cancel" data-translate="cancel">Нет</button> </div> </div> <script> // Translation Dictionary const translations = { "appTitle": { "ru": "AI Stories", "en": "AI Stories" }, "startButton": { "ru": "Начать историю", "en": "Start Story" }, "continueButton": { "ru": "Продолжить", "en": "Continue" }, "modalQuestion": { "ru": "Вы уверены, что хотите вернуться на главную?", "en": "Are you sure you want to return to the main page?" }, "confirm": { "ru": "Да", "en": "Yes" }, "cancel": { "ru": "Нет", "en": "No" }, "storyPlaceholderRu": "Введите начало истории", "storyPlaceholderEn": "Enter the beginning of the story" }; let currentLanguage = 'ru'; let storyHistory = ''; let imageGenerated = false; let imageUrl = ''; let textSpeed = 50; // milliseconds per character // Language Switcher const langRuButton = document.getElementById('lang-ru'); const langEnButton = document.getElementById('lang-en'); langRuButton.addEventListener('click', () => switchLanguage('ru')); langEnButton.addEventListener('click', () => switchLanguage('en')); function switchLanguage(lang) { currentLanguage = lang; document.querySelectorAll('[data-translate]').forEach(elem => { const key = elem.getAttribute('data-translate'); if (translations[key] && translations[key][lang]) { elem.textContent = translations[key][lang]; } }); // Update placeholders const storyInput = document.getElementById('story-input'); const continueInput = document.getElementById('continue-input'); if (currentLanguage === 'ru') { storyInput.placeholder = translations['storyPlaceholderRu']; continueInput.placeholder = translations['storyPlaceholderRu']; } else { storyInput.placeholder = translations['storyPlaceholderEn']; continueInput.placeholder = translations['storyPlaceholderEn']; } // Toggle active button if (lang === 'ru') { langRuButton.classList.add('active'); langEnButton.classList.remove('active'); } else { langEnButton.classList.add('active'); langRuButton.classList.remove('active'); } } // Event Delegation for Buttons document.getElementById('start-story-button').addEventListener('click', startStory); document.getElementById('random-story-button').addEventListener('click', getRandomStory); document.getElementById('home-button').addEventListener('click', () => showModal(true)); document.getElementById('modal-confirm').addEventListener('click', () => { hideModal(); returnToMain(); }); document.getElementById('modal-cancel').addEventListener('click', hideModal); document.getElementById('continue-story-button').addEventListener('click', continueStory); // Show Modal Function function showModal() { document.getElementById('modal').classList.add('active'); } function hideModal() { document.getElementById('modal').classList.remove('active'); } // Return to Main Function function returnToMain() { document.getElementById('story-section').classList.remove('active'); document.getElementById('main-section').classList.add('active'); storyHistory = ''; imageGenerated = false; imageUrl = ''; document.getElementById('story-text').innerHTML = ''; document.getElementById('story-section').style.backgroundImage = ''; document.getElementById('continue-container').style.display = 'none'; } // Start Story Function function startStory() { const input = document.getElementById('story-input').value.trim(); if (input === '') return; storyHistory = input; initiateStoryProcessing(); } // Continue Story Function function continueStory() { const input = document.getElementById('continue-input').value.trim(); if (input !== '') { storyHistory += ' ' + input; } document.getElementById('continue-container').style.display = 'none'; initiateStoryProcessing(true); } // Get Random Story Function function getRandomStory() { // Implementing random story functionality if needed // For now, it can trigger the startStory with a random prompt const randomPrompts = { "ru": "Начало случайной истории", "en": "Start of a random story" }; storyHistory = currentLanguage === 'ru' ? randomPrompts.ru : randomPrompts.en; initiateStoryProcessing(); } // Initiate Story Processing async function initiateStoryProcessing() { showLoading(); try { // First Request: Generate Story Text with retries const storyText = await fetchWithRetries(() => requestStory(storyHistory, currentLanguage), 5, 'story'); storyHistory = storyText; // Second Request: Generate Description in English const description = await requestDescription(storyText); // Third Request: Generate Image const generatedImageUrl = await requestImage(description); if (generatedImageUrl) { imageUrl = generatedImageUrl; imageGenerated = true; } else { imageGenerated = false; } // Update Story Section updateStorySection(); } catch (error) { showError(error); } finally { hideLoading(); } } // Fetch with Retries function fetchWithRetries(fetchFunction, retries, type) { return new Promise((resolve, reject) => { const attempt = (n) => { fetchFunction().then(resolve).catch((err) => { if (n > 0 && type === 'story') { attempt(n - 1); } else { reject(err); } }); }; attempt(retries); }); } // Request Story Function function requestStory(prompt, lang) { return new Promise((resolve, reject) => { const localizedPrompt = lang === 'ru' ? `Придумай незавершенную историю длиной aproximadamente на 600 символов на языке "${lang}" на запрос: "${prompt}"` : `Come up with an unfinished story of about 600 characters in length in the language "${lang}" per request: "${prompt}"`; requestAI(localizedPrompt, { responseCallback: ({ message }) => { resolve(message); }, errorCallback: ({ message }) => { reject(message); }, }); }); } // Request Description Function function requestDescription(text) { return new Promise((resolve, reject) => { const prompt = `Come up with a short description in English, about 10 words long or less, that describes the query: "${text}"`; requestAI(prompt, { responseCallback: ({ message }) => { resolve(message); }, errorCallback: () => { resolve(null); // Continue without image }, }); }); } // Request Image Function function requestImage(description) { if (!description) return Promise.resolve(null); return new Promise((resolve, reject) => { requestAI(description, { type: 'image', responseCallback: ({ image }) => { resolve(image); }, errorCallback: () => { resolve(null); // Continue without image }, }); }); } // Update Story Section function updateStorySection() { document.getElementById('main-section').classList.remove('active'); const storySection = document.getElementById('story-section'); storySection.classList.add('active'); if (imageGenerated) { storySection.style.backgroundImage = `url('${imageUrl}')`; storySection.style.opacity = 1; } else { storySection.style.backgroundColor = '#a8d0e6'; storySection.style.opacity = 1; } animateText(storyHistory); } // Animate Text Function function animateText(text) { const storyTextElement = document.getElementById('story-text'); storyTextElement.innerHTML = ''; let index = 0; function type() { if (index < text.length) { storyTextElement.innerHTML += text.charAt(index); index++; setTimeout(type, textSpeed); } else { document.getElementById('continue-container').style.display = 'flex'; } } type(); } // Show Loading function showLoading() { document.getElementById('loading-text').textContent = currentLanguage === 'ru' ? 'Создание истории...' : 'Creating story...'; document.getElementById('loading-overlay').classList.add('active'); } // Hide Loading function hideLoading() { document.getElementById('loading-overlay').classList.remove('active'); } // Show Error Notification function showError(message) { alert(currentLanguage === 'ru' ? 'Произошла ошибка при создании истории.' : 'An error occurred while creating the story.'); } function requestAI(prompt, { url = 'https://nexra.aryahcr.cc/api/chat/complements', model = 'gpt-4o', stream = false, markdown = false, type = 'text', messages = [], // Бывают roles: system, user, assistant responseCallback = () => { }, // Колбек ответа от сервера вне зависимости от стриминга successCallback = () => { }, // Колбек для успешного завершения errorCallback = () => { }, // Колбек ошибки } = {}) { if (type === 'text') { // Текст messages.push({ role: 'user', content: prompt }); let body = { messages, model, stream, markdown, }; if (url.indexOf('/gptweb') !== -1) { body = { prompt, markdown, }; } if (messages.length > 1 && model === 'llama-3.1') { body.messages = [{ role: 'user', content: JSON.stringify({ messages: messages }) }]; } if (model === 'Bing') { body['conversation_style'] = 'balanced'; } if (model === 'blackbox') { body['websearch'] = false; } fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(body), }).then(response => response.text()).then((data) => { const modData = JSON.parse(data.slice(data.indexOf('{'))); const message = modData.message || modData.gpt; responseCallback({ data, modData, message, isStream: stream, isStreaming: false }); successCallback({ data, modData, message, isStream: stream, isStreaming: false }); }).catch((error) => { errorCallback({ message: `Ошибка в функции requestAI (type: text, stream: false): ${error}`, error }); }); } else if (type === 'image') { // Картинка model = 'emi'; fetch("https://nexra.aryahcr.cc/api/image/complements", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ prompt, model, //response: "base64" }) }).then((response) => { response.text().then((data) => { const modData = JSON.parse(data.slice(data.indexOf('{'))); const images = modData.images; const imageNode = document.createElement('img'); imageNode.className = 'image'; imageNode.src = images[0]; responseCallback({ data, modData, images, image: images[0], imageNode }); successCallback({ data, modData, images, image: images[0], imageNode }); }).catch((err) => { errorCallback({ message: `Ошибка в функции requestAI (type: image): ${err}`, err }); }); }).catch((err) => { errorCallback({ message: `Ошибка в функции requestAI (type: image): ${err}`, err }); }); } } // Initial Language Setup switchLanguage('ru'); </script> </body> </html>В этом коде:
- Блок с ID
continue-containerпервоначально скрыт и появляется после анимации ввода текста. - После продолжения истории, этот блок исчезает до завершения анимации вывода текста.
- Добавлен элемент
#home-buttonс иконкой домика, перемещенный в левый верхний угол.
- Блок с ID