This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, json, jsonify, request, Response, Blueprint | |
app = Flask(__name__) | |
user = Blueprint('user', __name__) | |
userInfoMap = {"1": {"firstname": "sourav", "lastname": "kumar"}, | |
"2": {"firstname": "elon", "lastname": "musk"}, | |
"3": {"firstname": "jenny", "lastname": "cooper"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, jsonify, request | |
app = Flask(__name__) | |
userInfoMap = {"1": {"firstname": "sourav", "lastname": "kumar"}, | |
"2": {"firstname": "elon", "lastname": "musk"}, | |
"3": {"firstname": "jenny", "lastname": "cooper"}} | |
@app.route('/user/fetch-info') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title> | |
EVENTS PROPOGATION | |
</title> | |
<style> | |
#first{ | |
height: 150px; | |
width: 150px; | |
background-color: red; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
positional arguments: | |
| arguments | details | | |
| ------------- | ------------- | | |
| dir_path | Output working directory | | |
| query | Query string to search for | | |
| API | API KEY FOR GOOGLE CUSTOM SEARCH API | | |
| CX | CUSTOM SEARCH ENGINE ID | | |
| imgSize | Size of image [icon/small/medium/large/xlarge/xxlarge/huge] | | |
| imgType | Type of image[clipart/face/lineart/stock/photo/animated] | | |
| imgColorType | Color of image[color/gray/mono] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function for downloading images using Google API | |
def download_images(dir_path, query, API, CX, imgSize, imgType, imgColorType, counter=0): | |
# check if given directory already exists | |
if not os.path.isdir(dir_path): | |
print("Image scraping using Google Custom Image Search Engine API....") | |
# lists of links / urls to be stored | |
urls = [] | |
for i in range(0, 100, 10): | |
# Making GET requests to google API | |
source = requests.get(f'https://www.googleapis.com/customsearch/v1?key={API}&cx={CX}&q={query}&searchType=image&imgSize={imgSize}&imgType={imgType}&imgColorType={imgColorType}&num=10&start={i}').text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Convert to integers and privately share the dataset | |
private_test_loader = [] | |
for data, target in test_loader: | |
private_test_loader.append(( | |
data.fix_prec().share(alice, bob, crypto_provider=crypto_provider), | |
target.fix_prec().share(alice, bob, crypto_provider=crypto_provider) | |
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def train_and_test(e): | |
epochs = e | |
train_losses , test_losses = [] , [] | |
valid_loss_min = np.Inf | |
model.train() | |
print("training started...") | |
for epoch in range(epochs): | |
running_loss = 0 | |
batch = 0 | |
#scheduler.step() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
model = Net().to(device) | |
optimizer = optim.SGD(model.parameters(), lr=args.lr) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Net(nn.Module): | |
def __init__(self): | |
super(Net, self).__init__() | |
self.fc1 = nn.Linear(784, 500) | |
self.fc2 = nn.Linear(500, 10) | |
def forward(self, x): | |
x = x.view(-1, 784) | |
x = self.fc1(x) | |
x = F.relu(x) | |
x = self.fc2(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# plotting the images of loaded batch with given fig size and frame data | |
import torchvision | |
import matplotlib.pyplot as plt | |
import numpy as np | |
grid = torchvision.utils.make_grid(images.get(), nrow = 20, padding = 2) | |
plt.figure(figsize = (20, 20)) | |
plt.imshow(np.transpose(grid, (1, 2, 0))) | |
print('labels:', labels.get()) |