Spaces:
Sleeping
Sleeping
Brunwo
commited on
Commit
·
bf90d9e
1
Parent(s):
9e47428
add api server param, getting backend call
Browse files- index.html +3 -0
- script.js +38 -21
- styles.css +6 -0
index.html
CHANGED
@@ -7,6 +7,7 @@
|
|
7 |
<meta name="theme-color" content="#317EFB">
|
8 |
<link rel="manifest" href="/manifest.json">
|
9 |
<link rel="stylesheet" href="/styles.css">
|
|
|
10 |
</head>
|
11 |
<body>
|
12 |
<h1>web to podcast player</h1>
|
@@ -25,6 +26,8 @@
|
|
25 |
<input type="password" id="apiKey" placeholder="Enter your API key">
|
26 |
<button id="toggleApiKey">👁️</button>
|
27 |
</div>
|
|
|
|
|
28 |
<button id="saveSettings">Save</button>
|
29 |
</div>
|
30 |
</div>
|
|
|
7 |
<meta name="theme-color" content="#317EFB">
|
8 |
<link rel="manifest" href="/manifest.json">
|
9 |
<link rel="stylesheet" href="/styles.css">
|
10 |
+
<!-- Removed Gradio client library -->
|
11 |
</head>
|
12 |
<body>
|
13 |
<h1>web to podcast player</h1>
|
|
|
26 |
<input type="password" id="apiKey" placeholder="Enter your API key">
|
27 |
<button id="toggleApiKey">👁️</button>
|
28 |
</div>
|
29 |
+
<label for="apiServer">API Server:</label>
|
30 |
+
<input type="text" id="apiServer" placeholder="Enter API server URL">
|
31 |
<button id="saveSettings">Save</button>
|
32 |
</div>
|
33 |
</div>
|
script.js
CHANGED
@@ -6,15 +6,20 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
6 |
const saveSettingsBtn = document.getElementById('saveSettings');
|
7 |
const apiKeyInput = document.getElementById('apiKey');
|
8 |
const toggleApiKeyBtn = document.getElementById('toggleApiKey');
|
|
|
9 |
|
10 |
let originalApiKey = '';
|
|
|
11 |
|
12 |
-
// Load saved
|
13 |
const savedApiKey = localStorage.getItem('openaiApiKey');
|
|
|
14 |
if (savedApiKey) {
|
15 |
apiKeyInput.value = savedApiKey;
|
16 |
originalApiKey = savedApiKey;
|
17 |
}
|
|
|
|
|
18 |
|
19 |
// Toggle API key visibility
|
20 |
toggleApiKeyBtn.onclick = function() {
|
@@ -30,6 +35,7 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
30 |
// Open settings modal
|
31 |
settingsBtn.onclick = function() {
|
32 |
originalApiKey = apiKeyInput.value;
|
|
|
33 |
settingsModal.style.display = "block";
|
34 |
apiKeyInput.focus();
|
35 |
}
|
@@ -63,13 +69,16 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
63 |
// Save settings
|
64 |
function saveSettings() {
|
65 |
const apiKey = apiKeyInput.value.trim();
|
66 |
-
|
|
|
67 |
localStorage.setItem('openaiApiKey', apiKey);
|
68 |
-
|
69 |
-
|
|
|
|
|
70 |
closeModal();
|
71 |
} else {
|
72 |
-
alert('Please enter a valid API key.');
|
73 |
}
|
74 |
}
|
75 |
|
@@ -79,38 +88,46 @@ document.addEventListener("DOMContentLoaded", function() {
|
|
79 |
async function fetchMp3(link) {
|
80 |
try {
|
81 |
const apiKey = localStorage.getItem('openaiApiKey');
|
|
|
82 |
if (!apiKey) {
|
83 |
throw new Error("API key not set. Please set your OpenAI API key in the settings.");
|
84 |
}
|
|
|
|
|
|
|
85 |
|
86 |
-
const response = await fetch(
|
87 |
method: 'POST',
|
88 |
headers: {
|
89 |
'Content-Type': 'application/json',
|
90 |
},
|
91 |
body: JSON.stringify({
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
|
|
|
|
|
|
|
|
100 |
}),
|
101 |
});
|
102 |
|
103 |
if (!response.ok) {
|
104 |
-
throw new Error(
|
105 |
-
}
|
106 |
-
|
107 |
-
const data = await response.json();
|
108 |
-
if (data.error) {
|
109 |
-
throw new Error(data.error);
|
110 |
}
|
111 |
|
|
|
|
|
|
|
|
|
|
|
112 |
// Set the audio player source
|
113 |
-
audioPlayer.src =
|
114 |
audioPlayer.play();
|
115 |
} catch (error) {
|
116 |
console.error('Error fetching MP3:', error);
|
|
|
6 |
const saveSettingsBtn = document.getElementById('saveSettings');
|
7 |
const apiKeyInput = document.getElementById('apiKey');
|
8 |
const toggleApiKeyBtn = document.getElementById('toggleApiKey');
|
9 |
+
const apiServerInput = document.getElementById('apiServer');
|
10 |
|
11 |
let originalApiKey = '';
|
12 |
+
let originalApiServer = '';
|
13 |
|
14 |
+
// Load saved settings on page load
|
15 |
const savedApiKey = localStorage.getItem('openaiApiKey');
|
16 |
+
const savedApiServer = localStorage.getItem('apiServer') || 'http://127.0.0.1:7860';
|
17 |
if (savedApiKey) {
|
18 |
apiKeyInput.value = savedApiKey;
|
19 |
originalApiKey = savedApiKey;
|
20 |
}
|
21 |
+
apiServerInput.value = savedApiServer;
|
22 |
+
originalApiServer = savedApiServer;
|
23 |
|
24 |
// Toggle API key visibility
|
25 |
toggleApiKeyBtn.onclick = function() {
|
|
|
35 |
// Open settings modal
|
36 |
settingsBtn.onclick = function() {
|
37 |
originalApiKey = apiKeyInput.value;
|
38 |
+
originalApiServer = apiServerInput.value;
|
39 |
settingsModal.style.display = "block";
|
40 |
apiKeyInput.focus();
|
41 |
}
|
|
|
69 |
// Save settings
|
70 |
function saveSettings() {
|
71 |
const apiKey = apiKeyInput.value.trim();
|
72 |
+
const apiServer = apiServerInput.value.trim();
|
73 |
+
if (apiKey && apiServer) {
|
74 |
localStorage.setItem('openaiApiKey', apiKey);
|
75 |
+
localStorage.setItem('apiServer', apiServer);
|
76 |
+
originalApiKey = apiKey;
|
77 |
+
originalApiServer = apiServer;
|
78 |
+
alert('Settings saved successfully!');
|
79 |
closeModal();
|
80 |
} else {
|
81 |
+
alert('Please enter both a valid API key and API server.');
|
82 |
}
|
83 |
}
|
84 |
|
|
|
88 |
async function fetchMp3(link) {
|
89 |
try {
|
90 |
const apiKey = localStorage.getItem('openaiApiKey');
|
91 |
+
const apiServer = localStorage.getItem('apiServer');
|
92 |
if (!apiKey) {
|
93 |
throw new Error("API key not set. Please set your OpenAI API key in the settings.");
|
94 |
}
|
95 |
+
if (!apiServer) {
|
96 |
+
throw new Error("API server not set. Please set the API server in the settings.");
|
97 |
+
}
|
98 |
|
99 |
+
const response = await fetch(`${apiServer}/api/predict`, {
|
100 |
method: 'POST',
|
101 |
headers: {
|
102 |
'Content-Type': 'application/json',
|
103 |
},
|
104 |
body: JSON.stringify({
|
105 |
+
data: [
|
106 |
+
link,
|
107 |
+
apiKey,
|
108 |
+
"gpt-4o-mini",
|
109 |
+
"tts-1",
|
110 |
+
"alloy",
|
111 |
+
"echo",
|
112 |
+
null, // api_base
|
113 |
+
"", // edited_transcript
|
114 |
+
"", // user_feedback
|
115 |
+
"summary" // original_text
|
116 |
+
]
|
117 |
}),
|
118 |
});
|
119 |
|
120 |
if (!response.ok) {
|
121 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
|
|
|
|
|
|
|
|
|
|
122 |
}
|
123 |
|
124 |
+
const result = await response.json();
|
125 |
+
|
126 |
+
// Assuming the audio file URL is the first item in the result
|
127 |
+
const audioFileUrl = result.data[0];
|
128 |
+
|
129 |
// Set the audio player source
|
130 |
+
audioPlayer.src = audioFileUrl;
|
131 |
audioPlayer.play();
|
132 |
} catch (error) {
|
133 |
console.error('Error fetching MP3:', error);
|
styles.css
CHANGED
@@ -85,3 +85,9 @@ body {
|
|
85 |
#toggleApiKey:hover {
|
86 |
background-color: #e0e0e0;
|
87 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
#toggleApiKey:hover {
|
86 |
background-color: #e0e0e0;
|
87 |
}
|
88 |
+
|
89 |
+
#apiServer {
|
90 |
+
width: 100%;
|
91 |
+
padding: 5px;
|
92 |
+
margin: 10px 0;
|
93 |
+
}
|