pierreguillou commited on
Commit
a05b433
1 Parent(s): 6f557bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -22,8 +22,13 @@ def get_filename(file_obj):
22
 
23
  def audio_to_transcript(file_obj):
24
  # get all audio segments
25
- segments, _ = model_whisper.transcribe(file_obj.name, beam_size=5, vad_filter=True)
26
- print("start")
 
 
 
 
 
27
  start_segments, end_segments, text_segments = list(), list(), list()
28
  for segment in segments:
29
  start, end, text = segment.start, segment.end, segment.text
@@ -37,20 +42,23 @@ def audio_to_transcript(file_obj):
37
  df["end"] = end_segments
38
  df["text"] = text_segments
39
 
40
- print(df)
 
 
41
 
42
- return get_filename(file_obj), df
43
 
44
  ## Gradio interface
45
  headers = ["start", "end", "text"]
46
  iface = gr.Interface(fn=audio_to_transcript,
47
  inputs=gr.File(label="Audio file"),
48
  outputs=[
49
- gr.Textbox(label="Name of the audio file"),
 
50
  gr.DataFrame(label="Transcript", headers=headers),
51
  ],
52
  allow_flagging="never",
53
  title="Audio to Transcript",
54
  description="Just paste any audio file and get its corresponding transcript with timeline.",
55
  )
56
- iface.launch()
 
22
 
23
  def audio_to_transcript(file_obj):
24
  # get all audio segments
25
+ try:
26
+ filename = get_filename(file_obj)
27
+ segments, _ = model_whisper.transcribe(file_obj.name, beam_size=5, vad_filter=True)
28
+ except:
29
+ filename = file_obj.split("/")[-1]
30
+ segments, _ = model_whisper.transcribe(file_obj, beam_size=5, vad_filter=True)
31
+
32
  start_segments, end_segments, text_segments = list(), list(), list()
33
  for segment in segments:
34
  start, end, text = segment.start, segment.end, segment.text
 
42
  df["end"] = end_segments
43
  df["text"] = text_segments
44
 
45
+ csv_file = filename.split(".")[0] + ".csv"
46
+ df.to_csv(csv_file, encoding="utf-8", index=False)
47
+ path_to_csv = gr.File.update(value=csv_file, visible=True)
48
 
49
+ return filename, path_to_csv, df
50
 
51
  ## Gradio interface
52
  headers = ["start", "end", "text"]
53
  iface = gr.Interface(fn=audio_to_transcript,
54
  inputs=gr.File(label="Audio file"),
55
  outputs=[
56
+ gr.Textbox(label="Audio file name"),
57
+ gr.File(label="Transcript csv file"),
58
  gr.DataFrame(label="Transcript", headers=headers),
59
  ],
60
  allow_flagging="never",
61
  title="Audio to Transcript",
62
  description="Just paste any audio file and get its corresponding transcript with timeline.",
63
  )
64
+ iface.launch(debug=True)