maguid28 commited on
Commit
7c7db6d
·
verified ·
1 Parent(s): 7ae0df4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -8
app.py CHANGED
@@ -272,13 +272,13 @@ with gr.Blocks() as demo:
272
  outputs=hf_token
273
  )
274
 
275
- # Initial token visibility check
276
  toggle_token_visibility(model_dd.value)
277
 
278
  uploader = gr.File(label="Upload audio/video", file_types=["audio", "video"])
279
  status = gr.Markdown()
280
  inp = gr.Textbox(label="Ask a question")
281
- out_audio = gr.Audio()
282
  ts_label = gr.Markdown()
283
 
284
  # Progress tracker
@@ -302,9 +302,7 @@ with gr.Blocks() as demo:
302
  const percent = document.getElementById('progress');
303
  const status = document.getElementById('status');
304
 
305
- // Ensure progress is a number and has a default
306
  const progressValue = Number(progress) || 0;
307
-
308
  bar.style.width = progressValue + '%';
309
  percent.textContent = progressValue + '%';
310
  status.textContent = message || 'Processing...';
@@ -322,11 +320,11 @@ with gr.Blocks() as demo:
322
  bar.style.background = '#f44336';
323
  }
324
  }
325
- // Initialize on load
326
  document.addEventListener('DOMContentLoaded', function() {
327
  updateProgress(0, 'Ready');
328
  });
329
  """
 
330
  demo.load(fn=None, inputs=None, outputs=None, js=js)
331
 
332
  def _on_model_change(label, token):
@@ -354,8 +352,8 @@ with gr.Blocks() as demo:
354
  return "⚠️ Please enter your Hugging Face token to use flan-t5-base. Get one at https://huggingface.co/settings/tokens"
355
 
356
  # Only pass the token if using flan-t5-base
357
- hf_token = token if name == "flan-t5-base" else None
358
- qa_chain = build_chain(store, name, hf_token)
359
  model_name = name # Update the current model name
360
  return f"✅ Switched to {label}"
361
  except Exception as e:
@@ -393,7 +391,13 @@ with gr.Blocks() as demo:
393
  """
394
 
395
  refresh_btn.click(refresh_logs, None, log_box)
396
- demo.load(refresh_logs, None, log_box, every=5)
 
 
 
 
 
 
397
 
398
  if __name__ == "__main__":
399
  demo.launch()
 
272
  outputs=hf_token
273
  )
274
 
275
+ # Initial token visibility check (no-op; starts hidden)
276
  toggle_token_visibility(model_dd.value)
277
 
278
  uploader = gr.File(label="Upload audio/video", file_types=["audio", "video"])
279
  status = gr.Markdown()
280
  inp = gr.Textbox(label="Ask a question")
281
+ out_audio = gr.Audio(type="filepath")
282
  ts_label = gr.Markdown()
283
 
284
  # Progress tracker
 
302
  const percent = document.getElementById('progress');
303
  const status = document.getElementById('status');
304
 
 
305
  const progressValue = Number(progress) || 0;
 
306
  bar.style.width = progressValue + '%';
307
  percent.textContent = progressValue + '%';
308
  status.textContent = message || 'Processing...';
 
320
  bar.style.background = '#f44336';
321
  }
322
  }
 
323
  document.addEventListener('DOMContentLoaded', function() {
324
  updateProgress(0, 'Ready');
325
  });
326
  """
327
+ # In Gradio 4, keep js= (no underscore)
328
  demo.load(fn=None, inputs=None, outputs=None, js=js)
329
 
330
  def _on_model_change(label, token):
 
352
  return "⚠️ Please enter your Hugging Face token to use flan-t5-base. Get one at https://huggingface.co/settings/tokens"
353
 
354
  # Only pass the token if using flan-t5-base
355
+ hf_token_val = token if name == "flan-t5-base" else None
356
+ qa_chain = build_chain(store, name, hf_token_val)
357
  model_name = name # Update the current model name
358
  return f"✅ Switched to {label}"
359
  except Exception as e:
 
391
  """
392
 
393
  refresh_btn.click(refresh_logs, None, log_box)
394
+
395
+ # Run once when the app loads
396
+ demo.load(fn=refresh_logs, outputs=log_box)
397
+
398
+ # Then poll every 5s with a Timer (Gradio 4 way)
399
+ timer = gr.Timer(interval=5.0, active=True)
400
+ timer.tick(fn=refresh_logs, outputs=log_box)
401
 
402
  if __name__ == "__main__":
403
  demo.launch()