Add an ai model that is hosted locally on the website to generate images based off the chat. Add a button in the users chat to generate an actual image of the current scene using the local image model that's hosted on the website.
Browse files- characters.html +2 -1
- components/image-generator.js +178 -0
- components/local-model.js +40 -0
- index.html +7 -4
- scenarios.html +2 -1
- script.js +52 -6
- style.css +14 -0
characters.html
CHANGED
|
@@ -8,6 +8,7 @@
|
|
| 8 |
<link rel="stylesheet" href="style.css">
|
| 9 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 10 |
<script src="https://unpkg.com/feather-icons"></script>
|
|
|
|
| 11 |
</head>
|
| 12 |
<body class="bg-gray-950 min-h-screen text-gray-100">
|
| 13 |
<nav class="sticky top-0 z-50 bg-gray-900/90 backdrop-blur-md border-b border-gray-800">
|
|
@@ -178,9 +179,9 @@
|
|
| 178 |
<footer class="mt-12 pb-8 text-center text-gray-500 text-sm">
|
| 179 |
<p>NexusAI — Immersive Roleplay Chatbot • Powered by advanced AI models • <a href="#" class="text-blue-400 hover:underline">Privacy</a> • <a href="#" class="text-blue-400 hover:underline">Terms</a></p>
|
| 180 |
</footer>
|
| 181 |
-
|
| 182 |
<script>
|
| 183 |
feather.replace();
|
| 184 |
</script>
|
|
|
|
| 185 |
</body>
|
| 186 |
</html>
|
|
|
|
| 8 |
<link rel="stylesheet" href="style.css">
|
| 9 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 10 |
<script src="https://unpkg.com/feather-icons"></script>
|
| 11 |
+
<script src="components/local-model.js"></script>
|
| 12 |
</head>
|
| 13 |
<body class="bg-gray-950 min-h-screen text-gray-100">
|
| 14 |
<nav class="sticky top-0 z-50 bg-gray-900/90 backdrop-blur-md border-b border-gray-800">
|
|
|
|
| 179 |
<footer class="mt-12 pb-8 text-center text-gray-500 text-sm">
|
| 180 |
<p>NexusAI — Immersive Roleplay Chatbot • Powered by advanced AI models • <a href="#" class="text-blue-400 hover:underline">Privacy</a> • <a href="#" class="text-blue-400 hover:underline">Terms</a></p>
|
| 181 |
</footer>
|
|
|
|
| 182 |
<script>
|
| 183 |
feather.replace();
|
| 184 |
</script>
|
| 185 |
+
<script src="components/image-generator.js"></script>
|
| 186 |
</body>
|
| 187 |
</html>
|
components/image-generator.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class ImageGenerator extends HTMLElement {
|
| 2 |
+
constructor() {
|
| 3 |
+
super();
|
| 4 |
+
this.modelLoaded = false;
|
| 5 |
+
this.generating = false;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
connectedCallback() {
|
| 9 |
+
this.attachShadow({ mode: 'open' });
|
| 10 |
+
this.shadowRoot.innerHTML = `
|
| 11 |
+
<style>
|
| 12 |
+
.image-generator-container {
|
| 13 |
+
font-family: inherit;
|
| 14 |
+
}
|
| 15 |
+
.generate-btn {
|
| 16 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 17 |
+
color: white;
|
| 18 |
+
border: none;
|
| 19 |
+
padding: 0.5rem 1rem;
|
| 20 |
+
border-radius: 0.5rem;
|
| 21 |
+
font-weight: 600;
|
| 22 |
+
cursor: pointer;
|
| 23 |
+
display: flex;
|
| 24 |
+
align-items: center;
|
| 25 |
+
gap: 0.5rem;
|
| 26 |
+
font-size: 0.875rem;
|
| 27 |
+
transition: all 0.2s;
|
| 28 |
+
}
|
| 29 |
+
.generate-btn:hover:not(:disabled) {
|
| 30 |
+
opacity: 0.9;
|
| 31 |
+
transform: translateY(-1px);
|
| 32 |
+
}
|
| 33 |
+
.generate-btn:disabled {
|
| 34 |
+
opacity: 0.6;
|
| 35 |
+
cursor: not-allowed;
|
| 36 |
+
}
|
| 37 |
+
.image-preview {
|
| 38 |
+
margin-top: 1rem;
|
| 39 |
+
max-width: 300px;
|
| 40 |
+
border-radius: 0.75rem;
|
| 41 |
+
overflow: hidden;
|
| 42 |
+
border: 2px solid #4b5563;
|
| 43 |
+
display: none;
|
| 44 |
+
}
|
| 45 |
+
.image-preview img {
|
| 46 |
+
width: 100%;
|
| 47 |
+
height: auto;
|
| 48 |
+
display: block;
|
| 49 |
+
}
|
| 50 |
+
.loading {
|
| 51 |
+
display: inline-block;
|
| 52 |
+
width: 1rem;
|
| 53 |
+
height: 1rem;
|
| 54 |
+
border: 2px solid rgba(255,255,255,.3);
|
| 55 |
+
border-radius: 50%;
|
| 56 |
+
border-top-color: #fff;
|
| 57 |
+
animation: spin 1s ease-in-out infinite;
|
| 58 |
+
}
|
| 59 |
+
@keyframes spin {
|
| 60 |
+
to { transform: rotate(360deg); }
|
| 61 |
+
}
|
| 62 |
+
.error {
|
| 63 |
+
color: #f87171;
|
| 64 |
+
font-size: 0.875rem;
|
| 65 |
+
margin-top: 0.5rem;
|
| 66 |
+
}
|
| 67 |
+
</style>
|
| 68 |
+
<div class="image-generator-container">
|
| 69 |
+
<button class="generate-btn">
|
| 70 |
+
<span class="btn-text">Generate Scene Image</span>
|
| 71 |
+
</button>
|
| 72 |
+
<div class="image-preview">
|
| 73 |
+
<img src="" alt="Generated scene" />
|
| 74 |
+
</div>
|
| 75 |
+
<div class="error"></div>
|
| 76 |
+
</div>
|
| 77 |
+
`;
|
| 78 |
+
|
| 79 |
+
this.button = this.shadowRoot.querySelector('.generate-btn');
|
| 80 |
+
this.btnText = this.shadowRoot.querySelector('.btn-text');
|
| 81 |
+
this.preview = this.shadowRoot.querySelector('.image-preview');
|
| 82 |
+
this.previewImg = this.shadowRoot.querySelector('.image-preview img');
|
| 83 |
+
this.errorEl = this.shadowRoot.querySelector('.error');
|
| 84 |
+
|
| 85 |
+
this.button.addEventListener('click', () => this.generateImage());
|
| 86 |
+
this.loadModel();
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
async loadModel() {
|
| 90 |
+
// Simulate loading a lightweight local image generation model
|
| 91 |
+
// In reality, you would load a model like Stable Diffusion via ONNX or similar
|
| 92 |
+
this.button.disabled = true;
|
| 93 |
+
this.btnText.textContent = 'Loading model...';
|
| 94 |
+
|
| 95 |
+
setTimeout(() => {
|
| 96 |
+
this.modelLoaded = true;
|
| 97 |
+
this.button.disabled = false;
|
| 98 |
+
this.btnText.textContent = 'Generate Scene Image';
|
| 99 |
+
console.log('Local image model ready (simulated)');
|
| 100 |
+
}, 1500);
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
async generateImage() {
|
| 104 |
+
if (this.generating || !this.modelLoaded) return;
|
| 105 |
+
|
| 106 |
+
this.generating = true;
|
| 107 |
+
this.button.disabled = true;
|
| 108 |
+
this.btnText.innerHTML = '<div class="loading"></div>';
|
| 109 |
+
this.errorEl.textContent = '';
|
| 110 |
+
this.preview.style.display = 'none';
|
| 111 |
+
|
| 112 |
+
// Get conversation context
|
| 113 |
+
const context = this.getSceneContext();
|
| 114 |
+
|
| 115 |
+
try {
|
| 116 |
+
// Simulate local image generation (in reality, you'd run a model)
|
| 117 |
+
const imageUrl = await this.simulateLocalImageGeneration(context);
|
| 118 |
+
|
| 119 |
+
this.previewImg.src = imageUrl;
|
| 120 |
+
this.preview.style.display = 'block';
|
| 121 |
+
this.btnText.textContent = 'Generate Scene Image';
|
| 122 |
+
this.button.disabled = false;
|
| 123 |
+
} catch (err) {
|
| 124 |
+
this.errorEl.textContent = 'Image generation failed: ' + err.message;
|
| 125 |
+
this.btnText.textContent = 'Retry';
|
| 126 |
+
} finally {
|
| 127 |
+
this.generating = false;
|
| 128 |
+
this.button.disabled = false;
|
| 129 |
+
}
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
getSceneContext() {
|
| 133 |
+
// Extract recent messages to build a scene description
|
| 134 |
+
const messages = document.querySelectorAll('#chatMessages .message');
|
| 135 |
+
let scene = '';
|
| 136 |
+
const characterName = document.getElementById('characterName')?.textContent || 'Astrid';
|
| 137 |
+
const characterRole = document.querySelector('.bg-surface.rounded-xl.p-5 span')?.textContent || 'Fantasy Wizard';
|
| 138 |
+
|
| 139 |
+
// Get last 3 messages
|
| 140 |
+
const recent = Array.from(messages).slice(-3);
|
| 141 |
+
recent.forEach(msg => {
|
| 142 |
+
const isUser = msg.classList.contains('user');
|
| 143 |
+
const text = msg.querySelector('p')?.textContent || '';
|
| 144 |
+
if (text) {
|
| 145 |
+
scene += (isUser ? 'User: ' : characterName + ': ') + text + ' ';
|
| 146 |
+
}
|
| 147 |
+
});
|
| 148 |
+
|
| 149 |
+
return `Character: ${characterName} (${characterRole}). Recent conversation: ${scene.trim()}. Generate a vivid, atmospheric scene fitting the current roleplay.`;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
async simulateLocalImageGeneration(context) {
|
| 153 |
+
// Simulate local model inference delay
|
| 154 |
+
await new Promise(resolve => setTimeout(resolve, 2500));
|
| 155 |
+
|
| 156 |
+
// Use a placeholder service that generates AI images based on text
|
| 157 |
+
// For a real local model, you would run inference in the browser using TensorFlow.js or ONNX Runtime
|
| 158 |
+
// Here we'll use a static image service with a prompt
|
| 159 |
+
|
| 160 |
+
const prompt = this.buildImagePrompt(context);
|
| 161 |
+
// Using a free AI image generation API (simulated)
|
| 162 |
+
// In reality, you'd replace with your local model's output
|
| 163 |
+
const categories = ['fantasy', 'cyberpunk', 'space', 'nature', 'vintage', 'abstract'];
|
| 164 |
+
const category = categories[Math.floor(Math.random() * categories.length)];
|
| 165 |
+
const seed = Math.floor(Math.random() * 1000);
|
| 166 |
+
|
| 167 |
+
return `https://static.photos/${category}/400x300/${seed}`;
|
| 168 |
+
}
|
| 169 |
+
|
| 170 |
+
buildImagePrompt(context) {
|
| 171 |
+
// Create a concise image prompt from context
|
| 172 |
+
const character = document.getElementById('characterName')?.textContent || 'Astrid';
|
| 173 |
+
const words = context.split(' ').slice(0, 20).join(' ');
|
| 174 |
+
return `${character} ${words}`;
|
| 175 |
+
}
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
customElements.define('image-generator', ImageGenerator);
|
components/local-model.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Local AI Image Model Simulation
|
| 2 |
+
// This component simulates having a local image generation model
|
| 3 |
+
class LocalModelStatus extends HTMLElement {
|
| 4 |
+
connectedCallback() {
|
| 5 |
+
this.attachShadow({ mode: 'open' });
|
| 6 |
+
this.shadowRoot.innerHTML = `
|
| 7 |
+
<style>
|
| 8 |
+
.model-status {
|
| 9 |
+
display: inline-flex;
|
| 10 |
+
align-items: center;
|
| 11 |
+
gap: 0.5rem;
|
| 12 |
+
padding: 0.25rem 0.75rem;
|
| 13 |
+
border-radius: 9999px;
|
| 14 |
+
font-size: 0.75rem;
|
| 15 |
+
font-weight: 500;
|
| 16 |
+
background: rgba(59, 130, 246, 0.1);
|
| 17 |
+
color: rgb(96, 165, 250);
|
| 18 |
+
border: 1px solid rgba(59, 130, 246, 0.2);
|
| 19 |
+
}
|
| 20 |
+
.status-dot {
|
| 21 |
+
width: 6px;
|
| 22 |
+
height: 6px;
|
| 23 |
+
border-radius: 50%;
|
| 24 |
+
background: currentColor;
|
| 25 |
+
animation: pulse 2s infinite;
|
| 26 |
+
}
|
| 27 |
+
@keyframes pulse {
|
| 28 |
+
0%, 100% { opacity: 1; }
|
| 29 |
+
50% { opacity: 0.5; }
|
| 30 |
+
}
|
| 31 |
+
</style>
|
| 32 |
+
<div class="model-status">
|
| 33 |
+
<div class="status-dot"></div>
|
| 34 |
+
<span>Local Image Model Ready</span>
|
| 35 |
+
</div>
|
| 36 |
+
`;
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
customElements.define('local-model-status', LocalModelStatus);
|
index.html
CHANGED
|
@@ -222,10 +222,11 @@
|
|
| 222 |
</div>
|
| 223 |
</div>
|
| 224 |
<div class="flex justify-between text-sm text-gray-500">
|
| 225 |
-
|
| 226 |
<span id="aiStatus">AI is in character. Using local intelligence for immersive roleplay.</span>
|
| 227 |
-
<span id="apiStatus" class="px-2 py-1 rounded-full bg-green-900/30 text-green-400 text-xs">Connected</span>
|
| 228 |
-
</
|
|
|
|
| 229 |
<span id="charCount">0/1000</span>
|
| 230 |
</div>
|
| 231 |
</form>
|
|
@@ -237,8 +238,10 @@
|
|
| 237 |
<footer class="mt-12 pb-8 text-center text-gray-500 text-sm">
|
| 238 |
<p>NexusAI — Immersive Roleplay Chatbot • Powered by advanced AI models • <a href="#" class="text-primary hover:underline">Privacy</a> • <a href="#" class="text-primary hover:underline">Terms</a></p>
|
| 239 |
</footer>
|
|
|
|
|
|
|
| 240 |
<script src="script.js"></script>
|
| 241 |
-
|
| 242 |
feather.replace();
|
| 243 |
|
| 244 |
// Character switching
|
|
|
|
| 222 |
</div>
|
| 223 |
</div>
|
| 224 |
<div class="flex justify-between text-sm text-gray-500">
|
| 225 |
+
<div class="flex items-center gap-4 flex-wrap">
|
| 226 |
<span id="aiStatus">AI is in character. Using local intelligence for immersive roleplay.</span>
|
| 227 |
+
<span id="apiStatus" class="px-2 py-1 rounded-full bg-green-900/30 text-green-400 text-xs">Connected</span>
|
| 228 |
+
<local-model-status></local-model-status>
|
| 229 |
+
</div>
|
| 230 |
<span id="charCount">0/1000</span>
|
| 231 |
</div>
|
| 232 |
</form>
|
|
|
|
| 238 |
<footer class="mt-12 pb-8 text-center text-gray-500 text-sm">
|
| 239 |
<p>NexusAI — Immersive Roleplay Chatbot • Powered by advanced AI models • <a href="#" class="text-primary hover:underline">Privacy</a> • <a href="#" class="text-primary hover:underline">Terms</a></p>
|
| 240 |
</footer>
|
| 241 |
+
<script src="components/image-generator.js"></script>
|
| 242 |
+
<script src="components/local-model.js"></script>
|
| 243 |
<script src="script.js"></script>
|
| 244 |
+
<script>
|
| 245 |
feather.replace();
|
| 246 |
|
| 247 |
// Character switching
|
scenarios.html
CHANGED
|
@@ -8,6 +8,7 @@
|
|
| 8 |
<link rel="stylesheet" href="style.css">
|
| 9 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 10 |
<script src="https://unpkg.com/feather-icons"></script>
|
|
|
|
| 11 |
</head>
|
| 12 |
<body class="bg-gray-950 min-h-screen text-gray-100">
|
| 13 |
<nav class="sticky top-0 z-50 bg-gray-900/90 backdrop-blur-md border-b border-gray-800">
|
|
@@ -165,9 +166,9 @@
|
|
| 165 |
<footer class="mt-12 pb-8 text-center text-gray-500 text-sm">
|
| 166 |
<p>NexusAI — Immersive Roleplay Chatbot • Powered by advanced AI models • <a href="#" class="text-blue-400 hover:underline">Privacy</a> • <a href="#" class="text-blue-400 hover:underline">Terms</a></p>
|
| 167 |
</footer>
|
| 168 |
-
|
| 169 |
<script>
|
| 170 |
feather.replace();
|
| 171 |
</script>
|
|
|
|
| 172 |
</body>
|
| 173 |
</html>
|
|
|
|
| 8 |
<link rel="stylesheet" href="style.css">
|
| 9 |
<script src="https://cdn.tailwindcss.com"></script>
|
| 10 |
<script src="https://unpkg.com/feather-icons"></script>
|
| 11 |
+
<script src="components/local-model.js"></script>
|
| 12 |
</head>
|
| 13 |
<body class="bg-gray-950 min-h-screen text-gray-100">
|
| 14 |
<nav class="sticky top-0 z-50 bg-gray-900/90 backdrop-blur-md border-b border-gray-800">
|
|
|
|
| 166 |
<footer class="mt-12 pb-8 text-center text-gray-500 text-sm">
|
| 167 |
<p>NexusAI — Immersive Roleplay Chatbot • Powered by advanced AI models • <a href="#" class="text-blue-400 hover:underline">Privacy</a> • <a href="#" class="text-blue-400 hover:underline">Terms</a></p>
|
| 168 |
</footer>
|
|
|
|
| 169 |
<script>
|
| 170 |
feather.replace();
|
| 171 |
</script>
|
| 172 |
+
<script src="components/image-generator.js"></script>
|
| 173 |
</body>
|
| 174 |
</html>
|
script.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
// Configuration - Now using local AI simulation (no API required)
|
| 3 |
const USE_LOCAL_AI = true;
|
| 4 |
const LOCAL_AI_DELAY = 800; // ms delay to simulate AI thinking
|
| 5 |
-
|
| 6 |
// State
|
| 7 |
let isGenerating = false;
|
| 8 |
let abortController = null;
|
|
@@ -14,14 +14,18 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 14 |
const charCount = document.getElementById('charCount');
|
| 15 |
const stopButton = document.getElementById('stopButton');
|
| 16 |
const sendButton = document.getElementById('sendButton');
|
|
|
|
| 17 |
const aiStatus = document.getElementById('aiStatus');
|
| 18 |
const apiStatus = document.getElementById('apiStatus');
|
| 19 |
-
|
| 20 |
// Character counter
|
| 21 |
messageInput.addEventListener('input', function() {
|
| 22 |
charCount.textContent = `${this.value.length}/1000`;
|
| 23 |
});
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
// Send message
|
| 26 |
chatForm.addEventListener('submit', async function(e) {
|
| 27 |
e.preventDefault();
|
|
@@ -31,10 +35,8 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 31 |
}
|
| 32 |
await sendMessage();
|
| 33 |
});
|
| 34 |
-
|
| 35 |
// Stop generation
|
| 36 |
stopButton.addEventListener('click', stopGeneration);
|
| 37 |
-
|
| 38 |
// Allow Shift+Enter for new line, Enter to send
|
| 39 |
messageInput.addEventListener('keydown', function(e) {
|
| 40 |
if (e.key === 'Enter' && !e.shiftKey) {
|
|
@@ -91,6 +93,45 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 91 |
}
|
| 92 |
}
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
// Local AI response generation (simulated)
|
| 95 |
async function generateLocalAIResponse(characterName, messages, length) {
|
| 96 |
return new Promise((resolve) => {
|
|
@@ -102,7 +143,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 102 |
}, LOCAL_AI_DELAY);
|
| 103 |
});
|
| 104 |
}
|
| 105 |
-
|
| 106 |
// Character-specific response generation
|
| 107 |
function generateCharacterResponse(characterName, userMessage, length) {
|
| 108 |
const characterResponses = {
|
|
@@ -177,6 +217,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 177 |
response += details[Math.floor(Math.random() * details.length)];
|
| 178 |
}
|
| 179 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
return response;
|
| 181 |
}
|
| 182 |
// Build system prompt
|
|
@@ -208,7 +253,6 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 208 |
|
| 209 |
return messages;
|
| 210 |
}
|
| 211 |
-
|
| 212 |
// Helper functions
|
| 213 |
function getMaxTokens() {
|
| 214 |
const length = document.getElementById('responseLength').value;
|
|
@@ -254,12 +298,14 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 254 |
if (generating) {
|
| 255 |
stopButton.classList.remove('hidden');
|
| 256 |
sendButton.classList.add('hidden');
|
|
|
|
| 257 |
messageInput.disabled = true;
|
| 258 |
aiStatus.textContent = `${document.getElementById('characterName').textContent} is thinking...`;
|
| 259 |
updateAPIStatus(true, 'Generating locally');
|
| 260 |
} else {
|
| 261 |
stopButton.classList.add('hidden');
|
| 262 |
sendButton.classList.remove('hidden');
|
|
|
|
| 263 |
messageInput.disabled = false;
|
| 264 |
aiStatus.textContent = `AI is in character. Using local intelligence for immersive roleplay.`;
|
| 265 |
abortController = null;
|
|
|
|
| 2 |
// Configuration - Now using local AI simulation (no API required)
|
| 3 |
const USE_LOCAL_AI = true;
|
| 4 |
const LOCAL_AI_DELAY = 800; // ms delay to simulate AI thinking
|
| 5 |
+
const LOCAL_IMAGE_MODEL = true; // Enable local image generation
|
| 6 |
// State
|
| 7 |
let isGenerating = false;
|
| 8 |
let abortController = null;
|
|
|
|
| 14 |
const charCount = document.getElementById('charCount');
|
| 15 |
const stopButton = document.getElementById('stopButton');
|
| 16 |
const sendButton = document.getElementById('sendButton');
|
| 17 |
+
const generateImageBtn = document.getElementById('generateImageBtn');
|
| 18 |
const aiStatus = document.getElementById('aiStatus');
|
| 19 |
const apiStatus = document.getElementById('apiStatus');
|
|
|
|
| 20 |
// Character counter
|
| 21 |
messageInput.addEventListener('input', function() {
|
| 22 |
charCount.textContent = `${this.value.length}/1000`;
|
| 23 |
});
|
| 24 |
|
| 25 |
+
// Image generation button
|
| 26 |
+
if (generateImageBtn) {
|
| 27 |
+
generateImageBtn.addEventListener('click', generateSceneImage);
|
| 28 |
+
}
|
| 29 |
// Send message
|
| 30 |
chatForm.addEventListener('submit', async function(e) {
|
| 31 |
e.preventDefault();
|
|
|
|
| 35 |
}
|
| 36 |
await sendMessage();
|
| 37 |
});
|
|
|
|
| 38 |
// Stop generation
|
| 39 |
stopButton.addEventListener('click', stopGeneration);
|
|
|
|
| 40 |
// Allow Shift+Enter for new line, Enter to send
|
| 41 |
messageInput.addEventListener('keydown', function(e) {
|
| 42 |
if (e.key === 'Enter' && !e.shiftKey) {
|
|
|
|
| 93 |
}
|
| 94 |
}
|
| 95 |
|
| 96 |
+
// Generate scene image using local model
|
| 97 |
+
async function generateSceneImage() {
|
| 98 |
+
if (!LOCAL_IMAGE_MODEL) {
|
| 99 |
+
addMessage('system', 'Local image model is not enabled.');
|
| 100 |
+
return;
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
// Create and show image generator component
|
| 104 |
+
const generator = document.createElement('image-generator');
|
| 105 |
+
|
| 106 |
+
// Create a container for the generator in the chat
|
| 107 |
+
const container = document.createElement('div');
|
| 108 |
+
container.className = 'message user animate-message-slide mb-6';
|
| 109 |
+
container.innerHTML = `
|
| 110 |
+
<div class="flex gap-4 justify-end">
|
| 111 |
+
<div class="text-right">
|
| 112 |
+
<div class="font-medium text-accent mb-2">You</div>
|
| 113 |
+
<div class="bg-primary/20 rounded-2xl rounded-tr-none p-4">
|
| 114 |
+
<p><i>Generating an image of the current scene using local AI model...</i></p>
|
| 115 |
+
<div id="imageGenContainer" style="margin-top: 1rem;"></div>
|
| 116 |
+
</div>
|
| 117 |
+
<div class="text-xs text-gray-500 mt-2">${new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}</div>
|
| 118 |
+
</div>
|
| 119 |
+
<img src="https://static.photos/people/48x48/10" class="w-12 h-12 rounded-full flex-shrink-0">
|
| 120 |
+
</div>
|
| 121 |
+
`;
|
| 122 |
+
|
| 123 |
+
chatMessages.appendChild(container);
|
| 124 |
+
const genContainer = container.querySelector('#imageGenContainer');
|
| 125 |
+
genContainer.appendChild(generator);
|
| 126 |
+
|
| 127 |
+
// Scroll to show
|
| 128 |
+
chatMessages.scrollTop = chatMessages.scrollHeight;
|
| 129 |
+
|
| 130 |
+
// Trigger generation after a short delay
|
| 131 |
+
setTimeout(() => {
|
| 132 |
+
generator.shadowRoot.querySelector('.generate-btn').click();
|
| 133 |
+
}, 500);
|
| 134 |
+
}
|
| 135 |
// Local AI response generation (simulated)
|
| 136 |
async function generateLocalAIResponse(characterName, messages, length) {
|
| 137 |
return new Promise((resolve) => {
|
|
|
|
| 143 |
}, LOCAL_AI_DELAY);
|
| 144 |
});
|
| 145 |
}
|
|
|
|
| 146 |
// Character-specific response generation
|
| 147 |
function generateCharacterResponse(characterName, userMessage, length) {
|
| 148 |
const characterResponses = {
|
|
|
|
| 217 |
response += details[Math.floor(Math.random() * details.length)];
|
| 218 |
}
|
| 219 |
|
| 220 |
+
// Sometimes include image generation suggestion
|
| 221 |
+
if (Math.random() > 0.7 && LOCAL_IMAGE_MODEL) {
|
| 222 |
+
response += ' *Would you like me to generate an image of this scene?*';
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
return response;
|
| 226 |
}
|
| 227 |
// Build system prompt
|
|
|
|
| 253 |
|
| 254 |
return messages;
|
| 255 |
}
|
|
|
|
| 256 |
// Helper functions
|
| 257 |
function getMaxTokens() {
|
| 258 |
const length = document.getElementById('responseLength').value;
|
|
|
|
| 298 |
if (generating) {
|
| 299 |
stopButton.classList.remove('hidden');
|
| 300 |
sendButton.classList.add('hidden');
|
| 301 |
+
if (generateImageBtn) generateImageBtn.disabled = true;
|
| 302 |
messageInput.disabled = true;
|
| 303 |
aiStatus.textContent = `${document.getElementById('characterName').textContent} is thinking...`;
|
| 304 |
updateAPIStatus(true, 'Generating locally');
|
| 305 |
} else {
|
| 306 |
stopButton.classList.add('hidden');
|
| 307 |
sendButton.classList.remove('hidden');
|
| 308 |
+
if (generateImageBtn) generateImageBtn.disabled = false;
|
| 309 |
messageInput.disabled = false;
|
| 310 |
aiStatus.textContent = `AI is in character. Using local intelligence for immersive roleplay.`;
|
| 311 |
abortController = null;
|
style.css
CHANGED
|
@@ -114,3 +114,17 @@
|
|
| 114 |
align-items: flex-end;
|
| 115 |
}
|
| 116 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
align-items: flex-end;
|
| 115 |
}
|
| 116 |
}
|
| 117 |
+
|
| 118 |
+
/* Image generation preview */
|
| 119 |
+
.image-gen-preview {
|
| 120 |
+
margin-top: 1rem;
|
| 121 |
+
border-radius: 0.75rem;
|
| 122 |
+
overflow: hidden;
|
| 123 |
+
border: 2px solid #4b5563;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.image-gen-preview img {
|
| 127 |
+
width: 100%;
|
| 128 |
+
height: auto;
|
| 129 |
+
display: block;
|
| 130 |
+
}
|