Raphael AI Assistant

A deep learning based virtual assistant with natural language processing capabilities

Project Overview

Raphael is an intelligent virtual assistant built using Python and TensorFlow/Keras for natural language understanding. It combines deep learning with practical functionality like system control, web browsing, and conversation.

💬

Natural Language Processing

Uses TensorFlow/Keras with custom-trained models to understand user intents and respond appropriately.

🎙️

Voice Interaction

Supports both text and voice commands using speech recognition and text-to-speech synthesis.

⚙️

System Control

Can open/close applications, adjust volume, check system status, and more.

Technical Architecture

The project consists of several key components working together:

Core Modules

Key Dependencies

TensorFlow/Keras pyttsx3 SpeechRecognition NumPy scikit-learn pyautogui psutil

Intent Recognition

The assistant understands user queries through a trained neural network that classifies input text into predefined intent categories.

Sample Intents

Greeting

Responds to hello, hi, greetings

Patterns: "Hi there", "Hello", "Good day"
Responses: "Hello", "Good to see you again"

Jokes

Tells random jokes

Patterns: "Tell me a joke", "Make me laugh"
Responses: Various humorous responses

System Control

Manages applications and settings

Commands: "Open calculator", "Volume up", "Close notepad"

The complete intent schema includes many more categories like goodbye, thanks, datetime queries, identity questions, and more.

Code Examples

Main Application (main.py)

main.py
import pyttsx3
import speech_recognition as sr
import datetime, os, time, webbrowser
import pyautogui 
import sys
import psutil
import json, pickle, random
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.sequence import pad_sequences
import numpy as np

# Initialization code omitted for brevity...

def speak(text):
    engine = initialize_engine()
    print(f"SPEAKING: {text}")
    engine.say(text)
    engine.runAndWait()

def command():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        r.adjust_for_ambient_noise(source, duration=0.5)
        print("Listening.....", end="", flush=True)
        audio = r.listen(source)
    try:
        query = r.recognize_google(audio, language="en-in")
        print(f"User said: {query}")
    except Exception as e:
        print("Say that again please")
        return "None"
    return query

# More functions omitted...

Model Training (model_train.py)

model_train.py
import json
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Embedding, GlobalAveragePooling1D
from tensorflow.keras.preprocessing.text import Tokenizer
from tensorflow.keras.preprocessing.sequence import pad_sequences
from sklearn.preprocessing import LabelEncoder
import pickle

with open("intents.json") as file:
    data = json.load(file)

# Prepare training data
training_sentences = []
training_labels = []
labels = []
responses = []

for intent in data["intents"]:
    for pattern in intent['patterns']:
        training_sentences.append(pattern)
        training_labels.append(intent['tag'])
    responses.append(intent['responses'])

    if intent['tag'] not in labels:
        labels.append(intent['tag'])

# Encode labels
label_encoder = LabelEncoder()
label_encoder.fit(training_labels)
training_labels = label_encoder.transform(training_labels)

# Tokenize text
tokenizer = Tokenizer(num_words=1000, oov_token="<OOV>")
tokenizer.fit_on_texts(training_sentences)
sequences = tokenizer.texts_to_sequences(training_sentences)
padded_sequences = pad_sequences(sequences, truncating='post', maxlen=20)

# Build model
model = Sequential([
    Embedding(1000, 16, input_length=20),
    GlobalAveragePooling1D(),
    Dense(16, activation='relu'),
    Dense(16, activation='relu'),
    Dense(len(labels), activation='softmax')
])

model.compile(loss='sparse_categorical_crossentropy', 
              optimizer='adam', 
              metrics=['accuracy'])

# Train model
history = model.fit(padded_sequences, np.array(training_labels), epochs=1000)

# Save model and tokenizers
model.save("chat_model.h5")
with open("tokenizer.pkl", "wb") as f:
    pickle.dump(tokenizer, f)
with open("label_encoder.pkl", "wb") as encoder_file:
    pickle.dump(label_encoder, encoder_file)

Getting Started

Installation

To set up Raphael on your system:

Terminal
# Clone the repository
git clone https://github.com/Frosty-8/frosty-8-raphael-bot.git

# Navigate to project directory
cd frosty-8-raphael-bot

# Install dependencies
pip install -r requirements.txt

# Train the model (optional - pre-trained model included)
python model_train.py

# Run the assistant
python main.py

Requirements

requirements.txt
tensorflow>=2.0
pyttsx3==2.90
SpeechRecognition==3.8.1
numpy>=1.19.5
pyautogui>=0.9.53
psutil>=5.8.0
scikit-learn>=0.24.2

Features & Capabilities

Conversational AI

  • Natural language understanding
  • Contextual responses
  • Multiple response variations
  • Emotional intelligence (responds to compliments/insults)

System Integration

  • Open/close applications
  • Volume control
  • System monitoring (CPU, battery)
  • Schedule management

Web Services

  • Web browsing
  • Social media integration
  • Google searches

Example Commands

"Hello Raphael" - Initiates conversation
"What's the time?" - Provides current time
"Tell me a joke" - Shares a humorous response
"Open calculator" - Launches calculator app
"Volume up" - Increases system volume
"What's my schedule?" - Reads today's schedule
"System condition" - Reports CPU and battery status
"Open LinkedIn" - Launches LinkedIn in browser