Spaces:
Running on Zero
Running on Zero
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -983,11 +983,21 @@ window.stopTranscribeTimer=function(ok){
|
|
| 983 |
},60000);
|
| 984 |
};
|
| 985 |
|
| 986 |
-
/* Auto-
|
|
|
|
|
|
|
|
|
|
| 987 |
new MutationObserver(function(muts){
|
| 988 |
muts.forEach(function(m){
|
| 989 |
m.addedNodes.forEach(function(n){
|
| 990 |
if(n.nodeType===1){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 991 |
var isToast=n.classList&&(n.classList.contains('toast-wrap')||n.classList.contains('error'));
|
| 992 |
var hasError=n.querySelector&&n.querySelector('.error,.toast-body');
|
| 993 |
if((isToast||hasError)&&window._timerInterval){
|
|
@@ -1102,24 +1112,14 @@ with gr.Blocks(theme=THEME, title="TranscribeAI", css=CUSTOM_CSS, head=UPLOAD_PR
|
|
| 1102 |
docx_file = gr.File(label="DOCX β Dokumen Word berwarna")
|
| 1103 |
|
| 1104 |
# ---- Connect ----
|
| 1105 |
-
#
|
| 1106 |
-
#
|
| 1107 |
-
#
|
| 1108 |
-
# Step 3: Stop timer on success (JS).
|
| 1109 |
-
def validate_audio(audio_file):
|
| 1110 |
-
if audio_file is None:
|
| 1111 |
-
raise gr.Error("Upload file audio terlebih dahulu!")
|
| 1112 |
-
|
| 1113 |
btn_start.click(
|
| 1114 |
-
fn=validate_audio,
|
| 1115 |
-
inputs=[audio_input],
|
| 1116 |
-
outputs=None,
|
| 1117 |
-
).then(
|
| 1118 |
fn=transcribe_full,
|
| 1119 |
inputs=[audio_input, language_choice, speaker_count,
|
| 1120 |
enable_diarization, enable_vad],
|
| 1121 |
outputs=[summary_output, transcript_output, srt_file, txt_file, docx_file],
|
| 1122 |
-
js="() => { window.startTranscribeTimer(); }",
|
| 1123 |
).then(
|
| 1124 |
fn=lambda: None,
|
| 1125 |
inputs=None,
|
|
|
|
| 983 |
},60000);
|
| 984 |
};
|
| 985 |
|
| 986 |
+
/* Auto-start timer on Gradio progress indicator (server-side signal).
|
| 987 |
+
This ensures timer ONLY starts after validation passes:
|
| 988 |
+
- No file β gr.Error() before progress() β no progress element β timer never starts
|
| 989 |
+
- File OK β progress(0.05) β progress element added β timer starts */
|
| 990 |
new MutationObserver(function(muts){
|
| 991 |
muts.forEach(function(m){
|
| 992 |
m.addedNodes.forEach(function(n){
|
| 993 |
if(n.nodeType===1){
|
| 994 |
+
/* Detect Gradio progress β start timer (only once) */
|
| 995 |
+
var isProgress=n.classList&&(n.classList.contains('progress-level')||n.classList.contains('eta-bar'));
|
| 996 |
+
var hasProgress=n.querySelector&&n.querySelector('.progress-level,.eta-bar');
|
| 997 |
+
if((isProgress||hasProgress)&&!window._timerInterval){
|
| 998 |
+
window.startTranscribeTimer();
|
| 999 |
+
}
|
| 1000 |
+
/* Detect error toast β stop timer */
|
| 1001 |
var isToast=n.classList&&(n.classList.contains('toast-wrap')||n.classList.contains('error'));
|
| 1002 |
var hasError=n.querySelector&&n.querySelector('.error,.toast-body');
|
| 1003 |
if((isToast||hasError)&&window._timerInterval){
|
|
|
|
| 1112 |
docx_file = gr.File(label="DOCX β Dokumen Word berwarna")
|
| 1113 |
|
| 1114 |
# ---- Connect ----
|
| 1115 |
+
# Timer is started by MutationObserver when Gradio progress() appears in DOM.
|
| 1116 |
+
# This ensures timer ONLY starts after validation passes (no file β no progress).
|
| 1117 |
+
# Timer success-stop via .then(); error-stop via MutationObserver on error toast.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1118 |
btn_start.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1119 |
fn=transcribe_full,
|
| 1120 |
inputs=[audio_input, language_choice, speaker_count,
|
| 1121 |
enable_diarization, enable_vad],
|
| 1122 |
outputs=[summary_output, transcript_output, srt_file, txt_file, docx_file],
|
|
|
|
| 1123 |
).then(
|
| 1124 |
fn=lambda: None,
|
| 1125 |
inputs=None,
|