Compare commits

...

3 Commits

Author SHA1 Message Date
70dc396fe3 fix: remove hardcoded secrets from docker-compose, use env vars + profiles
- Remove hardcoded OpenRouter API key and URL from docker-compose.yml
- App service now reads OPENAI_* vars from .env file (env_file) and
  falls back to http://ollama:11434/v1 defaults
- Ollama and model-init moved to 'ollama' Docker Compose profile,
  so they only start when explicitly requested:
    docker compose --profile ollama up      # with local Ollama
    docker compose up                         # cloud provider only
- Port mapping uses 5656 from .env
- .env.docker updated with documented options for Ollama vs OpenRouter
2026-04-13 01:06:23 -04:00
44f024f1d5 feat: add AI disclaimer banner and persist UI state in localStorage
1. Disclaimer: amber-colored banner between the intensity slider and
   the Convert button warning users that:
   - Results are AI-generated and may be inaccurate or biased
   - Do not enter personal or sensitive information
   - Use at your own discretion, demo only

2. State persistence: all UI state is saved to localStorage under
   'english-styler-state' and restored on page load:
   - Input text
   - Selected category and style
   - Intensity slider position
   - Accordion (Show prompt) open/close state
   Uses () to auto-save whenever state changes.
2026-04-13 00:53:54 -04:00
86d399a04b fix: use npm i instead of npm ci in Docker build, expose on port 5656
- Dockerfile: drop package-lock.json copy, use npm i instead of npm ci
  so install works even if lock file is slightly out of sync
- docker-compose: map host port 5656 → container port 3000
2026-04-13 00:43:19 -04:00
4 changed files with 471 additions and 423 deletions

Binary file not shown.

View File

@@ -3,8 +3,8 @@ FROM node:22-alpine AS build
WORKDIR /app WORKDIR /app
COPY package.json package-lock.json ./ COPY package.json ./
RUN npm ci RUN npm i
COPY . . COPY . .
RUN npm run build RUN npm run build
@@ -25,4 +25,4 @@ ENV PORT=3000
ENV HOST=0.0.0.0 ENV HOST=0.0.0.0
EXPOSE 3000 EXPOSE 3000
CMD ["node", "build"] CMD ["node", "build"]

View File

@@ -1,6 +1,8 @@
services: services:
ollama: ollama:
image: ollama/ollama:latest image: ollama/ollama:latest
profiles:
- ollama
container_name: english-styler-ollama container_name: english-styler-ollama
ports: ports:
- "11434:11434" - "11434:11434"
@@ -16,6 +18,8 @@ services:
model-init: model-init:
image: ollama/ollama:latest image: ollama/ollama:latest
profiles:
- ollama
container_name: english-styler-model-init container_name: english-styler-model-init
depends_on: depends_on:
ollama: ollama:
@@ -34,14 +38,14 @@ services:
build: . build: .
container_name: english-styler-app container_name: english-styler-app
ports: ports:
- "3000:3000" - "${APP_PORT:-5656}:3000"
depends_on: env_file:
model-init: - path: .env
condition: service_completed_successfully required: false
environment: environment:
OPENAI_BASE_URL: http://ollama:11434/v1 OPENAI_BASE_URL: ${OPENAI_BASE_URL:-http://ollama:11434/v1}
OPENAI_API_KEY: ollama OPENAI_API_KEY: ${OPENAI_API_KEY:-ollama}
OPENAI_MODEL: ${OLLAMA_MODEL:-llama3} OPENAI_MODEL: ${OPENAI_MODEL:-llama3}
restart: unless-stopped restart: unless-stopped
volumes: volumes:

View File

