|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <title>Smart CMS</title> |
| 6 | + <style> |
| 7 | + body { |
| 8 | + font-family: Arial, sans-serif; |
| 9 | + max-width: 600px; |
| 10 | + margin: 20px auto; |
| 11 | + text-align: center; |
| 12 | + } |
| 13 | + input, button, textarea { |
| 14 | + margin: 10px 0; |
| 15 | + padding: 8px; |
| 16 | + width: 100%; |
| 17 | + max-width: 500px; |
| 18 | + font-size: 16px; |
| 19 | + } |
| 20 | + button { |
| 21 | + cursor: pointer; |
| 22 | + } |
| 23 | + .output { |
| 24 | + margin-top: 20px; |
| 25 | + padding: 10px; |
| 26 | + border: 1px solid #ccc; |
| 27 | + border-radius: 5px; |
| 28 | + background: #f9f9f9; |
| 29 | + white-space: pre-wrap; |
| 30 | + display: none; |
| 31 | + } |
| 32 | + </style> |
| 33 | +</head> |
| 34 | +<body> |
| 35 | +<h1>Smart CMS</h1> |
| 36 | + |
| 37 | +<h2>Create a Story</h2> |
| 38 | +<p><em>Note: Story titles cannot contain spaces.</em></p> |
| 39 | +<input id="create-title" type="text" placeholder="Story Title"> |
| 40 | +<textarea id="create-content" placeholder="Story Content"></textarea> |
| 41 | +<button onclick="createStory()">Create Story</button> |
| 42 | + |
| 43 | +<h2>Get a Story</h2> |
| 44 | +<p><em>Note: Story titles cannot contain spaces.</em></p> |
| 45 | +<input id="get-title" type="text" placeholder="Story Title"> |
| 46 | +<button onclick="getStory()">Get Story</button> |
| 47 | + |
| 48 | +<h2>Generate a Story</h2> |
| 49 | +<button onclick="generateStory()">Generate Story</button> |
| 50 | + |
| 51 | +<div id="output" class="output"></div> |
| 52 | + |
| 53 | +<script> |
| 54 | + const API_BASE = 'http://127.0.0.1:8000'; |
| 55 | + |
| 56 | + async function createStory() { |
| 57 | + let title = document.getElementById('create-title').value.trim(); |
| 58 | + let content = document.getElementById('create-content').value; |
| 59 | + |
| 60 | + // Check for spaces in the title |
| 61 | + if (title.includes(' ')) { |
| 62 | + showOutput('Error: The story title cannot contain spaces.'); |
| 63 | + return; |
| 64 | + } |
| 65 | + |
| 66 | + if (!title || !content) { |
| 67 | + showOutput('Please enter both a title and content.'); |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + // Combine title and content with a newline separator |
| 72 | + const body = `${title}\n${content}`; |
| 73 | + |
| 74 | + try { |
| 75 | + const response = await fetch(`${API_BASE}/create`, { |
| 76 | + method: 'POST', |
| 77 | + headers: { 'Content-Type': 'text/plain' }, |
| 78 | + body: body |
| 79 | + }); |
| 80 | + |
| 81 | + const result = await response.text(); |
| 82 | + showOutput(result || 'Story created successfully.'); |
| 83 | + } catch (err) { |
| 84 | + showOutput('Error creating story.'); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + async function getStory() { |
| 89 | + let title = document.getElementById('get-title').value.trim(); |
| 90 | + |
| 91 | + // Check for spaces in the title |
| 92 | + if (title.includes(' ')) { |
| 93 | + showOutput('Error: The story title cannot contain spaces.'); |
| 94 | + return; |
| 95 | + } |
| 96 | + |
| 97 | + if (!title) { |
| 98 | + showOutput('Please enter a title.'); |
| 99 | + return; |
| 100 | + } |
| 101 | + |
| 102 | + try { |
| 103 | + const response = await fetch(`${API_BASE}/retrieve`, { |
| 104 | + method: 'POST', |
| 105 | + headers: { 'Content-Type': 'text/plain' }, |
| 106 | + body: title |
| 107 | + }); |
| 108 | + |
| 109 | + const result = await response.text(); |
| 110 | + |
| 111 | + if (result === 'Story not found') { |
| 112 | + showOutput(result); |
| 113 | + return; |
| 114 | + } |
| 115 | + |
| 116 | + showOutput(`Title: ${title}\n\n${result}`); |
| 117 | + } catch (err) { |
| 118 | + showOutput('Error retrieving story.'); |
| 119 | + } |
| 120 | + } |
| 121 | + |
| 122 | + async function generateStory() { |
| 123 | + try { |
| 124 | + const response = await fetch(`${API_BASE}/generate`, { |
| 125 | + method: 'GET', |
| 126 | + }); |
| 127 | + |
| 128 | + const result = await response.text(); |
| 129 | + |
| 130 | + // Split the result into lines |
| 131 | + const lines = result.split('\n'); |
| 132 | + const title = lines[0]; |
| 133 | + const content = lines.slice(1).join('\n'); |
| 134 | + |
| 135 | + showOutput(`Title: ${title}\n\n${content}`); |
| 136 | + } catch (err) { |
| 137 | + showOutput('Error generating story.'); |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + function showOutput(message) { |
| 142 | + const output = document.getElementById('output'); |
| 143 | + output.textContent = message; |
| 144 | + output.style.display = 'block'; |
| 145 | + } |
| 146 | +</script> |
| 147 | +</body> |
| 148 | +</html> |
0 commit comments