This code implements a voice assistant using Streamlit, Langchain, and Cohere. It provides a user interface for interacting with the assistant, transcribing audio, and retrieving information from a knowledge base.
Key Features
Audio Transcription: Records audio using Streamlit's audio recorder and transcribes it using the Cohere Whisper API.
Knowledge Base: Uses Langchain's DeepLake to store and retrieve embeddings from a set of documentation.
Chat Interface: Provides a Streamlit-based chat interface for interaction with the assistant.
Text-to-Speech: Converts the assistant's responses to audio using Pyttsx3.
Running the Code
Set up Environment:
Install required Python packages: pip install -r requirements.txt
Set API Keys:
Create a .env file in the project directory and set the following environment variables:
COHERE_API_KEY: Your Cohere API Key
Create a Dataset:
Create a DeepLake dataset for storing embeddings, following the instructions in the code (lines 24-26).
Run the Script:
Execute the code using streamlit run voice_assistant.py
Interact with the Assistant:
Use the chat interface or record audio to interact with the assistant.
Code Breakdown
Load Documents: The code loads and splits documentation files to create chunks for embedding.
Embed and Store: CohereEmbeddings are used to create embeddings for the document chunks, which are then stored in a DeepLake database.
Search and Retrieve: The assistant searches the DeepLake database based on user input and retrieves the most relevant information.
Chat Interface: The display_conversation function handles the display of chat messages and audio playback.
Text-to-Speech: The text_to_speech_pyttsx3 function converts the assistant's responses to speech using Pyttsx3.