Skip to content

Commit

Permalink
'#1823: redirect warmless console messages to log
Browse files Browse the repository at this point in the history
  • Loading branch information
lfcnassif committed Apr 28, 2024
1 parent 4f7fcf3 commit 8b23384
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions iped-app/resources/scripts/tasks/WhisperProcess.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def main():
deviceNum = 0

try:
model = whisperx.load_model(modelName, device=deviceId, device_index=deviceNum, threads=threads, compute_type=compute_type)
model = whisperx.load_model(modelName, device=deviceId, device_index=deviceNum, threads=threads, compute_type=compute_type, language=language)

except Exception as e:
if deviceId != 'cpu':
# loading on GPU failed (OOM?), try on CPU
print('FAILED to load model on GPU, fallbacking to CPU!', file=sys.stderr)
deviceId = 'cpu'
compute_type = 'int8'
model = whisperx.load_model(modelName, device=deviceId, device_index=deviceNum, threads=threads, compute_type=compute_type)
model = whisperx.load_model(modelName, device=deviceId, device_index=deviceNum, threads=threads, compute_type=compute_type, language=language)
else:
raise e

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Wav2Vec2TranscriptTask extends AbstractTranscriptTask {

private static LinkedBlockingDeque<Server> deque = new LinkedBlockingDeque<>();

private static volatile Level logLevel = Level.forName("MSG", 250);
protected static volatile Level logLevel = Level.forName("MSG", 250);

static class Server {
Process process;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang3.SystemUtils;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -96,4 +99,41 @@ protected TextAndScore transcribeAudio(File tmpFile) throws Exception {
return transcribeWavPart(tmpFile);
}

@Override
protected void logInputStream(InputStream is) {
List<String> ignoreMsgs = Arrays.asList(
"With dispatcher enabled, this function is no-op. You can remove the function call.",
"torchvision is not available - cannot save figures",
"Lightning automatically upgraded your loaded checkpoint from",
"Model was trained with pyannote.audio 0.0.1, yours is",
"Model was trained with torch 1.10.0+cu102, yours is");
Thread t = new Thread() {
public void run() {
byte[] buf = new byte[1024];
int read = 0;
try {
while ((read = is.read(buf)) != -1) {
String msg = new String(buf, 0, read).trim();
boolean ignore = false;
for (String i : ignoreMsgs) {
if (msg.contains(i)) {
ignore = true;
break;
}
}
if (ignore) {
logger.warn(msg);
} else {
logger.log(logLevel, msg);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
};
t.setDaemon(true);
t.start();
}

}

0 comments on commit 8b23384

Please sign in to comment.