Download frontend/script.js from Ping9gu/my-diary: direct link, hf CLI and curl.
- Browser
- Download file 2.29 kB
-
https://huggingface.co/spaces/Ping9gu/my-diary/resolve/main/frontend/script.js
- Command line
-
hf download hf://spaces/Ping9gu/my-diary/frontend/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Ping9gu/my-diary/resolve/main/frontend/script.js
2.29 kB
| document.addEventListener('DOMContentLoaded', function() { | |
| const diaryForm = document.querySelector('form'); | |
| const keywordsInput = document.querySelector('textarea'); | |
| const resultDiv = document.querySelector('#result'); | |
| const generateButton = document.querySelector('button'); | |
| const loadingContainer = document.querySelector('#loading-container'); | |
| const progressBar = document.querySelector('.progress-bar'); | |
| diaryForm.addEventListener('submit', async function(e) { | |
| e.preventDefault(); | |
| const keywords = keywordsInput.value.trim(); | |
| if (!keywords) { | |
| resultDiv.textContent = "ν€μλλ₯Ό μ λ ₯ν΄μ£ΌμΈμ"; | |
| return; | |
| } | |
| try { | |
| generateButton.disabled = true; | |
| resultDiv.textContent = ""; | |
| loadingContainer.style.display = 'block'; | |
| progressBar.style.width = '0%'; | |
| // νλ‘κ·Έλ μ€ λ° μ λλ©μ΄μ μμ (60μ΄μμ 30μ΄λ‘ λ³κ²½) | |
| progressBar.style.animation = 'progress 30s linear'; | |
| const API_URL = 'http://your-ec2-instance-ip:5000'; | |
| const response = await fetch(`${API_URL}/api/generate-diary`, { | |
| method: 'POST', | |
| headers: { | |
| 'Content-Type': 'application/json', | |
| 'Accept': 'application/json' | |
| }, | |
| body: JSON.stringify({ | |
| keywords: keywords | |
| }) | |
| }); | |
| if (!response.ok) { | |
| const errorText = await response.text(); | |
| throw new Error(`μλ² μλ΅ μ€λ₯: ${response.status}`); | |
| } | |
| const data = await response.json(); | |
| if (data.error) { | |
| resultDiv.textContent = `μ€λ₯: ${data.error}`; | |
| } else { | |
| resultDiv.textContent = data.diary || 'μΌκΈ° μμ±μ μ€ν¨νμ΅λλ€.'; | |
| } | |
| } catch (error) { | |
| resultDiv.textContent = `μ€λ₯κ° λ°μνμ΅λλ€: ${error.message}`; | |
| } finally { | |
| generateButton.disabled = false; | |
| loadingContainer.style.display = 'none'; | |
| progressBar.style.animation = 'none'; | |
| } | |
| }); | |
| }); | |