File size: 966 Bytes
c2cddf6
d1cf1d1
 
 
 
 
 
 
 
 
 
 
 
c2cddf6
 
d1cf1d1
c2cddf6
d1cf1d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import whisper
import gradio as gr
from pathlib import Path
from dotenv import load_dotenv
import os

transcription_value = ""


def transcribe_speech(filepath):
    if filepath is None:
        gr.Warning("No audio found, please retry.")

    model = whisper.load_model("base")
    result = model.transcribe(filepath, fp16=False)

    return result["text"]


def store_transcription(output):
    global transcription_value
    transcription_value = output
    return output


mic_transcribe = gr.Interface(
    fn=lambda x: store_transcription(transcribe_speech(x)),
    inputs=gr.Audio(sources=["microphone"], type="filepath"),
    outputs=gr.Textbox(label="Transcription")
)


test_interface = gr.Blocks()
with test_interface:
    gr.TabbedInterface(
        [mic_transcribe],
        ["Transcribe Microphone"]
    )

test_interface.launch(
    share=True,
    server_port=8000,
    #prevent_thread_lock=True
)

print(transcription_value)

#test_interface.close()