Spaces:
Sleeping
Sleeping
UI: Change 'Use via API' footer text and add JS for it
Browse files
app.py
CHANGED
@@ -292,4 +292,33 @@ with gr.Blocks() as app:
|
|
292 |
|
293 |
# Launch the Gradio application
|
294 |
if __name__ == "__main__":
|
295 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
|
293 |
# Launch the Gradio application
|
294 |
if __name__ == "__main__":
|
295 |
+
# JavaScript to find and replace the 'Use via API' link text
|
296 |
+
# This attempts to change the text a few times in case Gradio renders elements late.
|
297 |
+
js_code = """
|
298 |
+
(function() {
|
299 |
+
function attemptChangeApiLinkText() {
|
300 |
+
const links = document.querySelectorAll('a'); // Get all anchor tags
|
301 |
+
let changed = false;
|
302 |
+
for (let i = 0; i < links.length; i++) {
|
303 |
+
// Check if the link's text content is exactly 'Use via API'
|
304 |
+
if (links[i].textContent && links[i].textContent.trim() === 'Use via API') {
|
305 |
+
links[i].textContent = 'Use as an MCP or via API';
|
306 |
+
changed = true;
|
307 |
+
// If you only expect one such link and want to stop after the first, uncomment the next line
|
308 |
+
// break;
|
309 |
+
}
|
310 |
+
}
|
311 |
+
return changed;
|
312 |
+
}
|
313 |
+
|
314 |
+
let attempts = 0;
|
315 |
+
const maxAttempts = 30; // Try for up to 3 seconds (30 * 100ms)
|
316 |
+
const intervalId = setInterval(() => {
|
317 |
+
if (attemptChangeApiLinkText() || attempts >= maxAttempts) {
|
318 |
+
clearInterval(intervalId);
|
319 |
+
}
|
320 |
+
attempts++;
|
321 |
+
}, 100);
|
322 |
+
})();
|
323 |
+
"""
|
324 |
+
app.launch(js=js_code, server_name="0.0.0.0")
|