Skip to content

Commit f8332e4

Browse files
committed
cleanup and error handling
1 parent f8afc52 commit f8332e4

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

transcribe_proc.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
from types import FunctionType
77
from huggingface_hub.hf_api import repo_exists as is_valid_model_id
88
import pycountry
9-
from CustomAiEngine import CustomAiEngine
10-
import traceback
9+
# from CustomAiEngine import CustomAiEngine
1110

1211

1312
def transcribe_file(input_file, model_name=None, num_speakers=2, lang="eng"):
@@ -46,7 +45,7 @@ def transcribe_file(input_file, model_name=None, num_speakers=2, lang="eng"):
4645
retrace, # uncertain how this benifits us
4746
# morphosyntax,
4847
utr,
49-
# fa
48+
fa
5049
] if action]
5150

5251
n = 0
@@ -66,31 +65,19 @@ def transcribe_file(input_file, model_name=None, num_speakers=2, lang="eng"):
6665
with open(output_file,'a',encoding='utf-8') as f:
6766
f.write(f"@DEBUG Completed step {idx}/{len(pipeline_activity)} - {(type(activity).__name__).replace('Engine','')}\n")
6867
except Exception as e:
69-
print(traceback.format_exc(e))
70-
print(f"{output_file} made it to step: {idx-1}/{len(pipeline_activity)}")
7168
with open(output_file,'a',encoding='utf-8') as f:
7269
f.write(f"@DEBUG error during step {idx}/{len(pipeline_activity)} - {(type(activity).__name__).replace('Engine','')}\n")
73-
74-
75-
# create a pipeline
76-
# nlp = ba.BatchalignPipeline(*pipeline_activity)
77-
# doc = ba.Document.new(media_path=input_file, lang=lang)
78-
# doc = nlp(doc)
79-
# chat = ba.CHATFile(doc=doc)
80-
# n = 0
81-
# output_file = f"{input_file}{'_'+str(n) if n > 0 else ''}.cha"
82-
# while 1:
83-
# output_file = f"{input_file}{'_'+str(n) if n > 0 else ''}.cha"
84-
# if not os.path.exists(output_file):
85-
# break
86-
# n += 1
87-
# chat.write(output_file, write_wor=False)
70+
print(e)
71+
print(f"{output_file} made it to step: {idx-1}/{len(pipeline_activity)}")
72+
73+
8874
print(f"Wrote to {output_file}", flush=True)
75+
# uncomment this next block if you want the output file to automatically open
76+
# this process is blocking so we dont do it for now so that we can run through the rest of the files given by the UI component
8977
# try:
9078
# os.startfile(output_file)
9179
# except:
9280
# pass
93-
# this is process blocking so we dont do it for now
9481
# return spawn_popup_activity(title="COMPLETED!",message=f"Completed transcription of\n{input_file}\nOutput file can be found here:\n{output_file}\nOpen file now?", yes=lambda: os.startfile(output_file))
9582

9683
def spawn_popup_activity(title, message, yes=None, no=None):
@@ -101,14 +88,13 @@ def spawn_popup_activity(title, message, yes=None, no=None):
10188
return no()
10289

10390
if __name__ == "__main__":
104-
sys.argv.append('{"input_file":"D:\\\\Parent-Child Interactions\\\\Parent-Child Interactions\\\\P002_PCI.mp3","num_speakers":3,"lang":"","model_name":"openai/whisper-base.en"}')
105-
print("Attempting to transcribe for:", sys.argv[1:], flush=True)
10691
print(sys.argv, flush=True)
10792
for data in sys.argv[1:]:
10893
try:
10994
args = json.loads(data)
11095
except:
11196
print(f"Failed to parse input data: {data}")
11297
continue
98+
print("Attempting to transcribe for:", args.get('input_file',args), flush=True)
11399
transcribe_file(**args)
114-
print("Attempt completed for:", sys.argv[1:], flush=True)
100+
print("Attempt completed for:", sys.argv[1:], flush=True)

0 commit comments

Comments
 (0)