Repository: vra/talkGPT4All Branch: main Commit: f2ba7d85eb93 Files: 9 Total size: 10.9 KB Directory structure: gitextract_xl3nwft_/ ├── .gitignore ├── BUILD.md ├── LICENSE ├── README.md ├── pyproject.toml ├── requirements.txt ├── src/ │ └── talkgpt4all/ │ ├── __init__.py │ └── chat.py └── tests/ └── example_test.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] *$py.class # C extensions *.so # Distribution / packaging .Python build/ develop-eggs/ dist/ downloads/ eggs/ .eggs/ lib/ lib64/ parts/ sdist/ var/ wheels/ pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg *.egg MANIFEST # PyInstaller # Usually these files are written by a python script from a template # before PyInstaller builds the exe, so as to inject date/other infos into it. *.manifest *.spec # Installer logs pip-log.txt pip-delete-this-directory.txt # Unit test / coverage reports htmlcov/ .tox/ .nox/ .coverage .coverage.* .cache nosetests.xml coverage.xml *.cover *.py,cover .hypothesis/ .pytest_cache/ # Translations *.mo *.pot # Django stuff: *.log local_settings.py db.sqlite3 db.sqlite3-journal # Flask stuff: instance/ .webassets-cache # Scrapy stuff: .scrapy # Sphinx documentation docs/_build/ # PyBuilder target/ # Jupyter Notebook .ipynb_checkpoints # IPython profile_default/ ipython_config.py # pyenv .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies # having no cross-platform support, pipenv may install dependencies that don't work, or not # install all needed dependencies. #Pipfile.lock # PEP 582; used by e.g. github.com/David-OConnor/pyflow __pypackages__/ # Celery stuff celerybeat-schedule celerybeat.pid # SageMath parsed files *.sage.py # Environments .env .venv env/ venv/ ENV/ env.bak/ venv.bak/ # Spyder project settings .spyderproject .spyproject # Rope project settings .ropeproject # mkdocs documentation /site # mypy .mypy_cache/ .dmypy.json dmypy.json # Pyre type checker .pyre/ ================================================ FILE: BUILD.md ================================================ Build package and publish to pypi: ```bash rm -rf dist/* python3 -m build python3 -m twine upload dist/* ``` ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2023 Yunfeng Wang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: README.md ================================================ # talkGPT4All A voice chatbot based on GPT4All and talkGPT. [Video demo](https://www.zhihu.com/zvideo/1625779747656515584). Please check more details in this [blog post (in Chinese)](https://zhuanlan.zhihu.com/p/632592897). If you are looking for the older version of talkGPT4All, please checkout to [dev/v1.0.0](https://github.com/vra/talkGPT4All/tree/dev/v1.0.0) branch. ## Installation ### Install using pip (Recommend) talkgpt4all is on PyPI, you can install it using simple one command: ```bash pip install talkgpt4all ``` ### Install from source code Clone the code: ```bash git clone https://github.com/vra/talkGPT4All.git ``` Install the dependencies and talkGPT4All in a python virtual environment: ```bash cd python -m venv talkgpt4all source talkgpt4all/bin/activate pip install -U pip pip install -r requirements.txt ``` ## Extra dependencies for Linux users We use [pyttsx3](https://github.com/nateshmbhat/pyttsx3) to convert text to voice. Please note that on Linux ,You need to install dependencies: ```bash sudo apt update && sudo apt install -y espeak ffmpeg libespeak1 ``` ## Usage Open a terminal and type `talkgpt4all` to begin: ```bash talkgpt4all ``` ### Use different LLMs You can choose different LLMs using `--gpt-model-type `, all available choices: ```python { "ggml-gpt4all-j-v1.3-groovy" "ggml-gpt4all-j-v1.2-jazzy" "ggml-gpt4all-j-v1.1-breezy" "ggml-gpt4all-j" "ggml-gpt4all-l13b-snoozy" "ggml-vicuna-7b-1.1-q4_2" "ggml-vicuna-13b-1.1-q4_2" "ggml-wizardLM-7B.q4_2" } ``` ### Use different Whisper models You can choose whisper model type using `--whisper-model-type `, all available choices: ```python { "tiny.en" "tiny" "base.en" "base" "small.en" "small" "medium.en" "medium" "large-v1" "large-v2" "large" } ``` ### Tune voice rate You can tune the voice rate using `--voice-rate `, default rate is 165. the larger the speak faster. e.g., ```bash talkgpt4all --whisper-model-type large --voice-rate 150 ``` ## RoadMap + [x] Add source building for llama.cpp, with more flexible interface. + [x] More LLMs + [x] Add support for contextual information during chating. + [ ] Test code on Linux,Mac Intel and WSL2. + [ ] Add support for Chinese input and output. + [ ] Add Documents and Changelog contributions are welcomed! ================================================ FILE: pyproject.toml ================================================ [build-system] requires = ["hatchling"] build-backend = "hatchling.build" [project] name = "talkgpt4all" version = "2.1.1" authors = [ { name="Yunfeng Wang", email="wyf.brz@gmail.com" }, ] description = "A voice chatbot based on GPT4All and OpenAI Whisper, running on your PC locally" readme = "README.md" requires-python = ">=3.7" classifiers = [ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", ] dependencies = [ "gpt4all", "openai-whisper", "playsound", "SpeechRecognition", "TTS", ] [project.scripts] talkgpt4all = "talkgpt4all.__init__:main" [project.urls] "Homepage" = "https://github.com/vra/talkGPT4All" "Bug Tracker" = "https://github.com/vra/talkGPT4All/issues" ================================================ FILE: requirements.txt ================================================ gpt4all openai-whisper playsound SpeechRecognition TTS ================================================ FILE: src/talkgpt4all/__init__.py ================================================ import argparse from .chat import GPT4AllChatBot def main(): parser = argparse.ArgumentParser() parser.add_argument( "--gpt-model-name", type=str, default="ggml-gpt4all-j-v1.3-groovy", help="""GPT4All model name, All available names: [ ggml-gpt4all-j-v1.3-groovy ggml-gpt4all-j-v1.2-jazzy ggml-gpt4all-j-v1.1-breezy ggml-gpt4all-j ggml-gpt4all-l13b-snoozy ggml-vicuna-7b-1.1-q4_2 ggml-vicuna-13b-1.1-q4_2 ggml-wizardLM-7B.q4_2 ggml-stable-vicuna-13B.q4_2 ] """, ) parser.add_argument( "--whisper-model-type", type=str, default="base", help="whisper model type, default is base", ) parser.add_argument( "--voice-rate", type=int, default=165, help="voice rate, default is 165, the larger the speak faster", ) args = parser.parse_args() chat_bot = GPT4AllChatBot( args.gpt_model_name, args.whisper_model_type, args.voice_rate ) while True: chat_bot.run() ================================================ FILE: src/talkgpt4all/chat.py ================================================ import argparse import os import subprocess import tempfile from gpt4all import GPT4All from playsound import playsound import speech_recognition as sr from TTS.api import TTS class GlowTTS: def __init__(self): self.tts = TTS(model_name="tts_models/en/ljspeech/glow-tts", progress_bar=False) def process(self, text, audio_save_path): return self.tts.tts_to_file(text=text, file_path=audio_save_path) class GPT4AllChatBot: """Voice chat bot based on Whisper and GPT4All""" def __init__(self, gpt_model_name, whisper_model_type, tts_rate=165): print(f"==> GPT4All model: {gpt_model_name}, Whisper model: {whisper_model_type}") self.gpt_model = GPT4All(gpt_model_name, allow_download=True) self.whisper_model_type = whisper_model_type self.voice_recognizer = sr.Recognizer() self.mic = sr.Microphone() self.tts_engine = GlowTTS() def run(self): """Run the listen-think-response loop""" input_words = self._voice_to_text() answer = self.run_gpt(input_words) self._text_to_voice(answer) def _voice_to_text(self): """Listen voice and convert voice to text using OpenAI Whisper""" print("Listening...") with self.mic as source: self.voice_recognizer.adjust_for_ambient_noise(source) audio = self.voice_recognizer.listen(source) transcript = self.voice_recognizer.recognize_whisper( audio, self.whisper_model_type ) return transcript def run_gpt(self, question): """Run GPT4All model with input_data as input""" with self.gpt_model.chat_session(): answer = self.gpt_model.generate(prompt=question) print("==> answer:", answer) return answer def _text_to_voice(self, answer): """Convert text to voice using TTS tools""" tmp_file = tempfile.NamedTemporaryFile( prefix="talkgpt4all-", suffix=".wav", delete=False ) tmp_dir = os.path.dirname(tmp_file.name) try: try: audio = self.tts_engine.process(answer, tmp_file.name) except RuntimeError: print( "Errors occur when converting anwser to audio. please try another question." ) return playsound(tmp_file.name) finally: tmp_file.close() os.remove(tmp_file.name) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument( "-m", "--gpt-model-name", type=str, default="mistral-7b-openorca.Q4_0.gguf", help="""GPT4All model name, All available names: [ mistral-7b-openorca.Q4_0.gguf mistral-7b-instruct-v0.1.Q4_0.gguf gpt4all-falcon-q4_0.gguf orca-2-7b.Q4_0.gguf orca-2-13b.Q4_0.gguf wizardlm-13b-v1.2.Q4_0.gguf nous-hermes-llama2-13b.Q4_0.gguf gpt4all-13b-snoozy-q4_0.gguf mpt-7b-chat-merges-q4_0.gguf orca-mini-3b-gguf2-q4_0.gguf replit-code-v1_5-3b-q4_0.gguf starcoder-q4_0.gguf rift-coder-v0-7b-q4_0.gguf all-MiniLM-L6-v2-f16.gguf em_german_mistral_v01.Q4_0.gguf ] """, ) parser.add_argument( "-w", "--whisper-model-type", type=str, default="base", help="whisper model type, default is base", ) parser.add_argument( "--voice-rate", type=int, default=165, help="voice rate, default is 165, the larger the speak faster", ) args = parser.parse_args() chat_bot = GPT4AllChatBot( args.gpt_model_name, args.whisper_model_type, args.voice_rate ) while True: chat_bot.run() ================================================ FILE: tests/example_test.py ================================================