aleger commited on
Commit
423498c
·
1 Parent(s): 646a880

header with filename added to docx

Browse files
src/runners/transcription_zipper.py CHANGED
@@ -18,7 +18,7 @@ class TranscriptionZipper(bentoml.Runnable):
18
 
19
  for t_list in transcription_list:
20
  orig_filename = t_list[0]
21
- new_content = create_word_content(t_list[1], t_list[2])
22
  new_content.save(orig_filename + '.docx')
23
  # new_content = create_content(t_list[1], t_list[2]) # html string
24
  if ".mp3" in orig_filename:
@@ -26,18 +26,19 @@ class TranscriptionZipper(bentoml.Runnable):
26
  else:
27
  file_name = orig_filename.removesuffix(".wav")
28
  with zipfile.ZipFile(zip_buffer, "a") as zip_file:
29
- #zip_file.writestr(file_name + ".html", new_content)
30
  zip_file.write(orig_filename + '.docx')
31
 
32
  # Return the zip file as bytes
33
  return zip_buffer.getvalue()
34
 
35
- def create_word_content(old_content, new_content):
 
36
  from docx import Document
37
 
38
  document = Document()
39
 
40
- # document.add_heading('Document Title', 0)
41
 
42
  p = document.add_paragraph()
43
 
@@ -51,7 +52,7 @@ def create_word_content(old_content, new_content):
51
  try:
52
  if changed_content[i] == old_content[i]:
53
  p.add_run(" " + changed_content[i])
54
- #new_content += " " + changed_content[i]
55
  both.pop(0)
56
  old_content.pop(0)
57
  changed_content.pop(0)
 
18
 
19
  for t_list in transcription_list:
20
  orig_filename = t_list[0]
21
+ new_content = create_word_content(orig_filename, t_list[1], t_list[2])
22
  new_content.save(orig_filename + '.docx')
23
  # new_content = create_content(t_list[1], t_list[2]) # html string
24
  if ".mp3" in orig_filename:
 
26
  else:
27
  file_name = orig_filename.removesuffix(".wav")
28
  with zipfile.ZipFile(zip_buffer, "a") as zip_file:
29
+ # zip_file.writestr(file_name + ".html", new_content)
30
  zip_file.write(orig_filename + '.docx')
31
 
32
  # Return the zip file as bytes
33
  return zip_buffer.getvalue()
34
 
35
+
36
+ def create_word_content(filename, old_content, new_content):
37
  from docx import Document
38
 
39
  document = Document()
40
 
41
+ document.add_heading(filename, 0)
42
 
43
  p = document.add_paragraph()
44
 
 
52
  try:
53
  if changed_content[i] == old_content[i]:
54
  p.add_run(" " + changed_content[i])
55
+ # new_content += " " + changed_content[i]
56
  both.pop(0)
57
  old_content.pop(0)
58
  changed_content.pop(0)