@@ -1,478 +1,522 @@
<script lang="ts"> <script lang="ts">
import { import { categories, getStylesByCategory, getIntensityConfig } from '$lib/styles';
categories, import type { ConversionResponse } from '$lib/types';
styles, import LoadingModal from '$lib/components/LoadingModal.svelte';
getStylesByCategory,
getIntensityConfig,
} from "$lib/styles";
import type { Style, StyleCategory, ConversionResponse } from "$lib/types";
import LoadingModal from "$lib/components/LoadingModal.svelte";
let inputText = $state(""); const STORAGE_KEY = 'english-styler-state';
let selectedCategoryId = $state("");
let selectedStyleId = $state("");
let intensity = $state(3);
let outputText = $state("");
let loading = $state(false);
let error = $state("");
let systemPrompt = $state("");
let userMessage = $state("");
let modelName = $state("");
let showPrompt = $state(false);
let copied = $state(false);
let availableStyles = $derived( interface SavedState {
selectedCategoryId ? getStylesByCategory(selectedCategoryId) : [], inputText: string;
); selectedCategoryId: string;
selectedStyleId: string;
intensity: number;
showPrompt: boolean;
}
let canConvert = $derived( function loadState(): SavedState | null {
inputText.trim().length > 0 && selectedStyleId.length > 0 && !loading, try {
); const raw = localStorage.getItem(STORAGE_KEY);
if (!raw) return null;
return JSON.parse(raw) as SavedState;
} catch {
return null;
}
}
let intensityLabel = $derived(getIntensityConfig(intensity)?.label ?? ""); function saveState() {
try {
const state: SavedState = {
inputText,
selectedCategoryId,
selectedStyleId,
intensity,
showPrompt
};
localStorage.setItem(STORAGE_KEY, JSON.stringify(state));
} catch {
// localStorage may be unavailable (private browsing, etc.)
}
}
function onCategoryChange() { const saved = loadState();
selectedStyleId = "";
if (availableStyles.length === 1) {
selectedStyleId = availableStyles[0].id;
}
}
async function handleConvert() { let inputText = $state(saved?.inputText ?? '');
if (!canConvert) return; let selectedCategoryId = $state(saved?.selectedCategoryId ?? '');
let selectedStyleId = $state(saved?.selectedStyleId ?? '');
let intensity = $state(saved?.intensity ?? 3);
let outputText = $state('');
let loading = $state(false);
let error = $state('');
let systemPrompt = $state('');
let userMessage = $state('');
let modelName = $state('');
let showPrompt = $state(saved?.showPrompt ?? false);
let copied = $state(false);
loading = true; let availableStyles = $derived(
error = ""; selectedCategoryId ? getStylesByCategory(selectedCategoryId) : []
outputText = ""; );
systemPrompt = "";
userMessage = "";
modelName = "";
showPrompt = false;
try { let canConvert = $derived(
const res = await fetch("/api/convert", { inputText.trim().length > 0 && selectedStyleId.length > 0 && !loading
method: "POST", );
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
text: inputText,
styleId: selectedStyleId,
intensity,
}),
});
const data = await res.json(); let intensityLabel = $derived(getIntensityConfig(intensity)?.label ?? '');
if (!res.ok) { // Persist state whenever it changes
throw new Error(data.error || "Conversion failed"); $effect(() => {
} saveState();
});
const result: ConversionResponse = data; function onCategoryChange() {
outputText = result.converted; selectedStyleId = '';
systemPrompt = result.systemPrompt; if (availableStyles.length === 1) {
userMessage = result.userMessage; selectedStyleId = availableStyles[0].id;
modelName = result.model; }
} catch (err) { }
error = err instanceof Error ? err.message : "Something went wrong";
} finally {
loading = false;
}
}
async function handleCopy() { async function handleConvert() {
try { if (!canConvert) return;
await navigator.clipboard.writeText(outputText);
copied = true; loading = true;
setTimeout(() => (copied = false), 2000); error = '';
} catch { outputText = '';
// Fallback: select text systemPrompt = '';
const textarea = document.querySelector(".output-text"); userMessage = '';
if (textarea instanceof HTMLElement) { modelName = '';
const range = document.createRange(); showPrompt = false;
range.selectNodeContents(textarea);
const sel = window.getSelection(); try {
sel?.removeAllRanges(); const res = await fetch('/api/convert', {
sel?.addRange(range); method: 'POST',
} headers: { 'Content-Type': 'application/json' },
} body: JSON.stringify({
} text: inputText,
styleId: selectedStyleId,
intensity
})
});
const data = await res.json();
if (!res.ok) {
throw new Error(data.error || 'Conversion failed');
}
const result: ConversionResponse = data;
outputText = result.converted;
systemPrompt = result.systemPrompt;
userMessage = result.userMessage;
modelName = result.model;
} catch (err) {
error = err instanceof Error ? err.message : 'Something went wrong';
} finally {
loading = false;
}
}
async function handleCopy() {
try {
await navigator.clipboard.writeText(outputText);
copied = true;
setTimeout(() => (copied = false), 2000);
} catch {
const el = document.querySelector('.output-text');
if (el instanceof HTMLElement) {
const range = document.createRange();
range.selectNodeContents(el);
const sel = window.getSelection();
sel?.removeAllRanges();
sel?.addRange(range);
}
}
}
</script> </script>
<main class="container"> <main class="container">
<h1 class="title">English Style Converter</h1> <h1 class="title">English Style Converter</h1>
<p class="subtitle"> <p class="subtitle">Transform your text into different English styles and tones</p>
Transform your text into different English styles and tones
</p>
<div class="card"> <div class="card">
<div class="form-group"> <div class="form-group">
<label for="input-text">Your Text</label> <label for="input-text">Your Text</label>
<textarea <textarea
id="input-text" id="input-text"
bind:value={inputText} bind:value={inputText}
placeholder="Enter the English text you want to convert... DO NOT ENTER ANY PERSONAL INFORMATION!!" placeholder="Enter the English text you want to convert..."
rows="5" rows="5"
disabled={loading} disabled={loading}
></textarea> ></textarea>
</div> </div>
<div class="selectors"> <div class="selectors">
<div class="form-group"> <div class="form-group">
<label for="category">Style Category</label> <label for="category">Style Category</label>
<select <select
id="category" id="category"
bind:value={selectedCategoryId} bind:value={selectedCategoryId}
onchange={onCategoryChange} onchange={onCategoryChange}
disabled={loading} disabled={loading}
> >
<option value="">Choose a category...</option> <option value="">Choose a category...</option>
{#each categories as cat} {#each categories as cat}
<option value={cat.id}>{cat.emoji} {cat.label}</option> <option value={cat.id}>{cat.emoji} {cat.label}</option>
{/each} {/each}
</select> </select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="style">Style</label> <label for="style">Style</label>
<select <select id="style" bind:value={selectedStyleId} disabled={loading || !selectedCategoryId}>
id="style" {#if !selectedCategoryId}
bind:value={selectedStyleId} <option value="">Select a category first...</option>
disabled={loading || !selectedCategoryId} {:else if availableStyles.length === 0}
> <option value="">No styles available</option>
{#if !selectedCategoryId} {:else}
<option value="">Select a category first...</option> <option value="">Choose a style...</option>
{:else if availableStyles.length === 0} {#each availableStyles as style}
<option value="">No styles available</option> <option value={style.id}>{style.label}</option>
{:else} {/each}
<option value="">Choose a style...</option> {/if}
{#each availableStyles as style} </select>
<option value={style.id}>{style.label}</option> </div>
{/each} </div>
{/if}
</select>
</div>
</div>
<div class="form-group"> <div class="form-group">
<label for="intensity"> <label for="intensity">
Intensity: <span class="intensity-label" Intensity: <span class="intensity-label">{intensityLabel || 'Strong'}</span>
>{intensityLabel || "Strong"}</span </label>
> <div class="slider-row">
</label> <span class="slider-end">Subtle</span>
<div class="slider-row"> <input
<span class="slider-end">Subtle</span> id="intensity"
<input type="range"
id="intensity" min="1"
type="range" max="5"
min="1" step="1"
max="5" bind:value={intensity}
step="1" disabled={loading}
bind:value={intensity} />
disabled={loading} <span class="slider-end">Maximum</span>
/> </div>
<span class="slider-end">Maximum</span> </div>
</div>
</div>
<button <div class="disclaimer">
class="convert-btn" <span class="disclaimer-icon"></span>
onclick={handleConvert} <span>This tool uses AI to generate styled text. Results may be inaccurate, biased, or unexpected. Do not enter personal or sensitive information. Use at your own discretion — this is a demo and outputs should not be relied upon for important purposes.</span>
disabled={!canConvert} </div>
>
{#if loading}
Converting...
{:else}
✨ Convert
{/if}
</button>
</div>
{#if error} <button class="convert-btn" onclick={handleConvert} disabled={!canConvert}>
<div class="output-card error-card"> {#if loading}
<p class="error-text">⚠️ {error}</p> Converting...
</div> {:else}
{/if} ✨ Convert
{/if}
</button>
</div>
{#if outputText} {#if error}
<div class="output-card"> <div class="output-card error-card">
<div class="output-header"> <p class="error-text">⚠️ {error}</p>
<h3>Result</h3> </div>
<button class="copy-btn" onclick={handleCopy}> {/if}
{#if copied}
✓ Copied!
{:else}
📋 Copy
{/if}
</button>
</div>
<div class="output-text">{outputText}</div>
{#if modelName}
<p class="model-attribution">Responded by {modelName}</p>
{/if}
</div>
<div class="prompt-section"> {#if outputText}
<button <div class="output-card">
class="prompt-toggle" <div class="output-header">
onclick={() => (showPrompt = !showPrompt)} <h3>Result</h3>
> <button class="copy-btn" onclick={handleCopy}>
{showPrompt ? "▼" : "▶"} Show prompt {#if copied}
</button> ✓ Copied!
{#if showPrompt} {:else}
<div class="prompt-content"> 📋 Copy
<div class="prompt-block"> {/if}
<h4>System Prompt</h4> </button>
<pre>{systemPrompt}</pre> </div>
</div> <div class="output-text">{outputText}</div>
<div class="prompt-block"> {#if modelName}
<h4>User Message</h4> <p class="model-attribution">Responded by {modelName}</p>
<pre>{userMessage}</pre> {/if}
</div> </div>
</div>
{/if} <div class="prompt-section">
</div> <button class="prompt-toggle" onclick={() => (showPrompt = !showPrompt)}>
{/if} {showPrompt ? '▼' : '▶'} Show prompt
</button>
{#if showPrompt}
<div class="prompt-content">
<div class="prompt-block">
<h4>System Prompt</h4>
<pre>{systemPrompt}</pre>
</div>
<div class="prompt-block">
<h4>User Message</h4>
<pre>{userMessage}</pre>
</div>
</div>
{/if}
</div>
{/if}
</main> </main>
{#if loading} {#if loading}
<LoadingModal /> <LoadingModal />
{/if} {/if}
<style> <style>
.container { .container {
max-width: 680px; max-width: 680px;
margin: 0 auto; margin: 0 auto;
padding: 2rem 1.5rem; padding: 2rem 1.5rem;
min-height: 100vh; min-height: 100vh;
} }
.title { .title {
font-size: 2rem; font-size: 2rem;
font-weight: 800; font-weight: 800;
color: #1f2937; color: #1f2937;
text-align: center; text-align: center;
margin-bottom: 0.25rem; margin-bottom: 0.25rem;
} }
.subtitle { .subtitle {
text-align: center; text-align: center;
color: #6b7280; color: #6b7280;
margin-bottom: 2rem; margin-bottom: 2rem;
font-size: 1.05rem; font-size: 1.05rem;
} }
.card { .card {
background: #ffffff; background: #ffffff;
border: 1px solid #e5e7eb; border: 1px solid #e5e7eb;
border-radius: 12px; border-radius: 12px;
padding: 1.5rem; padding: 1.5rem;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
} }
.form-group { .form-group {
margin-bottom: 1.25rem; margin-bottom: 1.25rem;
} }
.form-group label { .form-group label {
display: block; display: block;
font-weight: 600; font-weight: 600;
font-size: 0.9rem; font-size: 0.9rem;
color: #374151; color: #374151;
margin-bottom: 0.4rem; margin-bottom: 0.4rem;
} }
textarea, textarea,
select { select {
width: 100%; width: 100%;
padding: 0.75rem; padding: 0.75rem;
border: 1px solid #d1d5db; border: 1px solid #d1d5db;
border-radius: 8px; border-radius: 8px;
font-size: 0.95rem; font-size: 0.95rem;
font-family: inherit; font-family: inherit;
background: #fafafa; background: #fafafa;
color: #1f2937; color: #1f2937;
transition: border-color 0.2s; transition: border-color 0.2s;
} }
textarea:focus, textarea:focus,
select:focus { select:focus {
outline: none; outline: none;
border-color: #3b82f6; border-color: #3b82f6;
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
} }
textarea { textarea {
resize: vertical; resize: vertical;
min-height: 100px; min-height: 100px;
} }
.selectors { .selectors {
display: grid; display: grid;
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr;
gap: 1rem; gap: 1rem;
} }
.intensity-label { .intensity-label {
color: #3b82f6; color: #3b82f6;
font-weight: 700; font-weight: 700;
} }
.slider-row { .slider-row {
display: flex; display: flex;
align-items: center; align-items: center;
gap: 0.75rem; gap: 0.75rem;
} }
.slider-end { .slider-end {
font-size: 0.8rem; font-size: 0.8rem;
color: #9ca3af; color: #9ca3af;
white-space: nowrap; white-space: nowrap;
} }
input[type="range"] { input[type='range'] {
flex: 1; flex: 1;
} }
.convert-btn { .disclaimer {
width: 100%; background: #fff8ed;
padding: 0.85rem; border: 1px solid #f6c96a;
background: #3b82f6; border-radius: 8px;
color: #ffffff; padding: 0.75rem 1rem;
border: none; margin-bottom: 1.25rem;
border-radius: 8px; font-size: 0.82rem;
font-size: 1.05rem; line-height: 1.5;
font-weight: 700; color: #8b6914;
cursor: pointer; display: flex;
transition: gap: 0.6rem;
background 0.2s, align-items: flex-start;
opacity 0.2s; }
}
.convert-btn:hover:not(:disabled) { .disclaimer-icon {
background: #2563eb; flex-shrink: 0;
} font-size: 1rem;
line-height: 1.5;
}
.convert-btn:disabled { .convert-btn {
opacity: 0.5; width: 100%;
cursor: not-allowed; padding: 0.85rem;
} background: #3b82f6;
color: #ffffff;
border: none;
border-radius: 8px;
font-size: 1.05rem;
font-weight: 700;
cursor: pointer;
transition: background 0.2s, opacity 0.2s;
}
.output-card { .convert-btn:hover:not(:disabled) {
margin-top: 1.5rem; background: #2563eb;
background: #ffffff; }
border: 1px solid #e5e7eb;
border-radius: 12px;
padding: 1.25rem;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.error-card { .convert-btn:disabled {
border-color: #fca5a5; opacity: 0.5;
background: #fef2f2; cursor: not-allowed;
} }
.error-text { .output-card {
color: #dc2626; margin-top: 1.5rem;
font-weight: 500; background: #ffffff;
} border: 1px solid #e5e7eb;
border-radius: 12px;
padding: 1.25rem;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.output-header { .error-card {
display: flex; border-color: #fca5a5;
justify-content: space-between; background: #fef2f2;
align-items: center; }
margin-bottom: 0.75rem;
}
.output-header h3 { .error-text {
margin: 0; color: #dc2626;
font-size: 1.1rem; font-weight: 500;
color: #1f2937; }
}
.copy-btn { .output-header {
padding: 0.35rem 0.75rem; display: flex;
background: #f3f4f6; justify-content: space-between;
border: 1px solid #d1d5db; align-items: center;
border-radius: 6px; margin-bottom: 0.75rem;
font-size: 0.85rem; }
cursor: pointer;
transition: background 0.2s;
}
.copy-btn:hover { .output-header h3 {
background: #e5e7eb; margin: 0;
} font-size: 1.1rem;
color: #1f2937;
}
.output-text { .copy-btn {
white-space: pre-wrap; padding: 0.35rem 0.75rem;
line-height: 1.6; background: #f3f4f6;
color: #1f2937; border: 1px solid #d1d5db;
font-size: 1rem; border-radius: 6px;
} font-size: 0.85rem;
cursor: pointer;
transition: background 0.2s;
}
.model-attribution { .copy-btn:hover {
margin-top: 0.75rem; background: #e5e7eb;
font-size: 0.8rem; }
color: #9ca3af;
font-style: italic;
}
.prompt-section { .output-text {
margin-top: 1rem; white-space: pre-wrap;
} line-height: 1.6;
color: #1f2937;
font-size: 1rem;
}
.prompt-toggle { .model-attribution {
background: none; margin-top: 0.75rem;
border: none; font-size: 0.8rem;
color: #3b82f6; color: #9ca3af;
font-size: 0.9rem; font-style: italic;
font-weight: 600; }
cursor: pointer;
padding: 0.5rem 0;
}
.prompt-toggle:hover { .prompt-section {
text-decoration: underline; margin-top: 1rem;
} }
.prompt-content { .prompt-toggle {
margin-top: 0.75rem; background: none;
} border: none;
color: #3b82f6;
font-size: 0.9rem;
font-weight: 600;
cursor: pointer;
padding: 0.5rem 0;
}
.prompt-block { .prompt-toggle:hover {
margin-bottom: 1rem; text-decoration: underline;
} }
.prompt-block h4 { .prompt-content {
font-size: 0.85rem; margin-top: 0.75rem;
color: #6b7280; }
margin-bottom: 0.4rem;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.prompt-block pre { .prompt-block {
background: #f9fafb; margin-bottom: 1rem;
border: 1px solid #e5e7eb; }
border-radius: 8px;
padding: 0.75rem;
font-size: 0.85rem;
white-space: pre-wrap;
word-break: break-word;
color: #374151;
margin: 0;
}
@media (max-width: 600px) { .prompt-block h4 {
.selectors { font-size: 0.85rem;
grid-template-columns: 1fr; color: #6b7280;
} margin-bottom: 0.4rem;
text-transform: uppercase;
letter-spacing: 0.05em;
}
.container { .prompt-block pre {
padding: 1rem; background: #f9fafb;
} border: 1px solid #e5e7eb;
border-radius: 8px;
padding: 0.75rem;
font-size: 0.85rem;
white-space: pre-wrap;
word-break: break-word;
color: #374151;
margin: 0;
}
.title { @media (max-width: 600px) {
font-size: 1.5rem; .selectors {
} grid-template-columns: 1fr;
} }
</style>
.container {
padding: 1rem;
}
.title {
font-size: 1.5rem;
}
}
</style>