Skip to content

Instantly share code, notes, and snippets.

View pranshuj73's full-sized avatar
💭
La poésie est dans la rue

Pranshu Jha pranshuj73

💭
La poésie est dans la rue
View GitHub Profile
@pranshuj73
pranshuj73 / tweeter.py
Last active April 26, 2020 00:00
code section 1
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
class Tweeter:
def login(self):
username = "your username/email will go here"
password = "and your password shall go here"
# opens up the browser window
@pranshuj73
pranshuj73 / tweeter.py
Last active April 26, 2020 00:01
code section 2
# everything here is a part of login function of Tweeter class
# Now we need to find the field where we want to type in the username/email
uname_field = driver.find_element_by_name("session[username_or_email]")
# typing the username
# Note: it's important to press tab using Keys.TAB after typing the username
# to switch to the password field (or we can add extra lines of code to click on it)
uname_field.send_keys(username, Keys.TAB)
# selecting the password field
pass_field = driver.find_element_by_name("session[password]")
@pranshuj73
pranshuj73 / tweeter.py
Last active April 26, 2020 00:01
code section 3
# This function is a part of Tweeter class which will allow us to tweet
def tweet(self):
tweet_text = input("Enter your tweet here: ")
driver = self.driver
sleep(3)
# finds the compose tweet button
tweet_btn = driver.find_element_by_xpath("//a[@aria-label=\"Tweet\"]")
tweet_btn.click()
@pranshuj73
pranshuj73 / tweeter.py
Last active April 26, 2020 00:03
Final Version of Selenium Twitter Bot
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
class Tweeter:
@classmethod
def login(self):
username = "your username/email will go here"
password = "and your password shall go here"
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
class Tweeter:
def __init__(self, username, password):
self.username = username
self.password = password
self.driver = webdriver.Chrome() # opens up the browser window
classes = {
0: 'Angry', 1: 'Disgust', 2: 'Fear', 3: 'Happy', 4: 'Sad', 5: 'Surprise', 6: 'Neutral'
}
# this is for the transforms
train_trfm = transforms.Compose(
[
transforms.ToPILImage(),
transforms.Grayscale(num_output_channels=1),
transforms.RandomCrop(48, padding=4, padding_mode='reflect'),
transforms.RandomHorizontalFlip(),
transforms.ToTensor(),
transforms.Normalize((0.5), (0.5), inplace=True)
])
# Creating the class for our dataset for the FER
class FERDataset(Dataset):
def __init__(self, images, labels, transforms):
self.X = images
self.y = labels
self.transforms = transforms
def __len__(self):
return len(self.X)
batch_num = 400
train_dl = DataLoader(train_data, batch_num, shuffle=True, num_workers=4, pin_memory=True)
val_dl = DataLoader(val_data, batch_num*2, num_workers=4, pin_memory=True)
def accuracy(outputs, labels):
_, preds = torch.max(outputs, dim=1)
return torch.tensor(torch.sum(preds==labels).item()/len(preds))
class FERBase(nn.Module):
# this takes is batch from training dl
def training_step(self, batch):
images, labels = batch
out = self(images) # calls the training model and generates predictions