Update app.py
Browse files
app.py
CHANGED
@@ -4,25 +4,33 @@ from fpdf import FPDF
|
|
4 |
import librosa
|
5 |
|
6 |
def transcribe_and_generate_pdf(audio_file):
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
19 |
|
20 |
interface = gr.Interface(
|
21 |
fn=transcribe_and_generate_pdf,
|
22 |
-
inputs=gr.Audio(
|
23 |
-
outputs=[
|
|
|
|
|
|
|
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()
|