File size: 1,095 Bytes
a088775
 
 
 
 
 
 
 
28be9e8
 
 
 
a088775
28be9e8
 
 
 
 
 
 
 
 
 
 
 
a088775
 
 
 
28be9e8
 
a088775
 
 
28be9e8
a088775
 
 
 
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
import whisper
import gradio as gr


model = whisper.load_model('base')



def transcribe(inputs , timestamp):
    if inputs is None:
          raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
    output = ""
    result = model.transcribe(inputs)
    if timestamp == "Yes":
      for indx, segment in enumerate(result['segments']):
        output += str(datetime.timedelta (seconds=segment['start'])) +" "+ str(datetime.timedelta (seconds=segment['end'])) + "\n"
        output += segment['text'].strip() + '\n'
    else:
      output = result["text"]


    print(result)
    return  output




interface = gr.Interface(
    fn=transcribe,
    inputs=[gr.Audio(sources=["upload"],type="filepath"),
            gr.Radio(["Yes", "No"], label="Timestamp", info="Displays with timestamp if needed."),],
    outputs="text",
    title="Whisper Large V3: Transcribe Audio",
    description=(
        "Transcribe long-form microphone or audio inputs with the click of a button! Demo uses the OpenAI Whisper API"
    )
)

interface.launch()