Posts

Showing posts from July, 2021

NATURAL LANGUAGE PROCESSING ... :)

  We are going to learn what is Natural Language Processing or NLP for short .. We will start with the basics like 'sentence tokenization' and 'word tokenization' and work our way to build a crappy model that can predict whether you are a boy or a girl by analysing your name ... Installing package : pip install nltk Then we have to import nltk and download some stuff ... The code for this is ... : import nltk # we need this for PunktSentenceTokenizer nltk.download( 'punkt' ) # we need this for removing stop words nltk.download( 'stopwords' ) # interface for tagging each token in a sentence with supplementary information nltk.download( 'averaged_perceptron_tagger' ) # for classifying names nltk.download( 'names' ) But let's first understand what is nltk .. ? The Natural Language Toolkit (NLTK) is a platform used for building Python programs that work with human language data for applying in statistical natural language processing (NLP)

PAINT PROGRAM IN PYTHON ..

Image
  Why use MS Paint when we can build our own paint program .. The source code : # pip install PyQt5 # importing libraries from PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import * import sys class Window(QMainWindow): def __init__ ( self ): super (). __init__ () # setting title self .setWindowTitle( "Paint" ) # setting geometry to main window self .setGeometry( 100 , 100 , 800 , 600 ) # creating image object self .image = QImage( self .size() , QImage.Format_RGB32) # making image color to white self .image.fill(Qt.white) # variables # drawing flag self .drawing = False # default brush size self .brushSize = 2 # default color self .brushColor = Qt.black # QPoint object to tract the point self .lastPoint = QPoint() # creating menu bar mainMenu = self .menuBar() # creating file menu fo

LIVE STREAMING .. (with Python and HTML)

Image
LIVE STREAMING ..  Create a main.py file in the directory named live_streaming .. The code for main.py # pip install flask # pip install opencv-python from flask import Flask , render_template , Response import cv2 app = Flask(__name__) camera = cv2.VideoCapture( 0 ) def gen_frames (): while True : success , frame = camera.read() if not success: break else : ret , buffer = cv2.imencode( '.jpg' , frame) frame = buffer.tobytes() yield ( b'--frame \r\n ' b'Content-Type: image/jpeg \r\n\r\n ' + frame + b' \r\n ' ) @app.route ( '/' ) def index (): return render_template( 'index.html' ) @app.route ( '/video_feed' ) def video_feed (): return Response(gen_frames() , mimetype = 'multipart/x-mixed-replace; boundary=frame' ) if __name__ == "__main__" : app.run( debug = True ) Create a directory named templates ... and

Random Password Generator in Python ..

Image
 Random Password Generator in Python .. the source code : # pip install pyperclip import random import pyperclip from tkinter import * from tkinter.ttk import * # Function for calculation of password def low (): entry.delete( 0 , END) # Get the length of password length = var1.get() lower = "abcdefghijklmnopqrstuvwxyz" upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 !@#$%^&*()" password = "" # if strength selected is low if var.get() == 1 : for i in range ( 0 , length): password = password + random.choice(lower) return password # if strength selected is medium elif var.get() == 0 : for i in range ( 0 , length): password = password + random.choice(upper) return password # if strength selected is strong elif var.get() == 3 : for i in range ( 0 , length): password

2048 game in Python ..

Image
 2048 game in Python (without installing any modules ..) the source code : from tkinter import * from tkinter import messagebox import random class Board: bg_color = { '2' : '#eee4da' , '4' : '#ede0c8' , '8' : '#edc850' , '16' : '#edc53f' , '32' : '#f67c5f' , '64' : '#f65e3b' , '128' : '#edcf72' , '256' : '#edcc61' , '512' : '#f2b179' , '1024' : '#f59563' , '2048' : '#edc22e' , } color = { '2' : '#776e65' , '4' : '#f9f6f2' , '8' : '#f9f6f2' , '16' : '#f9f6f2' , '32' : '#f9f6f2' , '64' : '#f9f6f2' , '128' : '#f9f6f2' , '256' : '#f9