jomasego commited on
Commit
00e1afd
·
1 Parent(s): 3ddb139

UI: Improve JS for API link, add YouTube note

Browse files
Files changed (1) hide show
  1. app.py +30 -9
app.py CHANGED
@@ -285,6 +285,7 @@ with gr.Blocks() as app:
285
  gr.Markdown("### Use this endpoint from another application (e.g., another Hugging Face Space).")
286
  gr.Markdown("The `process_video_input` function is exposed here.")
287
  api_interface.render()
 
288
 
289
  with gr.Tab("Demo (for Manual Testing)"):
290
  gr.Markdown("### Manually test video URLs or paths and observe the response.")
@@ -296,26 +297,46 @@ if __name__ == "__main__":
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);
 
285
  gr.Markdown("### Use this endpoint from another application (e.g., another Hugging Face Space).")
286
  gr.Markdown("The `process_video_input` function is exposed here.")
287
  api_interface.render()
288
+ gr.Markdown("**Note:** Some YouTube videos may fail to download if they require login or cookie authentication due to YouTube's restrictions. Direct video links are generally more reliable for automated processing.")
289
 
290
  with gr.Tab("Demo (for Manual Testing)"):
291
  gr.Markdown("### Manually test video URLs or paths and observe the response.")
 
297
  # This attempts to change the text a few times in case Gradio renders elements late.
298
  js_code = """
299
  (function() {
300
+ console.log('[MCP Script] Initializing script to change API link text...');
301
  function attemptChangeApiLinkText() {
302
+ const links = document.querySelectorAll('a');
303
+ let foundAndChanged = false;
304
+ // console.log('[MCP Script] Found ' + links.length + ' anchor tags on this attempt.'); // Can be too verbose for interval
305
  for (let i = 0; i < links.length; i++) {
306
+ const linkText = links[i].textContent ? links[i].textContent.trim() : '';
307
+ if (linkText === 'Use via API') {
308
  links[i].textContent = 'Use as an MCP or via API';
309
+ console.log('[MCP Script] Successfully changed \"Use via API\" link text.');
310
+ foundAndChanged = true;
311
+ break;
312
  }
313
  }
314
+ return foundAndChanged;
315
  }
316
 
317
  let attempts = 0;
318
+ const maxAttempts = 50; // Try for up to 5 seconds (50 * 100ms)
319
+ let initialScanDone = false;
320
  const intervalId = setInterval(() => {
321
+ if (!initialScanDone && attempts === 0) {
322
+ console.log('[MCP Script] Performing initial scan for API link text.');
323
+ initialScanDone = true;
324
+ }
325
  if (attemptChangeApiLinkText() || attempts >= maxAttempts) {
326
  clearInterval(intervalId);
327
+ if (attempts >= maxAttempts && !foundAndChanged) {
328
+ // Check if the link was ever found and changed by a concurrent script or if it's truly not there
329
+ let stillNotFound = true;
330
+ const finalLinks = document.querySelectorAll('a');
331
+ for (let i = 0; i < finalLinks.length; i++) {
332
+ if (finalLinks[i].textContent && finalLinks[i].textContent.trim() === 'Use as an MCP or via API') {
333
+ stillNotFound = false; break;
334
+ }
335
+ }
336
+ if (stillNotFound) {
337
+ console.log('[MCP Script] Max attempts reached. \"Use via API\" link was not found or changed. It might not be rendered or has a different text.');
338
+ }
339
+ }
340
  }
341
  attempts++;
342
  }, 100);