dmartincy commited on
Commit
d4f99c0
·
1 Parent(s): 403c243

Some polishing

Browse files
Files changed (3) hide show
  1. document-authoring.js +22 -9
  2. index.html +24 -27
  3. nginx.conf +9 -5
document-authoring.js CHANGED
@@ -2,7 +2,17 @@
2
  const app = document.getElementById('app');
3
  app.innerHTML = `
4
  <div style="max-width: 1024px; margin: 0 auto; padding: 20px;">
5
- <button id="translateButton" style="margin-bottom: 10px;" disabled class="button-disabled">Translate to Spanish</button>
 
 
 
 
 
 
 
 
 
 
6
  <div id="editor" style="border: 1px solid black; height: 600px; position: relative"></div>
7
  </div>
8
  `;
@@ -23,8 +33,8 @@ script.onload = async () => {
23
  }
24
  );
25
 
26
- // Translation function.
27
- async function translate(content, lang = "Spanish") {
28
  try {
29
  const response = await fetch('/client/api/v1/chat/completions', {
30
  method: 'POST',
@@ -59,33 +69,36 @@ script.onload = async () => {
59
  }
60
  }
61
 
62
- // Function to recursively translate text in the JSON structure.
63
- async function translateRecursive(obj) {
64
  for (let key in obj) {
65
  if (typeof obj[key] === "string" && key === "text" && obj[key].length > 0) {
66
- obj[key] = await translate(obj[key]);
67
  } else if (typeof obj[key] === "object") {
68
- await translateRecursive(obj[key]);
69
  }
70
  }
71
  }
72
 
73
  // Add translation button handler
74
  const translateButton = document.getElementById('translateButton');
 
 
75
  translateButton.addEventListener('click', async () => {
76
  try {
 
77
  translateButton.disabled = true;
78
  translateButton.innerHTML = '<span class="spinner"></span> Translating...';
79
 
80
  const jsonDoc = await editor.currentDocument().saveDocument();
81
- await translateRecursive(jsonDoc.container.document);
82
  const translatedDoc = await docAuthSystem.loadDocument(jsonDoc);
83
  editor.setCurrentDocument(translatedDoc);
84
  } catch (error) {
85
  alert('Translation failed: ' + error.message);
86
  } finally {
87
  translateButton.disabled = false;
88
- translateButton.innerHTML = 'Translate to Spanish';
89
  }
90
  });
91
  };
 
2
  const app = document.getElementById('app');
3
  app.innerHTML = `
4
  <div style="max-width: 1024px; margin: 0 auto; padding: 20px;">
5
+ <div id="statusIndicator">
6
+ <span class="spinner"></span> Services starting...
7
+ </div>
8
+ <div id="translationControls">
9
+ <select id="languageSelect">
10
+ <option value="Spanish">Spanish</option>
11
+ <option value="French">French</option>
12
+ <option value="German">German</option>
13
+ </select>
14
+ <button id="translateButton">Translate Document</button>
15
+ </div>
16
  <div id="editor" style="border: 1px solid black; height: 600px; position: relative"></div>
17
  </div>
18
  `;
 
33
  }
34
  );
35
 
36
+ // Translation function with language parameter
37
+ async function translate(content, lang) {
38
  try {
39
  const response = await fetch('/client/api/v1/chat/completions', {
40
  method: 'POST',
 
69
  }
70
  }
71
 
72
+ // Function to recursively translate text in the JSON structure
73
+ async function translateRecursive(obj, lang) {
74
  for (let key in obj) {
75
  if (typeof obj[key] === "string" && key === "text" && obj[key].length > 0) {
76
+ obj[key] = await translate(obj[key], lang);
77
  } else if (typeof obj[key] === "object") {
78
+ await translateRecursive(obj[key], lang);
79
  }
80
  }
81
  }
82
 
83
  // Add translation button handler
84
  const translateButton = document.getElementById('translateButton');
85
+ const languageSelect = document.getElementById('languageSelect');
86
+
87
  translateButton.addEventListener('click', async () => {
88
  try {
89
+ const selectedLanguage = languageSelect.value;
90
  translateButton.disabled = true;
91
  translateButton.innerHTML = '<span class="spinner"></span> Translating...';
92
 
93
  const jsonDoc = await editor.currentDocument().saveDocument();
94
+ await translateRecursive(jsonDoc.container.document, selectedLanguage);
95
  const translatedDoc = await docAuthSystem.loadDocument(jsonDoc);
96
  editor.setCurrentDocument(translatedDoc);
97
  } catch (error) {
98
  alert('Translation failed: ' + error.message);
99
  } finally {
100
  translateButton.disabled = false;
101
+ translateButton.innerHTML = 'Translate Document';
102
  }
103
  });
104
  };
index.html CHANGED
@@ -23,62 +23,59 @@
23
  100% { transform: rotate(360deg); }
24
  }
25
 
