Skip to content

singlaamitesh/ChatBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎙️ AI Voice Chatbot

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.

✨ Features

  • 🎤 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

🛠️ Prerequisites

  • 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)

📝 Environment Setup

  1. 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
  2. Set up environment variables Create a .env file in the root directory and add your Hugging Face API key:

    HUGGINGFACE_API_KEY=your_api_key_here

    Replace your_api_key_here with the token you obtained from Hugging Face.

🚀 Installation

  1. Clone the repository

    git clone https://github.com/singlaamitesh/ChatBot.git
    cd ChatBot
  2. 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
  3. Install dependencies

    pip install -r requirements.txt

    This will install:

    • gradio: For the web interface
    • SpeechRecognition: For voice input processing
    • sounddevice & soundfile: For audio handling
    • python-dotenv: For environment variable management
    • huggingface-hub: For interacting with Hugging Face models

🏃‍♂️ Running the Application

  1. Start the application

    python app.py

    The application will start and provide a local URL (typically http://localhost:7860).

  2. Using the Chatbot

    • Voice Chat Tab:

      1. Click the microphone button
      2. Speak clearly into your microphone
      3. Click "Stop" when finished speaking
      4. The AI will process your speech and respond with both text and speech
    • Text Chat Tab:

      1. Type your message in the text box
      2. Press Enter or click "Send"
      3. The AI will respond with both text and speech
    • Clear Conversation: Use the "Clear Conversation" button to start a new chat session

  3. 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 .env file

🎯 Example Commands

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?"

🛠️ Troubleshooting

Common Issues

  1. 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
  2. Hugging Face API Errors

    • Verify your API key in the .env file
    • Check your Hugging Face account for valid tokens
    • Ensure you have sufficient credits/quota for the Zephyr 7B Beta model
  3. 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
  4. Audio Playback

    • Ensure your system volume is up and not muted
    • Check sound output device settings
    • The application uses macOS native say command - verify it works in terminal

Getting Help

If you encounter any issues not covered here, please:

  1. Check the Issues page
  2. Include details about:
    • Your operating system version
    • Python version (python --version)
    • Any error messages received
    • Steps to reproduce the issue
    • Monitor API usage limits

📝 Customization

Changing the AI's Personality

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

Adding New Features

  • Customize voice settings: Modify the text_to_speech function to use different voices or adjust speaking rate
  • Enhance speech recognition: Adjust recognizer settings in process_audio function
  • Add new models: Integrate different Hugging Face models by updating the API endpoint
  • Save conversation history: Add functionality to persist conversations to a database

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages