theodotus's picture
Lower temperature
b3ad65b
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()