Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ import gradio as gr
|
|
| 7 |
|
| 8 |
|
| 9 |
model = whisper.load_model("base")
|
| 10 |
-
|
| 11 |
def convert_to_text(audio_path: str) -> str:
|
| 12 |
# Load the model outside the function if possible, so it's only loaded once
|
| 13 |
model = whisper.load_model("base")
|
|
@@ -18,19 +17,17 @@ def convert_to_text(audio_path: str) -> str:
|
|
| 18 |
|
| 19 |
|
| 20 |
# Process segments in parallel using multiprocessing
|
| 21 |
-
|
| 22 |
-
pool = ctx.Pool()
|
| 23 |
print("Starting the processes....")
|
| 24 |
results = pool.map(process_segment, audio_segments)
|
| 25 |
pool.close()
|
| 26 |
-
pool.join()
|
| 27 |
|
| 28 |
-
return audio_segments[0]
|
| 29 |
|
| 30 |
# Combine the results
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
import os
|
| 35 |
from pydub import AudioSegment
|
| 36 |
|
|
@@ -69,7 +66,7 @@ def split_audio(audio_path: str, chunk_size: int) -> List[str]:
|
|
| 69 |
return audio_segments
|
| 70 |
|
| 71 |
|
| 72 |
-
def process_segment(segment_path: str
|
| 73 |
# Load the model for each process if necessary
|
| 74 |
|
| 75 |
print(f"Processing segment : {segment_path}")
|
|
@@ -92,6 +89,6 @@ def get_results(path):
|
|
| 92 |
return "complete"
|
| 93 |
|
| 94 |
ad = gr.components.Audio(type='filepath')
|
| 95 |
-
iface = gr.Interface(fn=
|
| 96 |
iface.launch()
|
| 97 |
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
model = whisper.load_model("base")
|
|
|
|
| 10 |
def convert_to_text(audio_path: str) -> str:
|
| 11 |
# Load the model outside the function if possible, so it's only loaded once
|
| 12 |
model = whisper.load_model("base")
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
# Process segments in parallel using multiprocessing
|
| 20 |
+
pool = multiprocessing.Pool()
|
|
|
|
| 21 |
print("Starting the processes....")
|
| 22 |
results = pool.map(process_segment, audio_segments)
|
| 23 |
pool.close()
|
| 24 |
+
pool.join()
|
| 25 |
|
|
|
|
| 26 |
|
| 27 |
# Combine the results
|
| 28 |
+
text = ' '.join(results)
|
| 29 |
+
return text
|
| 30 |
+
|
| 31 |
import os
|
| 32 |
from pydub import AudioSegment
|
| 33 |
|
|
|
|
| 66 |
return audio_segments
|
| 67 |
|
| 68 |
|
| 69 |
+
def process_segment(segment_path: str) -> str:
|
| 70 |
# Load the model for each process if necessary
|
| 71 |
|
| 72 |
print(f"Processing segment : {segment_path}")
|
|
|
|
| 89 |
return "complete"
|
| 90 |
|
| 91 |
ad = gr.components.Audio(type='filepath')
|
| 92 |
+
iface = gr.Interface(fn=convert_to_text, inputs=ad, outputs="text")
|
| 93 |
iface.launch()
|
| 94 |
|