Spaces:
Build error
Build error
File size: 1,801 Bytes
50af8e7 62c62a8 50af8e7 62c62a8 b3ad65b 62c62a8 50af8e7 62c62a8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
from faster_whisper import WhisperModel
import gradio as gr
model_path = "./model"
model = WhisperModel(model_path)#, device="cpu"
def process_file(in_filename: str,):
if in_filename is None or in_filename == "":
return "Error: No file"
segments, info = model.transcribe(in_filename, language="uk", beam_size=5, without_timestamps=True, temperature = 0.01)
transcript = ""
for segment in segments:
transcript += segment.text
return transcript
demo = gr.Blocks()
with demo:
with gr.Tabs():
with gr.TabItem("Upload from disk"):
uploaded_file = gr.Audio(
source="upload", # Choose between "microphone", "upload"
type="filepath",
optional=False,
label="Upload from disk",
)
upload_button = gr.Button("Submit for recognition")
uploaded_output = gr.Textbox(label="Recognized speech from uploaded file")
with gr.TabItem("Record from microphone"):
microphone = gr.Audio(
source="microphone", # Choose between "microphone", "upload"
type="filepath",
optional=False,
label="Record from microphone",
)
record_button = gr.Button("Submit for recognition")
recorded_output = gr.Textbox(label="Recognized speech from recordings")
upload_button.click(
process_file,
inputs=[
uploaded_file,
],
outputs=[uploaded_output],
)
record_button.click(
process_file,
inputs=[
microphone,
],
outputs=[recorded_output],
)
if __name__ == "__main__":
demo.launch() |