romizone commited on
Commit
659dcd0
·
verified ·
1 Parent(s): 59cdb6f

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +75 -7
app.py CHANGED
@@ -357,7 +357,7 @@ def transcribe_full(audio_file, language_name, num_speakers,
357
  filename = Path(audio_path).name
358
  lang_code = LANGUAGE_MAP.get(language_name, None)
359
 
360
- progress(0.05, desc="Transkripsi di GPU...")
361
 
362
  # 1. Transcribe on GPU
363
  t0 = time.time()
@@ -372,11 +372,11 @@ def transcribe_full(audio_file, language_name, num_speakers,
372
  raise gr.Error("Tidak ada teks yang terdeteksi dari audio.")
373
 
374
  transcribe_time = time.time() - t0
375
- progress(0.60, desc=f"Transkripsi selesai ({transcribe_time:.0f}s)")
376
 
377
  # 2. Speaker Diarization (CPU)
378
  if enable_diarization and len(segments) >= 2:
379
- progress(0.65, desc="Mengidentifikasi pembicara...")
380
  try:
381
  segments = perform_diarization(audio_path, segments, num_speakers)
382
  segments = merge_consecutive(segments)
@@ -390,7 +390,7 @@ def transcribe_full(audio_file, language_name, num_speakers,
390
  seg['speaker'] = 'Speaker 1'
391
  seg['speaker_id'] = 0
392
 
393
- progress(0.85, desc="Membuat file output...")
394
 
395
  # 3. Export
396
  timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
@@ -404,7 +404,7 @@ def transcribe_full(audio_file, language_name, num_speakers,
404
  generate_txt(segments, txt_path, filename, detected_lang, duration)
405
  generate_docx(segments, docx_path, filename, detected_lang, duration)
406
 
407
- progress(0.95, desc="Menyiapkan hasil...")
408
 
409
  # Build display text
410
  transcript_lines = []
@@ -432,7 +432,7 @@ def transcribe_full(audio_file, language_name, num_speakers,
432
  f"| Engine | Whisper + ZeroGPU H200 |"
433
  )
434
 
435
- progress(1.0, desc="Selesai!")
436
  return summary, transcript_text, srt_path, txt_path, docx_path
437
 
438
 
@@ -807,7 +807,75 @@ span[data-testid="info-text"] {
807
  }
808
  """
809
 
810
- with gr.Blocks(theme=THEME, title="TranscribeAI", css=CUSTOM_CSS) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
811
 
812
  # ---- Header ----
813
  gr.HTML("""
 
357
  filename = Path(audio_path).name
358
  lang_code = LANGUAGE_MAP.get(language_name, None)
359
 
360
+ progress(0.05, desc=" Menunggu GPU & memproses audio... (bisa 30-90 detik)")
361
 
362
  # 1. Transcribe on GPU
363
  t0 = time.time()
 
372
  raise gr.Error("Tidak ada teks yang terdeteksi dari audio.")
373
 
374
  transcribe_time = time.time() - t0
375
+ progress(0.60, desc=f"Transkripsi selesai ({transcribe_time:.0f}s)")
376
 
377
  # 2. Speaker Diarization (CPU)
378
  if enable_diarization and len(segments) >= 2:
379
+ progress(0.65, desc="🔍 Mengidentifikasi pembicara...")
380
  try:
381
  segments = perform_diarization(audio_path, segments, num_speakers)
382
  segments = merge_consecutive(segments)
 
390
  seg['speaker'] = 'Speaker 1'
391
  seg['speaker_id'] = 0
392
 
393
+ progress(0.85, desc="📄 Membuat file output...")
394
 
395
  # 3. Export
396
  timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
 
404
  generate_txt(segments, txt_path, filename, detected_lang, duration)
405
  generate_docx(segments, docx_path, filename, detected_lang, duration)
406
 
407
+ progress(0.95, desc="📦 Menyiapkan hasil...")
408
 
409
  # Build display text
410
  transcript_lines = []
 
432
  f"| Engine | Whisper + ZeroGPU H200 |"
433
  )
434
 
435
+ progress(1.0, desc="🎉 Selesai!")
436
  return summary, transcript_text, srt_path, txt_path, docx_path
437
 
438
 
 
807
  }
808
  """
809
 
810
+ UPLOAD_PROGRESS_JS = """
811
+ <style>
812
+ #upload-bar-wrap{display:none;position:fixed;top:0;left:0;right:0;z-index:99999;height:5px;background:#222228}
813
+ #upload-bar{height:100%;width:0%;background:linear-gradient(90deg,#6366f1,#a78bfa);transition:width .2s;border-radius:0 3px 3px 0}
814
+ #upload-pct{display:none;position:fixed;top:12px;right:16px;z-index:99999;background:#1a1a1f;border:1px solid #6366f1;
815
+ color:#c7c7ff;padding:7px 16px;border-radius:10px;font-size:13px;font-weight:700;font-family:Inter,sans-serif;
816
+ box-shadow:0 4px 20px rgba(99,102,241,.3)}
817
+ </style>
818
+ <script>
819
+ (function(){
820
+ var barW=document.createElement('div');barW.id='upload-bar-wrap';
821
+ barW.innerHTML='<div id="upload-bar"></div>';document.body.appendChild(barW);
822
+ var pctEl=document.createElement('div');pctEl.id='upload-pct';document.body.appendChild(pctEl);
823
+
824
+ function show(p){
825
+ barW.style.display='block';pctEl.style.display='block';
826
+ document.getElementById('upload-bar').style.width=p+'%';
827
+ pctEl.textContent='\\u{1F4E4} Uploading... '+p+'%';
828
+ }
829
+ function hide(){
830
+ show(100);
831
+ setTimeout(function(){
832
+ barW.style.display='none';pctEl.style.display='none';
833
+ document.getElementById('upload-bar').style.width='0%';
834
+ },800);
835
+ }
836
+
837
+ var _fetch=window.fetch;
838
+ window.fetch=function(input,init){
839
+ var url=typeof input==='string'?input:(input&&input.url?input.url:'');
840
+ if(url.indexOf('/upload')!==-1 && init && init.method==='POST' && init.body){
841
+ return new Promise(function(resolve,reject){
842
+ var xhr=new XMLHttpRequest();
843
+ xhr.open('POST',url,true);
844
+ xhr.responseType='text';
845
+ if(init.headers){
846
+ try{
847
+ var h=init.headers instanceof Headers?init.headers:new Headers(init.headers);
848
+ h.forEach(function(v,k){
849
+ if(k.toLowerCase()!=='content-type')xhr.setRequestHeader(k,v);
850
+ });
851
+ }catch(e){}
852
+ }
853
+ xhr.upload.onprogress=function(e){
854
+ if(e.lengthComputable)show(Math.round(e.loaded/e.total*100));
855
+ };
856
+ xhr.onload=function(){
857
+ hide();
858
+ var headers=new Headers();
859
+ try{
860
+ xhr.getAllResponseHeaders().trim().split('\\r\\n').forEach(function(line){
861
+ var i=line.indexOf(':');
862
+ if(i>0)headers.append(line.slice(0,i).trim(),line.slice(i+1).trim());
863
+ });
864
+ }catch(e){}
865
+ resolve(new Response(xhr.responseText,{status:xhr.status,statusText:xhr.statusText,headers:headers}));
866
+ };
867
+ xhr.onerror=function(){hide();reject(new TypeError('Network request failed'));};
868
+ xhr.onabort=function(){hide();reject(new DOMException('Aborted','AbortError'));};
869
+ xhr.send(init.body);
870
+ });
871
+ }
872
+ return _fetch.apply(this,arguments);
873
+ };
874
+ })();
875
+ </script>
876
+ """
877
+
878
+ with gr.Blocks(theme=THEME, title="TranscribeAI", css=CUSTOM_CSS, head=UPLOAD_PROGRESS_JS) as demo:
879
 
880
  # ---- Header ----
881
  gr.HTML("""