Make your first AI Assistant in python. No complex setup, No advance coding. Just install configure and run!
Install pythonaibrain package.
pip install pythonaibrain==1.0.2- Camera
- TTS
- TTI
- ITT
- STT
- Context
- Brain
- Advance Brain
PyAI supports Camera to click photos and make videos, it can save photos or videos and also send Images and Videos to PyAI to take answer
For start your camera
# Import modules
import pyai
from pyai import Camera
import tkinter as tk
from tkinter import *
root = tk.Tk() # Create the GUI
Camera(root) # Call the Function and pass the master as root
root.mainloop() # Start GUI appFrom this you can easly use camera in your program.
TTS stands for Text To Speech, it convert text into both Male voice and Female voice.
# Import modules
import pyai
from pyai import TTS
tts = TTS(text = 'Hello World')
tts.say(voice= 'Male') # for male voice
tts.say(voice= 'Female') #for female voicetts.say() -> By default it takes Male voice tts.say(voice= 'Male') -> Pass the voice as Male tts.say(voice= 'Female') -> Pass the voice as Female
STT stands for Speech TO Text, which means it can easly convert any audio to text.
# Import Important functions
import pyai
from pyai import STT
stt = STT() # Call the class
text = stt.outputs() # stt.outputs() -> returns textstt.outputs() -> It directly record the voice and return the text
TTI stands for Text To Image, which means from a single prompt or a text you can generate images.
# Import modules
import pyai
from pyai import TTI
text = 'Generate an image of white color dog siting on a ground'
tti = TTI(text= text) # pass the text, you can also change it
tti.display() # For display the generated image
tti.save(folder_name = 'Dog.png') # For save the generated image you can also leave it bydefault it takes file name as output.pngTTI(text: str, data_dir: str = 'assert', json_file: str = "dataset.json") -> None:You can also provide your custom dataset
ITT stands for Image To Text, it can extract text from a given image
# Import modules
import pyai
from pyai import ITT
itt = ITT(file_path = 'example.jpeg') # You can change example.jpeg from your file name
text = itt.outputs() # It returns the text extract from the given imageITT(file_path: str)Give your own file path.
It is a module in pyai which can able to extract answers from the give context
# Import modules
import pyai
from pyai import Contexts
context = '''
Patanjali Ayurved is an Indian company. It was founded by Baba Ramdev and Acharya Balkrishna in 2006.
'''
question = 'Who founded Patanjali Ayurved?'
contexts = Contexts()
answer = contexts.ask(context= context, question= question)Or, Also
# Import modules
import pyai
from pyai import Contexts as contexts
context = '''
Patanjali Ayurved is an Indian company. It was founded by Baba Ramdev and Acharya Balkrishna in 2006.
'''
question = 'Who founded Patanjali Ayurved?'
answer = contexts.ask(context= context, question= question)It's a simple brain module which configure the input message.
It classify the input message and find the type of message, like
- Question
- Answer
- Command
- Shutdown
- Make Directory
- Statement
- Name
- Know
- Start
It also extract the name, location, and age from the given message, by using NER.
The Brain Module classify the given message weather it is a question or something else if answer then returns Question.
The Brain Module classify the given message weather it is a answer or something else if answer then returns Answer.
The Brain Module classify the given message weather it is a command or something else if command then returns Command
The Brain Module also classify the given message weather the given command shutdown or not if it is then it shutdown your device and it returns Shutdown
But there are few issue releated to it :
- This command doesn't support website to run this command, because it need a terminal support.
- This doesn't run or work on Android, IOS.
The Brain Module also classify the given message weather the given command Make Directory or not if it is then it create a Directory on your device and returns Make Dir.
It generally comes under File handling of the PyAI Module which is also known as fh.
The Brain Module also classify the given message weather the given command statement or not, if it is then it statement then it returns Statement.
Statement -> It means a simple text which is not a question, answer, command, etc... It a simple text. Like for example:
The sun rises in the east.
The Brain Module also classify the given message weather the given command name or not, if it is then it name then it returns Name.
Name -> It means the input message is caring name or specify the name like
I'm Divyanshu.
Myself Divyanshu.
Divyanshu Sinha
Know is similar to Statement.
Do you know ___ ?
Like that.
The Brain Module also classify the given message weather the given command start or not, if it is then it start any thing on your device and it returns Start.
Like:
Start www.youtube.com
Or,
Start Notepad
But it have issue:
- It doesn't works with website, because it support terminals like CMD for Window and etc.
- It also doesn't works in Android, IOS.
You should know how to create a intents.json for run this Brain Module.
{
"intents":[{
"tag": "greeting",
"patterns": ["Hi", "Hello", "Hey", "What's up?", "Howdy", "Greetings", "Hi there", "Is anyone there?", "Yo!"],
"responses": ["Hello! How can I help you today?", "Hey there!", "Hi! What can I do for you?"]
},
{
"tag": "bye",
"pattern": ["By", "See you soon", "See u soon", "Take care"],
"responce":["Bye! have a greate day", "See you"]
},
]
}From this way you can create your own database.
Remember this Database file in .json
To use Brain Module we should import Brain from PyAI
from pyai import BrainAfter importing the Module we use it in our main program as,
brain = Brain(intents_path= r'.\intents.json') # Use can replace .\intents.json with you database file name but extention should be same (.json)After this, we predict the message type of we can say classify the message
message = input('Message : ')
message_type = brain.predict_message_type(message= message) # On using predict_message_type() function we get the type of message is (question, answer, statement, command, shutdown, make directory, name, know, etc...)By gating the message type, we find the perfect answer for the message
if message_type in ['Question', 'Answer']:
print(f'Answer : {brain.process_messages(message = message)}')From these things you can create your own AI Assistant. But this is basic.
For Advance we can use Advance Brain Module.
This is advance version of Brain Module It work like Brain but smartly.
It classify the input message and find the type of message, like
- Question
- Answer
- Command
- Shutdown
- Make Directory
- Statement
- Name
- Know
- Start
It also extract the name, location, and age from the given message, by using NER.
The Brain Module classify the given message weather it is a question or something else if answer then returns Question.
The Brain Module classify the given message weather it is a answer or something else if answer then returns Answer.
The Brain Module classify the given message weather it is a command or something else if command then returns Command
The Brain Module also classify the given message weather the given command shutdown or not if it is then it shutdown your device and it returns Shutdown
But there are few issue releated to it :
- This command doesn't support website to run this command, because it need a terminal support.
- This doesn't run or work on Android, IOS.
The Brain Module also classify the given message weather the given command Make Directory or not if it is then it create a Directory on your device and returns Make Dir.
It generally comes under File handling of the PyAI Module which is also known as fh.
The Brain Module also classify the given message weather the given command statement or not, if it is then it statement then it returns Statement.
Statement -> It means a simple text which is not a question, answer, command, etc... It a simple text. Like for example:
The sun rises in the east.
The Brain Module also classify the given message weather the given command name or not, if it is then it name then it returns Name.
Name -> It means the input message is caring name or specify the name like
I'm Divyanshu.
Myself Divyanshu.
Divyanshu Sinha
Know is similar to Statement.
Do you know ___ ?
Like that.
The Brain Module also classify the given message weather the given command start or not, if it is then it start any thing on your device and it returns Start.
Like:
Start www.youtube.com
Or,
Start Notepad
But it have issue:
- It doesn't works with website, because it support terminals like CMD for Window and etc.
- It also doesn't works in Android, IOS.
You should know how to create a intents.json for run this Advance Brain Module.
{
"intents":[{
"tag": "greeting",
"patterns": ["Hi", "Hello", "Hey", "What's up?", "Howdy", "Greetings", "Hi there", "Is anyone there?", "Yo!"],
"responses": ["Hello! How can I help you today?", "Hey there!", "Hi! What can I do for you?"]
},
{
"tag": "bye",
"pattern": ["By", "See you soon", "See u soon", "Take care"],
"responce":["Bye! have a greate day", "See you"]
},
]
}From this way you can create your own database.
Remember this Database file in .json
To use Advance Brain Module we should import Brain from PyAI
from pyai import AdvanceBrainAfter importing the Module we use it in our main program as,
advance_brain = AdvanceBrain(intents_path= r'.\intents.json') # Use can replace .\intents.json with you database file name but extention should be same (.json)After this, we predict the message type of we can say classify the message
message = input('Message : ')
message_type = advance_brain.predict_message_type(message= message) # On using predict_message_type() function we get the type of message is (question, answer, statement, command, shutdown, make directory, name, know, etc...)By gating the message type, we find the perfect answer for the message
if message_type in ['Question', 'Answer']:
print(f'Answer : {advance_brain.process_messages(message = message)}')| Module Name | Description |
|---|---|
| Brain | It is use to create Brain for AI by passing .json file (or, Knowledge for Brain) |
| AdvanceBrain | It is use to create Advance Brain for AI by passing .json file (or, Knowledge for Brain). It can understand better than Brain |
| TTS | Convert text into Voice |
| STT | Convert Voice into Text |
| TTI | Convert Text into Image |
| ITT | Convert Or, extract Image into Text |
| Camera | Use camera to click photos and make videos |
| Context | Get Answer from the context for the respective question |
If you don't want to create your own AI assistant by coding or you want to see how this modules work you can also use PyBrain which is a built-in python AI assistance, provided by pythonaibrain == 1.0.2
python -m PyBrain -g
By using this you can use PyBrain in GUI.
Or,
python -m PyBrain -w
By using this you can use PyBrain in Web.
Or,
python -m PyBrain -h
By using this Help panel open.