Skip to content

Instantly share code, notes, and snippets.

View pemagrg1's full-sized avatar
:octocat:
working...

Pema Gurung pemagrg1

:octocat:
working...
View GitHub Profile
@pemagrg1
pemagrg1 / convert_envyml_to_reqtxt
Created April 22, 2020 17:51
convert environment.yml to requirement.txt
import ruamel.yaml
yaml = ruamel.yaml.YAML()
data = yaml.load(open('environment.yml'))
requirements = []
for dep in data['dependencies']:
if isinstance(dep, str):
package, package_version, python_version = dep.split('=')
if python_version == '0':
"""
Github Source: https://github.com/unitaryai/detoxify
saving a glimpse of https://www.section.io/engineering-education/building-a-toxicity-classifier/
Toxicity detection using Detoxify
pip install detoxify
"""
from detoxify import Detoxify
predictor = Detoxify('multilingual')
print(predictor.predict('Why are you so fat?'))
@pemagrg1
pemagrg1 / textonimage.py
Created February 24, 2022 11:58
Adding text on multiple images. (Can be used specially for invitation cards)
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
names = ["Pema", "Gurung", "Pema Gurung"]
for name in names:
myFont = ImageFont.truetype(
'/Downloads/precious/Precious.ttf', 65)
"""
In audio production, a sample rate (or "sampling rate") defines how many times per second a sound is sampled.
Technically speaking, it is the frequency of samples used in a digital recording.
"""
import numpy as np
from scipy.io import wavfile
sampleRate = 100
frequency = 10
audio_length = 1 #second
"""
regex based to search if a page is inner page or home page or category page.
"""
import re
def url_check(url):
url = url.split("/")
url = list(filter(None, url))
if "http" in url[0]:
import pickle
Project_path = "<path to project>"
model_path = Project_path + "/08. Multi-class_text_classification/models/model.pickle"
vectorizer_path = Project_path + "/08. Multi-class_text_classification/models/vectorizer.pickle"
vectorizer = pickle.load(open(vectorizer_path,'rb'))
model = pickle.load(open(model_path,'rb'))
pred = model.predict(vectorizer.transform(["i have got a new phone. its from Apple.. and i love it!"]))[0]
print ("predicted class:", pred)
from sklearn.feature_extraction.text import TfidfVectorizer
import pandas as pd
from sklearn import svm
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import pickle
from sklearn import linear_model
Project_path = "<path to the project folder>"
def get_total(df):
df.loc['Total'] = pd.Series(df['Marks'].sum(), index = ['Marks'])
return df
df = pd.DataFrame({'Subjects': ["Maths","Science","English"], 'Marks': [80,90,75]})
df = df.reindex(columns=['Subjects','Marks'])
df = get_total(df)
df
"""
Get total of each column values
"""
def totalcount(data):
return data.assign(Total=data.drop('Total', errors='ignore', axis=1).sum(1))
def pandas_get_total_row(df):
df = df.pipe(totalcount).T.pipe(totalcount).T
return df
@pemagrg1
pemagrg1 / one hot encoding using Tensorflow
Created January 10, 2019 10:52
one hot encoding using Tensorflow
import tensorflow as tf
import pandas as pd
text = 'My cat is a great cat'
tokens = text.lower().split()
vocab = set(tokens)
vocab = pd.Series(range(len(vocab)), index=vocab)
word_ids = vocab.loc[tokens].values