Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,8 @@ from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer
|
|
8 |
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
9 |
from io import BytesIO
|
10 |
import os
|
|
|
|
|
11 |
|
12 |
# Suppress warnings
|
13 |
import warnings
|
@@ -39,9 +41,17 @@ granite_headers = {
|
|
39 |
|
40 |
}
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
# Function to transcribe audio files
|
43 |
-
def transcribe_audio(
|
44 |
-
|
|
|
45 |
return result['text']
|
46 |
|
47 |
# Function to extract text and questions from PDF
|
@@ -150,4 +160,4 @@ if uploaded_audio_files and uploaded_pdf:
|
|
150 |
data=response_pdf_buffer,
|
151 |
file_name="response_output.pdf",
|
152 |
mime="application/pdf"
|
153 |
-
)
|
|
|
8 |
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
|
9 |
from io import BytesIO
|
10 |
import os
|
11 |
+
from pydub import AudioSegment
|
12 |
+
import numpy as np
|
13 |
|
14 |
# Suppress warnings
|
15 |
import warnings
|
|
|
41 |
|
42 |
}
|
43 |
|
44 |
+
# Function to convert BytesIO to numpy array
|
45 |
+
def bytesio_to_numpy(audio_file):
|
46 |
+
audio = AudioSegment.from_file(audio_file)
|
47 |
+
audio = audio.set_channels(1).set_frame_rate(16000) # Ensure mono and correct sampling rate
|
48 |
+
samples = np.array(audio.get_array_of_samples())
|
49 |
+
return samples.astype(np.float32) / 32768.0 # Normalize to [-1, 1]
|
50 |
+
|
51 |
# Function to transcribe audio files
|
52 |
+
def transcribe_audio(audio_file):
|
53 |
+
audio_np = bytesio_to_numpy(audio_file)
|
54 |
+
result = whisper_pipe(audio_np)
|
55 |
return result['text']
|
56 |
|
57 |
# Function to extract text and questions from PDF
|
|
|
160 |
data=response_pdf_buffer,
|
161 |
file_name="response_output.pdf",
|
162 |
mime="application/pdf"
|
163 |
+
)
|