26
- #translateButton:disabled {
27
- cursor: not-allowed;
28
- opacity: 0.7;
29
  }
30
 
31
- /* Add styles for disabled state */
32
- .button-disabled {
33
- cursor: not-allowed;
34
- opacity: 0.5;
35
- pointer-events: none;
 
 
36
  }
37
 
38
- /* Add a status indicator */
39
  #statusIndicator {
40
- position: fixed;
41
- bottom: 10px;
42
- right: 10px;
43
- padding: 8px;
44
- border-radius: 4px;
45
  background: #f0f0f0;
46
- font-size: 14px;
 
 
47
  }
48
  </style>
49
  </head>
50
  <body>
51
  <div id="app"></div>
52
- <div id="statusIndicator">Services starting...</div>
53
  <script>
54
  // Add this before loading the main script
55
  window.servicesReady = false;
56
 
57
  // Create a function to check service status
58
  function checkServicesStatus() {
59
- fetch('/client/api/v1/healthcheck')
60
  .then(response => {
61
  if (response.ok) {
62
  window.servicesReady = true;
63
- const translateButton = document.getElementById('translateButton');
64
  const statusIndicator = document.getElementById('statusIndicator');
65
- if (translateButton) {
66
- translateButton.classList.remove('button-disabled');
67
- translateButton.disabled = false;
68
  }
69
  if (statusIndicator) {
70
- statusIndicator.style.background = '#e6ffe6';
71
- statusIndicator.textContent = 'Services ready';
72
- // Optionally hide after a delay:
73
- setTimeout(() => {
74
- statusIndicator.style.display = 'none';
75
- }, 3000);
76
  }
77
  return true;
78
  }
79
  throw new Error('Services not ready');
80
  })
81
  .catch(error => {
 
 
 
 
82
  console.log('Waiting for services...', error);
83
  return false;
84
  });
 
23
  100% { transform: rotate(360deg); }
24
  }
25
 
26
+ #translationControls {
27
+ display: none;
28
+ margin-bottom: 10px;
29
  }
30
 
31
+ #languageSelect {
32
+ margin-right: 10px;
33
+ padding: 5px;
34
+ }
35
+
36
+ #translateButton {
37
+ padding: 5px 10px;
38
  }
39
 
 
40
  #statusIndicator {
41
+ text-align: center;
42
+ padding: 20px;
 
 
 
43
  background: #f0f0f0;
44
+ margin-bottom: 20px;
45
+ border-radius: 4px;
46
+ font-size: 16px;
47
  }
48
  </style>
49
  </head>
50
  <body>
51
  <div id="app"></div>
 
52
  <script>
53
  // Add this before loading the main script
54
  window.servicesReady = false;
55
 
56
  // Create a function to check service status
57
  function checkServicesStatus() {
58
+ fetch('/healthcheck')
59
  .then(response => {
60
  if (response.ok) {
61
  window.servicesReady = true;
62
+ const translationControls = document.getElementById('translationControls');
63
  const statusIndicator = document.getElementById('statusIndicator');
64
+ if (translationControls) {
65
+ translationControls.style.display = 'block';
 
66
  }
67
  if (statusIndicator) {
68
+ statusIndicator.style.display = 'none';
 
 
 
 
 
69
  }
70
  return true;
71
  }
72
  throw new Error('Services not ready');
73
  })
74
  .catch(error => {
75
+ const statusIndicator = document.getElementById('statusIndicator');
76
+ if (statusIndicator) {
77
+ statusIndicator.innerHTML = '<span class="spinner"></span> Services starting...';
78
+ }
79
  console.log('Waiting for services...', error);
80
  return false;
81
  });
nginx.conf CHANGED
@@ -5,22 +5,26 @@ events {
5
  http {
6
  server {
7
  listen 7860;
8
- listen 7861;
9
 
10
- location / {
11
  root /docauth;
12
- }
 
 
 
 
13
 
14
  location /client/api/v1/ {
15
  proxy_pass http://127.0.0.1:4000;
16
  }
17
 
18
  location /v1/embeddings {
19
- proxy_pass http://127.0.0.1:8081;
20
  }
21
 
22
  location /v1 {
23
- proxy_pass http://127.0.0.1:8082;
24
  }
25
  }
26
  }
 
5
  http {
6
  server {
7
  listen 7860;
8
+ listen 7861;
9
 
10
+ location / {
11
  root /docauth;
12
+ }
13
+
14
+ location /healthcheck {
15
+ proxy_pass http://127.0.0.1:4000/healthcheck;
16
+ }
17
 
18
  location /client/api/v1/ {
19
  proxy_pass http://127.0.0.1:4000;
20
  }
21
 
22
  location /v1/embeddings {
23
+ proxy_pass http://127.0.0.1:8081;
24
  }
25
 
26
  location /v1 {
27
+ proxy_pass http://127.0.0.1:8082;
28
  }
29
  }
30
  }