salomonsky commited on
Commit
152b33a
verified
1 Parent(s): 4b16238

Upload config.js with huggingface_hub

Browse files
Files changed (1) hide show
  1. config.js +67 -0
config.js ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.addEventListener('DOMContentLoaded', function() {
2
+ const apiConfigForm = document.getElementById('apiConfigForm');
3
+
4
+ // Cargar configuraci贸n guardada
5
+ loadSavedConfig();
6
+
7
+ apiConfigForm.addEventListener('submit', async function(e) {
8
+ e.preventDefault();
9
+
10
+ const config = {
11
+ openai_key: document.getElementById('openaiKey').value,
12
+ huggingface_key: document.getElementById('huggingfaceKey').value,
13
+ elevenlabs_key: document.getElementById('elevenLabsKey').value
14
+ };
15
+
16
+ try {
17
+ const response = await fetch('/save_config', {
18
+ method: 'POST',
19
+ headers: {
20
+ 'Content-Type': 'application/json'
21
+ },
22
+ body: JSON.stringify(config)
23
+ });
24
+
25
+ if (response.ok) {
26
+ showAlert('success', 'Configuraci贸n guardada exitosamente');
27
+ } else {
28
+ showAlert('danger', 'Error al guardar la configuraci贸n');
29
+ }
30
+ } catch (error) {
31
+ console.error('Error:', error);
32
+ showAlert('danger', 'Error al guardar la configuraci贸n');
33
+ }
34
+ });
35
+
36
+ async function loadSavedConfig() {
37
+ try {
38
+ const response = await fetch('/get_config');
39
+ if (response.ok) {
40
+ const config = await response.json();
41
+ document.getElementById('openaiKey').value = config.openai_key || '';
42
+ document.getElementById('huggingfaceKey').value = config.huggingface_key || '';
43
+ document.getElementById('elevenLabsKey').value = config.elevenlabs_key || '';
44
+ }
45
+ } catch (error) {
46
+ console.error('Error al cargar la configuraci贸n:', error);
47
+ }
48
+ }
49
+
50
+ function showAlert(type, message) {
51
+ const alertDiv = document.createElement('div');
52
+ alertDiv.className = `alert alert-${type} alert-dismissible fade show`;
53
+ alertDiv.role = 'alert';
54
+ alertDiv.innerHTML = `
55
+ ${message}
56
+ <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
57
+ `;
58
+
59
+ const form = document.getElementById('apiConfigForm');
60
+ form.insertAdjacentElement('beforebegin', alertDiv);
61
+
62
+ // Auto-cerrar la alerta despu茅s de 3 segundos
63
+ setTimeout(() => {
64
+ alertDiv.remove();
65
+ }, 3000);
66
+ }
67
+ });