gaur3009 commited on
Commit
5472a84
·
verified ·
1 Parent(s): a833101

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
app.py CHANGED
@@ -4,25 +4,33 @@ from fpdf import FPDF
4
  import librosa
5
 
6
  def transcribe_and_generate_pdf(audio_file):
7
- transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-large")
8
- audio, _ = librosa.load(audio_file, sr=16000)
9
- transcription = transcriber(audio)["text"]
 
10
 
11
- output_pdf = "transcription.pdf"
12
- pdf = FPDF()
13
- pdf.add_page()
14
- pdf.set_font("Arial", size=12)
15
- pdf.multi_cell(0, 10, transcription)
16
- pdf.output(output_pdf)
17
-
18
- return transcription, output_pdf
 
 
 
19
 
20
  interface = gr.Interface(
21
  fn=transcribe_and_generate_pdf,
22
- inputs=gr.Audio(source="upload", type="filepath"),
23
- outputs=[gr.Textbox(label="Transcription"), gr.File(label="Download PDF")],
 
 
 
24
  title="Audio-to-Text and PDF Generator",
 
25
  )
26
 
27
  if __name__ == "__main__":
28
- interface.launch()
 
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()
14
+ pdf.add_page()
15
+ pdf.set_font("Arial", size=12)
16
+ pdf.multi_cell(0, 10, transcription)
17
+ pdf.output(output_pdf)
18
+
19
+ return transcription, output_pdf
20
+
21
+ except Exception as e:
22
+ return f"An error occurred: {e}", None
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")
30
+ ],
31
  title="Audio-to-Text and PDF Generator",
32
+ description="Upload an audio file to get its transcription and download the PDF."
33
  )
34
 
35
  if __name__ == "__main__":
36
+ interface.launch()