EVad commited on
Commit
8aa535a
·
1 Parent(s): 0d7b7b7

initial files.

Browse files
Files changed (4) hide show
  1. README.md +9 -1
  2. app.py +52 -0
  3. sendToSheets.py +29 -0
  4. sheetsKey.json +12 -0
README.md CHANGED
@@ -9,4 +9,12 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
9
  pinned: false
10
  ---
11
 
12
+ # Brief
13
+ This repo contains the scripts for the app made during the Open AI Whisper Hackathon via lablab.ai by Whisper4Lokal team.
14
+
15
+ # About
16
+ This app takes in a voice recording, transcribe it and extracts the main keyword from the transcribed text. The text and keyword are then stored in a Google Sheet.
17
+
18
+ # Note
19
+ To obtain the Google Sheets API key, head to https://pygsheets.readthedocs.io/en/latest/authorization.html.
20
+ The sheetsKey.json contained my API key for Google Sheet.
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ import whisper
4
+ import time
5
+ from keybert import KeyBERT
6
+ from sendToSheets import sendToSheets
7
+
8
+ kw_model = KeyBERT()
9
+ model = whisper.load_model('base')
10
+
11
+ def transcribe(audio, state={}, lang=None):
12
+ time.sleep(1)
13
+
14
+ state['transcription'] = ""
15
+ transcription = model.transcribe(audio, language=lang)
16
+ state['transcription'] += transcription['text'] + " "
17
+
18
+ text = state['transcription']
19
+ keyword = kw_model.extract_keywords(text, keyphrase_ngram_range=(1, 1), stop_words=None, top_n=1)
20
+
21
+ if len(keyword) > 0 and len(text) > 0:
22
+ sendToSheets(keyword[0][0], text)
23
+
24
+
25
+ return state['transcription'], state, f"Detected language: {transcription['language']}", f"Detected Keyword: {keyword[0][0]}"
26
+
27
+
28
+ title = "RememberThis by Whisper4Lokal - OpenAI's Whisper hackathon"
29
+ transcription_tb = gr.Textbox(label="Transcription", lines=10, max_lines=20)
30
+ detected_lang = gr.outputs.HTML(label="Detected Language")
31
+ detected_keyword= gr.outputs.HTML(label="Detected Keyword")
32
+
33
+ state = gr.State({"transcription": ""})
34
+
35
+ gr.Interface(fn=transcribe,
36
+ inputs=[
37
+ gr.Audio(source="microphone", type="filepath", streaming=False),
38
+ state,
39
+ ],
40
+ outputs=[
41
+ transcription_tb,
42
+ state,
43
+ detected_lang,
44
+ detected_keyword
45
+ ],
46
+ #live=True,
47
+ allow_flagging='never',
48
+ title=title,
49
+ ).launch(
50
+ # enable_queue=True,
51
+ #debug=True
52
+ )
sendToSheets.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pygsheets
2
+ import pandas as pd
3
+ #authorization
4
+
5
+ def sendToSheets(keyword, text):
6
+
7
+ gc = pygsheets.authorize(service_file='./sheetsKey.json')
8
+
9
+ # Create empty dataframe
10
+ df = pd.DataFrame()
11
+
12
+ # Create a column
13
+ my_dict={'keyword':[keyword],
14
+ 'text':[text]}
15
+ df = pd.DataFrame(data=my_dict)
16
+ #open the google spreadsheet (where 'Sheet1' is the name of my sheet)
17
+ sh = gc.open('Whisper4Lokal - Saved texts')
18
+
19
+ #select the first sheet
20
+ wks = sh[0]
21
+
22
+ #update the first sheet with df, starting at cell.
23
+ cells = wks.get_all_values(include_tailing_empty_rows=None, include_tailing_empty=False, returnas='matrix')
24
+ last_row = len(cells)
25
+ if last_row>1:
26
+ wks.set_dataframe(df,(last_row+1,1))
27
+ wks.delete_rows(last_row+1)
28
+ else:
29
+ wks.set_dataframe(df,(1,1))
sheetsKey.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "type": "service_account",
3
+ "project_id": "my-project-1470563274806",
4
+ "private_key_id": "7e514a2cb82c74e07fa76dcd38367003b66896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ouUXT9dFH52oBzKboB61VFsaE5xcYaK1814a7YWd2fBlAQA193p\nOjskHc2sIwKBgQCdU3ha15TdJZqe0nv0xEBiXL2K+2lJDpjgoY52w1vcauuQZ43r\ndLITwFBygD9bll4g3S+MopXIkcvUPY/iacP2pBdQUUAr1OCkluoGM6wvv5Kfuvni\nfmtuwywPenyWazIs6ZNDfQHyMj0DcEEqfnvPrqflhCu4r+M086uFeQfg0QKBgA/h\nX3pZokP9Gj6AZEnU+wZ9D/60gH4eKT0tATkuojNtAuK+6Y9a0Aq/KnYIh6WzX3Yy\noYd2uZspu+mc5DdkDW/LmBt6BJmUCdMrP5dekSmfd9PncRMPDSm5tf6Rlm4Anyv4\niLlMlAOr9/PT0on672dlv8aQRpfCQ+Q41fGGGk+9AoGAfBROGErsjZ4Leu2So3B3\nYCQpJM9CL6GfSG+ADTlQZAge7NZrWwn6KpvvjGnIWGv9Rp6nsbDb/L++pN1UqenJ\nA02BakhUF34EwB1BpfvQ9Lu9mbkRhrO5+k93Gingo4FzlBNh5N8OM8LCopxK6UfZ\nAGbFF29A/OcZIYC/aHByzNY=\n-----END PRIVATE KEY-----\n",
6
+ "client_email": "whisper@my-project-1470563274806.iam.gserviceaccount.com",
7
+ "client_id": "113406757563758600626",
8
+ "auth_uri": "https://accounts.google.com/o/oauth2/auth",
9
+ "token_uri": "https://oauth2.googleapis.com/token",
10
+ "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11
+ "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/whisper%40my-project-1470563274806.iam.gserviceaccount.com"
12
+ }