An interactive voice-enabled chatbot that uses the Hugging Face Inference API with Zephyr 7B Beta model for natural language processing. This application provides a seamless voice and text-based chat interface built with Python and Gradio.
- 🎤 Real-time voice recognition using SpeechRecognition library
- 💬 Text-based chat interface with conversation history
- 🔊 Text-to-speech using macOS native 'say' command
- 🎙️ Background listening with noise adjustment
- 🌐 Hugging Face Inference API integration with Zephyr 7B Beta model
- 🚀 Fast and responsive web interface built with Gradio
- 🔒 Secure API key management with python-dotenv
- 📦 Easy installation with pip
- Python 3.8 or higher
- macOS (required for native text-to-speech)
- Microphone (for voice input)
- Speakers or headphones (for voice output)
- Internet connection (for Hugging Face API)
- Hugging Face account (to get API key)
-
Get a Hugging Face API Key
- Create an account at Hugging Face if you don't have one
- Go to your profile → Settings → Access Tokens
- Create a new token with read access
-
Set up environment variables Create a
.envfile in the root directory and add your Hugging Face API key:HUGGINGFACE_API_KEY=your_api_key_here
Replace
your_api_key_herewith the token you obtained from Hugging Face.
-
Clone the repository
git clone https://github.com/singlaamitesh/ChatBot.git cd ChatBot -
Set up a virtual environment (recommended)
# Create virtual environment python3 -m venv venv # Activate virtual environment # On macOS/Linux: source venv/bin/activate # On Windows: # .\venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
This will install:
gradio: For the web interfaceSpeechRecognition: For voice input processingsounddevice&soundfile: For audio handlingpython-dotenv: For environment variable managementhuggingface-hub: For interacting with Hugging Face models
-
Start the application
python app.py
The application will start and provide a local URL (typically http://localhost:7860).
-
Using the Chatbot
-
Voice Chat Tab:
- Click the microphone button
- Speak clearly into your microphone
- Click "Stop" when finished speaking
- The AI will process your speech and respond with both text and speech
-
Text Chat Tab:
- Type your message in the text box
- Press Enter or click "Send"
- The AI will respond with both text and speech
-
Clear Conversation: Use the "Clear Conversation" button to start a new chat session
-
-
Troubleshooting
- If you encounter any issues, make sure:
- Your microphone is properly connected and allowed in system preferences
- You have a stable internet connection
- Your Hugging Face API key is correctly set in the
.envfile
- If you encounter any issues, make sure:
Try these voice or text commands:
- "Hello!" or "Hi"
- "How are you?"
- "What's your name?"
- "Tell me a joke"
- "Thank you"
- "Goodbye"
- "What's the weather like today?"
-
Microphone Access
- On macOS, go to System Preferences > Security & Privacy > Microphone
- Ensure your browser or terminal has microphone access
- Test your microphone with other applications first
-
Hugging Face API Errors
- Verify your API key in the
.envfile - Check your Hugging Face account for valid tokens
- Ensure you have sufficient credits/quota for the Zephyr 7B Beta model
- Verify your API key in the
-
Installation Issues
# If you get port conflicts (port 7860 in use): # Option 1: Change the port in app.py # Option 2: Kill existing processes lsof -i :7860 # Find the process ID kill -9 <PID> # Replace <PID> with the actual process ID
-
Audio Playback
- Ensure your system volume is up and not muted
- Check sound output device settings
- The application uses macOS native
saycommand - verify it works in terminal
If you encounter any issues not covered here, please:
- Check the Issues page
- Include details about:
- Your operating system version
- Python version (
python --version) - Any error messages received
- Steps to reproduce the issue
- Monitor API usage limits
The chatbot uses the Zephyr 7B model from Hugging Face. You can modify the system prompt in app.py:
def generate_response(user_input):
conversation_history.append(f"User: {user_input}")
prompt = "<|system|>\nYou are a helpful AI assistant. Keep responses concise and natural for voice interaction.</s>\n"
# Add your custom system prompt here- Customize voice settings: Modify the
text_to_speechfunction to use different voices or adjust speaking rate - Enhance speech recognition: Adjust recognizer settings in
process_audiofunction - Add new models: Integrate different Hugging Face models by updating the API endpoint
- Save conversation history: Add functionality to persist conversations to a database
This project is licensed under the MIT License - see the LICENSE file for details.
- Gradio for the easy-to-use web interface
- SpeechRecognition for speech-to-text capabilities
- Hugging Face for the Zephyr 7B model and Inference API
- MacOS say command for text-to-speech on macOS
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request