1. add a new streamlit ui to preview manifest
2. implement rpcy transcription client for files
parent
ae5586be72
commit
fa89775f86
|
|
@ -2,6 +2,10 @@ import os
|
||||||
import logging
|
import logging
|
||||||
import rpyc
|
import rpyc
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
|
import typer
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
app = typer.Typer()
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
||||||
|
|
@ -19,3 +23,28 @@ def transcribe_gen(asr_host=ASR_HOST, asr_port=ASR_PORT):
|
||||||
asr = rpyc.connect(asr_host, asr_port).root
|
asr = rpyc.connect(asr_host, asr_port).root
|
||||||
logger.info(f"connected to asr server successfully")
|
logger.info(f"connected to asr server successfully")
|
||||||
return asr.transcribe
|
return asr.transcribe
|
||||||
|
|
||||||
|
|
||||||
|
@app.command()
|
||||||
|
def transcribe_file(audio_file: Path):
|
||||||
|
from pydub import AudioSegment
|
||||||
|
|
||||||
|
transcriber = transcribe_gen()
|
||||||
|
aud_seg = (
|
||||||
|
AudioSegment.from_file_using_temporary_files(audio_file)
|
||||||
|
.set_channels(1)
|
||||||
|
.set_sample_width(2)
|
||||||
|
.set_frame_rate(24000)
|
||||||
|
)
|
||||||
|
tscript_file_path = audio_file.with_suffix(".txt")
|
||||||
|
transcription = transcriber(aud_seg.raw_data)
|
||||||
|
with open(tscript_file_path, "w") as tf:
|
||||||
|
tf.write(transcription)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
app()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
||||||
|
|
@ -225,6 +225,12 @@ class ExtendedPath(type(Path())):
|
||||||
with self.open("r") as jf:
|
with self.open("r") as jf:
|
||||||
return json.load(jf)
|
return json.load(jf)
|
||||||
|
|
||||||
|
def read_jsonl(self):
|
||||||
|
print(f"reading jsonl from {self}")
|
||||||
|
with self.open("r") as jf:
|
||||||
|
for l in jf.readlines():
|
||||||
|
yield json.loads(l)
|
||||||
|
|
||||||
def write_json(self, data):
|
def write_json(self, data):
|
||||||
print(f"writing json to {self}")
|
print(f"writing json to {self}")
|
||||||
self.parent.mkdir(parents=True, exist_ok=True)
|
self.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,58 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
import streamlit as st
|
||||||
|
import typer
|
||||||
|
from jasper.data.utils import ExtendedPath
|
||||||
|
from jasper.data.validation.st_rerun import rerun
|
||||||
|
|
||||||
|
app = typer.Typer()
|
||||||
|
|
||||||
|
if not hasattr(st, "mongo_connected"):
|
||||||
|
# st.task_id = str(uuid4())
|
||||||
|
task_path = ExtendedPath("preview.lck")
|
||||||
|
|
||||||
|
def current_cursor_fn():
|
||||||
|
return task_path.read_json()["current_cursor"]
|
||||||
|
|
||||||
|
def update_cursor_fn(val=0):
|
||||||
|
task_path.write_json({"current_cursor": val})
|
||||||
|
rerun()
|
||||||
|
|
||||||
|
st.get_current_cursor = current_cursor_fn
|
||||||
|
st.update_cursor = update_cursor_fn
|
||||||
|
st.mongo_connected = True
|
||||||
|
# cursor_obj = mongo_conn.find_one({"type": "current_cursor", "task_id": st.task_id})
|
||||||
|
# if not cursor_obj:
|
||||||
|
update_cursor_fn(0)
|
||||||
|
|
||||||
|
|
||||||
|
@st.cache()
|
||||||
|
def load_ui_data(validation_ui_data_path: Path):
|
||||||
|
typer.echo(f"Using validation ui data from {validation_ui_data_path}")
|
||||||
|
return list(ExtendedPath(validation_ui_data_path).read_jsonl())
|
||||||
|
|
||||||
|
|
||||||
|
@app.command()
|
||||||
|
def main(manifest: Path):
|
||||||
|
asr_data = load_ui_data(manifest)
|
||||||
|
sample_no = st.get_current_cursor()
|
||||||
|
if len(asr_data) - 1 < sample_no or sample_no < 0:
|
||||||
|
print("Invalid samplno resetting to 0")
|
||||||
|
st.update_cursor(0)
|
||||||
|
sample = asr_data[sample_no]
|
||||||
|
st.title(f"ASR Manifest Preview")
|
||||||
|
st.markdown(f"{sample_no+1} of {len(asr_data)} : **{sample['text']}**")
|
||||||
|
new_sample = st.number_input(
|
||||||
|
"Go To Sample:", value=sample_no + 1, min_value=1, max_value=len(asr_data)
|
||||||
|
)
|
||||||
|
if new_sample != sample_no + 1:
|
||||||
|
st.update_cursor(new_sample - 1)
|
||||||
|
st.sidebar.markdown(f"Gold Text: **{sample['text']}**")
|
||||||
|
st.audio(Path(sample["audio_filepath"]).open("rb"))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
app()
|
||||||
|
except SystemExit:
|
||||||
|
pass
|
||||||
Loading…
Reference in New Issue