File size: 1,767 Bytes
8aa535a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ccf50e
0ef962c
8aa535a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2c8eee
1618b0e
8aa535a
 
 
 
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
import os
import gradio as gr
import whisper
import time
from keybert import KeyBERT
from sendToSheets import sendToSheets

kw_model = KeyBERT()
model = whisper.load_model('base')

def transcribe(audio, state={}, lang=None):
    time.sleep(1)
    
    state['transcription'] = ""
    transcription = model.transcribe(audio, language=lang)
    state['transcription'] += transcription['text'] + " "
    
    text = state['transcription']
    keyword = kw_model.extract_keywords(text, keyphrase_ngram_range=(1, 1), stop_words=None, top_n=1)

    #if len(keyword) > 0 and len(text) > 0:
        #sendToSheets(keyword[0][0], text)


    return state['transcription'], state, f"Detected language: {transcription['language']}", f"Detected Keyword: {keyword[0][0]}"


title = "RememberThis by Whisper4Lokal - OpenAI's Whisper hackathon"
transcription_tb = gr.Textbox(label="Transcription", lines=10, max_lines=20)
detected_lang = gr.outputs.HTML(label="Detected Language")
detected_keyword= gr.outputs.HTML(label="Detected Keyword")

state = gr.State({"transcription": ""})

gr.Interface(fn=transcribe,
    inputs=[
        gr.Audio(source="microphone", type="filepath", streaming=False),
        state,
    ],
    outputs=[
        transcription_tb,
        state,
        detected_lang,
        detected_keyword
    ],
    #live=True,
    allow_flagging='never',
    title=title,
    description = "How to use: Click on 'Record from microphone'. Say your line and click on 'Stop recording'. Click submit.",
    article="Transcribed texts and keywords can be viewed here at: https://docs.google.com/spreadsheets/d/1U50M1BpGd7mAK6BsHNE06EocMDM9-FXK3jDGHb33x8E/edit?usp=sharing. This link will be disabled after Oct 2022."
).launch(
    # enable_queue=True,
    #debug=True
)