Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- index.html +44 -19
- script.js +122 -0
- styles.css +212 -0
index.html
CHANGED
|
@@ -1,19 +1,44 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<meta name="description" content="AI Novel Generator - Create custom stories with AI">
|
| 7 |
+
<title>NovelCraft - AI Story Generator</title>
|
| 8 |
+
<link rel="stylesheet" href="styles.css">
|
| 9 |
+
<link href="https://fonts.googleapis.com/css2?family=Merriweather:wght@400;700&family=Open+Sans:wght@400;600&display=swap" rel="stylesheet">
|
| 10 |
+
</head>
|
| 11 |
+
<body>
|
| 12 |
+
<header>
|
| 13 |
+
<div class="container">
|
| 14 |
+
<h1>NovelCraft</h1>
|
| 15 |
+
<p>AI-Powered Story Generation</p>
|
| 16 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" class="anycoder-link">Built with anycoder</a>
|
| 17 |
+
</div>
|
| 18 |
+
</header>
|
| 19 |
+
|
| 20 |
+
<main class="container">
|
| 21 |
+
<div class="chat-container">
|
| 22 |
+
<div class="chat-history" id="chatHistory">
|
| 23 |
+
<div class="message bot-message">
|
| 24 |
+
<div class="message-content">
|
| 25 |
+
Hello! I'm your AI novel assistant. Describe the story you'd like me to generate (genre, characters, setting, etc.), and I'll create a unique novel excerpt for you!
|
| 26 |
+
</div>
|
| 27 |
+
</div>
|
| 28 |
+
</div>
|
| 29 |
+
<div class="input-area">
|
| 30 |
+
<textarea id="userInput" placeholder="Describe your novel idea..."></textarea>
|
| 31 |
+
<button id="sendButton">Generate Story</button>
|
| 32 |
+
</div>
|
| 33 |
+
</div>
|
| 34 |
+
</main>
|
| 35 |
+
|
| 36 |
+
<footer>
|
| 37 |
+
<div class="container">
|
| 38 |
+
<p>Powered by Groq's LLaMA API | NovelCraft © 2023</p>
|
| 39 |
+
</div>
|
| 40 |
+
</footer>
|
| 41 |
+
|
| 42 |
+
<script src="script.js"></script>
|
| 43 |
+
</body>
|
| 44 |
+
</html>
|
script.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// API Configuration - Replace with your actual Groq API key
|
| 2 |
+
const GROQ_API_KEY = 'YOUR_GROQ_API_KEY_HERE'; // TODO: Replace with your actual API key
|
| 3 |
+
const GROQ_API_URL = 'https://api.groq.com/openai/v1/chat/completions';
|
| 4 |
+
|
| 5 |
+
// DOM Elements
|
| 6 |
+
const chatHistory = document.getElementById('chatHistory');
|
| 7 |
+
const userInput = document.getElementById('userInput');
|
| 8 |
+
const sendButton = document.getElementById('sendButton');
|
| 9 |
+
|
| 10 |
+
// Add message to chat history
|
| 11 |
+
function addMessage(content, isUser = false) {
|
| 12 |
+
const messageDiv = document.createElement('div');
|
| 13 |
+
messageDiv.classList.add('message');
|
| 14 |
+
messageDiv.classList.add(isUser ? 'user-message' : 'bot-message');
|
| 15 |
+
|
| 16 |
+
const messageContent = document.createElement('div');
|
| 17 |
+
messageContent.classList.add('message-content');
|
| 18 |
+
messageContent.textContent = content;
|
| 19 |
+
|
| 20 |
+
messageDiv.appendChild(messageContent);
|
| 21 |
+
chatHistory.appendChild(messageDiv);
|
| 22 |
+
|
| 23 |
+
// Scroll to bottom
|
| 24 |
+
chatHistory.scrollTop = chatHistory.scrollHeight;
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
// Show loading indicator
|
| 28 |
+
function showLoading() {
|
| 29 |
+
const loadingDiv = document.createElement('div');
|
| 30 |
+
loadingDiv.classList.add('message', 'bot-message');
|
| 31 |
+
loadingDiv.id = 'loadingIndicator';
|
| 32 |
+
|
| 33 |
+
const loadingContent = document.createElement('div');
|
| 34 |
+
loadingContent.classList.add('message-content');
|
| 35 |
+
loadingContent.innerHTML = 'Generating your story... <span class="loading"></span>';
|
| 36 |
+
|
| 37 |
+
loadingDiv.appendChild(loadingContent);
|
| 38 |
+
chatHistory.appendChild(loadingDiv);
|
| 39 |
+
chatHistory.scrollTop = chatHistory.scrollHeight;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// Remove loading indicator
|
| 43 |
+
function removeLoading() {
|
| 44 |
+
const loadingIndicator = document.getElementById('loadingIndicator');
|
| 45 |
+
if (loadingIndicator) {
|
| 46 |
+
loadingIndicator.remove();
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
// Generate story using Groq API
|
| 51 |
+
async function generateStory(prompt) {
|
| 52 |
+
const systemPrompt = `You are a professional novelist specializing in creating engaging, original stories.
|
| 53 |
+
Generate a compelling novel excerpt based on the user's prompt.
|
| 54 |
+
Focus on vivid descriptions, character development, and immersive storytelling.
|
| 55 |
+
The excerpt should be 300-500 words long and written in a literary style appropriate to the genre specified.
|
| 56 |
+
Do not include any meta-commentary or disclaimers - just the story itself.`;
|
| 57 |
+
|
| 58 |
+
try {
|
| 59 |
+
const response = await fetch(GROQ_API_URL, {
|
| 60 |
+
method: 'POST',
|
| 61 |
+
headers: {
|
| 62 |
+
'Content-Type': 'application/json',
|
| 63 |
+
'Authorization': `Bearer ${GROQ_API_KEY}`
|
| 64 |
+
},
|
| 65 |
+
body: JSON.stringify({
|
| 66 |
+
model: "llama3-8b-8192", // Using LLaMA 3 8B model
|
| 67 |
+
messages: [
|
| 68 |
+
{ role: "system", content: systemPrompt },
|
| 69 |
+
{ role: "user", content: prompt }
|
| 70 |
+
],
|
| 71 |
+
temperature: 0.7,
|
| 72 |
+
max_tokens: 1000,
|
| 73 |
+
top_p: 0.9
|
| 74 |
+
})
|
| 75 |
+
});
|
| 76 |
+
|
| 77 |
+
if (!response.ok) {
|
| 78 |
+
throw new Error(`API error: ${response.status}`);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
const data = await response.json();
|
| 82 |
+
return data.choices[0].message.content;
|
| 83 |
+
} catch (error) {
|
| 84 |
+
console.error('Error generating story:', error);
|
| 85 |
+
return "I apologize, but I encountered an error while generating your story. Please try again later.";
|
| 86 |
+
}
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
// Handle send button click
|
| 90 |
+
async function handleSend() {
|
| 91 |
+
const prompt = userInput.value.trim();
|
| 92 |
+
if (!prompt) return;
|
| 93 |
+
|
| 94 |
+
// Add user message
|
| 95 |
+
addMessage(prompt, true);
|
| 96 |
+
userInput.value = '';
|
| 97 |
+
sendButton.disabled = true;
|
| 98 |
+
|
| 99 |
+
// Show loading
|
| 100 |
+
showLoading();
|
| 101 |
+
|
| 102 |
+
// Generate story
|
| 103 |
+
const story = await generateStory(prompt);
|
| 104 |
+
|
| 105 |
+
// Remove loading and add bot response
|
| 106 |
+
removeLoading();
|
| 107 |
+
addMessage(story);
|
| 108 |
+
sendButton.disabled = false;
|
| 109 |
+
userInput.focus();
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
// Event listeners
|
| 113 |
+
sendButton.addEventListener('click', handleSend);
|
| 114 |
+
userInput.addEventListener('keypress', (e) => {
|
| 115 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
| 116 |
+
e.preventDefault();
|
| 117 |
+
handleSend();
|
| 118 |
+
}
|
| 119 |
+
});
|
| 120 |
+
|
| 121 |
+
// Initialize
|
| 122 |
+
userInput.focus();
|
styles.css
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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+
* {
|
| 2 |
+
margin: 0;
|
| 3 |
+
padding: 0;
|
| 4 |
+
box-sizing: border-box;
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
body {
|
| 8 |
+
font-family: 'Open Sans', sans-serif;
|
| 9 |
+
background: linear-gradient(135deg, #f5f7fa 0%, #e4edf5 100%);
|
| 10 |
+
color: #333;
|
| 11 |
+
line-height: 1.6;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
.container {
|
| 15 |
+
width: 90%;
|
| 16 |
+
max-width: 1200px;
|
| 17 |
+
margin: 0 auto;
|
| 18 |
+
padding: 0 15px;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
header {
|
| 22 |
+
background: linear-gradient(120deg, #4b6cb7 0%, #182848 100%);
|
| 23 |
+
color: white;
|
| 24 |
+
padding: 2rem 0;
|
| 25 |
+
text-align: center;
|
| 26 |
+
position: relative;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
header h1 {
|
| 30 |
+
font-family: 'Merriweather', serif;
|
| 31 |
+
font-size: 2.8rem;
|
| 32 |
+
margin-bottom: 0.5rem;
|
| 33 |
+
text-shadow: 0 2px 4px rgba(0,0,0,0.2);
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
header p {
|
| 37 |
+
font-size: 1.2rem;
|
| 38 |
+
opacity: 0.9;
|
| 39 |
+
max-width: 600px;
|
| 40 |
+
margin: 0 auto;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
.anycoder-link {
|
| 44 |
+
position: absolute;
|
| 45 |
+
top: 15px;
|
| 46 |
+
right: 20px;
|
| 47 |
+
color: rgba(255, 255, 255, 0.8);
|
| 48 |
+
text-decoration: none;
|
| 49 |
+
font-size: 0.9rem;
|
| 50 |
+
transition: color 0.3s;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
.anycoder-link:hover {
|
| 54 |
+
color: white;
|
| 55 |
+
text-decoration: underline;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
main {
|
| 59 |
+
padding: 2rem 0;
|
| 60 |
+
min-height: 70vh;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.chat-container {
|
| 64 |
+
background: white;
|
| 65 |
+
border-radius: 16px;
|
| 66 |
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
|
| 67 |
+
overflow: hidden;
|
| 68 |
+
display: flex;
|
| 69 |
+
flex-direction: column;
|
| 70 |
+
height: 70vh;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.chat-history {
|
| 74 |
+
flex: 1;
|
| 75 |
+
padding: 20px;
|
| 76 |
+
overflow-y: auto;
|
| 77 |
+
display: flex;
|
| 78 |
+
flex-direction: column;
|
| 79 |
+
gap: 15px;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
.message {
|
| 83 |
+
max-width: 85%;
|
| 84 |
+
padding: 15px;
|
| 85 |
+
border-radius: 18px;
|
| 86 |
+
position: relative;
|
| 87 |
+
animation: fadeIn 0.3s ease-out;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
@keyframes fadeIn {
|
| 91 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 92 |
+
to { opacity: 1; transform: translateY(0); }
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
.user-message {
|
| 96 |
+
background: #e3f2fd;
|
| 97 |
+
align-self: flex-end;
|
| 98 |
+
border-bottom-right-radius: 5px;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
.bot-message {
|
| 102 |
+
background: #f0f4f8;
|
| 103 |
+
align-self: flex-start;
|
| 104 |
+
border-bottom-left-radius: 5px;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
.message-content {
|
| 108 |
+
white-space: pre-wrap;
|
| 109 |
+
word-break: break-word;
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
.input-area {
|
| 113 |
+
display: flex;
|
| 114 |
+
padding: 20px;
|
| 115 |
+
background: #f8fafc;
|
| 116 |
+
border-top: 1px solid #eaeef5;
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
#userInput {
|
| 120 |
+
flex: 1;
|
| 121 |
+
padding: 15px;
|
| 122 |
+
border: 2px solid #e2e8f0;
|
| 123 |
+
border-radius: 12px;
|
| 124 |
+
font-family: 'Open Sans', sans-serif;
|
| 125 |
+
font-size: 1rem;
|
| 126 |
+
resize: none;
|
| 127 |
+
min-height: 60px;
|
| 128 |
+
max-height: 150px;
|
| 129 |
+
transition: border-color 0.3s;
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
#userInput:focus {
|
| 133 |
+
outline: none;
|
| 134 |
+
border-color: #4b6cb7;
|
| 135 |
+
box-shadow: 0 0 0 3px rgba(75, 108, 183, 0.2);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
#sendButton {
|
| 139 |
+
background: linear-gradient(120deg, #4b6cb7 0%, #182848 100%);
|
| 140 |
+
color: white;
|
| 141 |
+
border: none;
|
| 142 |
+
border-radius: 12px;
|
| 143 |
+
padding: 0 25px;
|
| 144 |
+
margin-left: 15px;
|
| 145 |
+
font-size: 1rem;
|
| 146 |
+
font-weight: 600;
|
| 147 |
+
cursor: pointer;
|
| 148 |
+
transition: transform 0.2s, box-shadow 0.2s;
|
| 149 |
+
white-space: nowrap;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
#sendButton:hover {
|
| 153 |
+
transform: translateY(-2px);
|
| 154 |
+
box-shadow: 0 4px 12px rgba(75, 108, 183, 0.3);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
#sendButton:active {
|
| 158 |
+
transform: translateY(0);
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
#sendButton:disabled {
|
| 162 |
+
background: #cbd5e0;
|
| 163 |
+
cursor: not-allowed;
|
| 164 |
+
transform: none;
|
| 165 |
+
box-shadow: none;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
footer {
|
| 169 |
+
background: #1a202c;
|
| 170 |
+
color: #a0aec0;
|
| 171 |
+
text-align: center;
|
| 172 |
+
padding: 1.5rem 0;
|
| 173 |
+
font-size: 0.9rem;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
/* Responsive adjustments */
|
| 177 |
+
@media (max-width: 768px) {
|
| 178 |
+
header h1 {
|
| 179 |
+
font-size: 2.2rem;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
.message {
|
| 183 |
+
max-width: 90%;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
.input-area {
|
| 187 |
+
flex-direction: column;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
#sendButton {
|
| 191 |
+
margin-left: 0;
|
| 192 |
+
margin-top: 15px;
|
| 193 |
+
padding: 15px;
|
| 194 |
+
}
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
/* Loading indicator */
|
| 198 |
+
.loading {
|
| 199 |
+
display: inline-block;
|
| 200 |
+
width: 20px;
|
| 201 |
+
height: 20px;
|
| 202 |
+
border: 3px solid rgba(75, 108, 183, 0.3);
|
| 203 |
+
border-radius: 50%;
|
| 204 |
+
border-top-color: #4b6cb7;
|
| 205 |
+
animation: spin 1s ease-in-out infinite;
|
| 206 |
+
margin-left: 10px;
|
| 207 |
+
vertical-align: middle;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
@keyframes spin {
|
| 211 |
+
to { transform: rotate(360deg); }
|
| 212 |
+
}
|