MSchell0129 commited on
Commit
2befe53
·
1 Parent(s): 806e602

initial commit

Browse files
Files changed (2) hide show
  1. .gitignore +161 -0
  2. speech_to_text.py +96 -0
.gitignore ADDED
@@ -0,0 +1,161 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
161
+ api_key.py
speech_to_text.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import whisper
3
+ from langchain import OpenAI, SQLDatabase, SQLDatabaseChain
4
+ from langchain.llms import OpenAI
5
+ from langchain.chains.summarize import load_summarize_chain
6
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
7
+ from api_key import open_ai_key
8
+
9
+ llm = OpenAI(temperature=0, openai_api_key='open_ai_key')
10
+
11
+
12
+
13
+ #This is another alternative, but this block allows for the detection of the language and it also provides lowever-level access to the model
14
+
15
+ def transcribe(aud_inp, whisper_lang):
16
+ if aud_inp is None:
17
+ return ''
18
+ model = whisper.load_audo('base')
19
+ #load audo and pad/trim it to fit 30seconds
20
+ audio = whisper.load_audio(aud_inp)
21
+ audio = whisper.pad_or_trim(audio)
22
+ #make log-Mel spectrogram and move to the same devcice as the model
23
+ mel = whisper.log_mel_spectogram(audio).to(model.device)
24
+ #detect the spoken language
25
+ _,probs = model.detect_language(mel)
26
+ print(f'Detected language: {max(probs, key=probs.get)}')
27
+ #decode the audio
28
+ options = whisper.DecodingOptions()
29
+ result = whisper.decode(model, mel, options)
30
+ print(result.text)
31
+ return result
32
+ #Function to convert speech to text
33
+
34
+ #These two functions might need to go away but I am not entirely sure yet
35
+ # def transcribe_audio(audio_file_path):
36
+ # #not sure what the path to the audio file will be so just putting a string as a place holder
37
+ # with open('audio file path') as audio_file:
38
+ # transcribtion = openai.Audio.transcribe('whisper-1', audio_file)
39
+ # return transcribtion['text']
40
+ # #Save the transcribed text to a docx file
41
+ # def save_as_doc(question, filename):
42
+ # doc=Document()
43
+ # for key, value in minutes.items():
44
+ # heading = ' '.join(word.capitalize() for word in key.split('_'))
45
+ # doc.add_heading(heading, level=1)
46
+ # doc.add_paragraph(value)
47
+ # doc.add_page_break()
48
+ # doc.save(f'{filename}.docx')
49
+ #Not sure how the data will be stored, but my idea is that when a question or prompt is asked the audio file will be stored as text which then be fed into the llm
50
+ #to then query the database and return the answer.
51
+
52
+ #estbalish the question to be asked
53
+ # question = transcribe
54
+
55
+ # #I feel like I need another step here so that the model takes the question, goes to the db and knows that it needs to look for the answer to the question
56
+ # # I am wondering if I need to setup an extraction algorithm here, but then how do I link the extraction algorithm to the database?
57
+ # #Creating link to db
58
+ # # I am also wondering if there should be an api for the model to call in order to access the database? Thinking that might be more better?
59
+ # sqlite_db_path = 'sqlite:///database.db'
60
+ # db = SQLDatabase.from_uri(f'sqlite:///{sqlite_db_path}')
61
+
62
+ # db_chain = SQLDatabaseChain(llm-llm, database=db)
63
+
64
+ # db_results = db_chain.run(transcribe)
65
+
66
+ #After retrieving the data from the database, have llm summarize the data and return the answer to the question
67
+
68
+ # with open(db_results) as file:
69
+ # text = file.read()
70
+
71
+
72
+ # text_splitter = RecursiveCharacterTextSplitter(separators = ['\n\n', '\n'], chunk_size = 100, chunk_overlap = 0)
73
+ # docs = text_splitter.create_documents([text])
74
+
75
+ # chain = load_summarize_chain(llm=llm, chain_type = 'map_reduce')
76
+
77
+ # output = chain.run(docs)
78
+
79
+ # #Setup for the model to recevie a question and return the answer
80
+ # context = output
81
+
82
+
83
+ # answer = llm(context+question)
84
+
85
+
86
+ # def save_as_doc(answer, filename):
87
+ # doc=Document()
88
+ # #not sure what the data will look like, as to what the keys and values will be, so just putting a place holder
89
+ # for key, value in minutes.items():
90
+ # heading = ' '.join(word.capitalize() for word in key.split('_'))
91
+ # doc.add_heading(heading, level=1)
92
+ # doc.add_paragraph(value)
93
+ # doc.add_page_break()
94
+ # doc.save(f'{filename}.docx')
95
+
96
+ #Next part is to take the saved docx file and convert it to an audio file to be played back to the user