gaur3009 commited on
Commit
66083b4
·
verified ·
1 Parent(s): f93888e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -1,13 +1,24 @@
1
- import gradio as gr
2
  from transformers import pipeline
3
  from fpdf import FPDF
4
  import librosa
 
5
 
6
- def transcribe_and_generate_pdf(audio_file):
7
  try:
8
  transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-large")
9
- audio, _ = librosa.load(audio_file, sr=16000) # Resample to 16kHz
10
- transcription = transcriber(audio)["text"]
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  output_pdf = "transcription.pdf"
13
  pdf = FPDF()
@@ -23,7 +34,7 @@ def transcribe_and_generate_pdf(audio_file):
23
 
24
  interface = gr.Interface(
25
  fn=transcribe_and_generate_pdf,
26
- inputs=gr.Audio(type="filepath"), # Updated to remove 'source' and use 'type="filepath"'
27
  outputs=[
28
  gr.Textbox(label="Transcription"),
29
  gr.File(label="Download PDF")
@@ -33,4 +44,4 @@ interface = gr.Interface(
33
  )
34
 
35
  if __name__ == "__main__":
36
- interface.launch()
 
 
1
  from transformers import pipeline
2
  from fpdf import FPDF
3
  import librosa
4
+ import gradio as gr
5
 
6
+ def transcribe_and_generate_pdf(audio_file, chunk_duration=30):
7
  try:
8
  transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-large")
9
+
10
+ audio, sr = librosa.load(audio_file, sr=None)
11
+
12
+ num_chunks = int(len(audio) / (sr * chunk_duration)) + 1
13
+
14
+ transcription = ""
15
+ for i in range(num_chunks):
16
+ start = i * sr * chunk_duration
17
+ end = min((i + 1) * sr * chunk_duration, len(audio))
18
+ chunk = audio[start:end]
19
+
20
+ chunk_transcription = transcriber(chunk)["text"]
21
+ transcription += chunk_transcription + " "
22
 
23
  output_pdf = "transcription.pdf"
24
  pdf = FPDF()
 
34
 
35
  interface = gr.Interface(
36
  fn=transcribe_and_generate_pdf,
37
+ inputs=gr.Audio(type="filepath"),
38
  outputs=[
39
  gr.Textbox(label="Transcription"),
40
  gr.File(label="Download PDF")
 
44
  )
45
 
46
  if __name__ == "__main__":
47
+ interface.launch()