Slide 1

Slide 1 text

CONSUMING AND BUILDING APIS DURING HACKATHONS 12TH OCTOBER 2023 WILLIAM MCKEE

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

AGENDA About Me / Hackathons Hackathons / Projects Learnings / Tools Get Involved / Resources Contact / QA

Slide 4

Slide 4 text

ABOUT WILLIAM Currently based in Auckland Study at Massey Uni & do dev contract work Enjoy travel, drawing, coding, video games

Slide 5

Slide 5 text

ABOUT TECHNICAL Self taught Python during Art school (2011) Started attending hackathons & conferences Moved to Sydney worked as developer and attended hackathons

Slide 6

Slide 6 text

WHAT ARE HACKATHONS? Friday. Meet and greet. Team forming. Pizza. Saturday. Working on the project. Sunday. Clearing loose ends and presenting. 48 hour research and development projects. Could be run as public or company internal event. In person or online.

Slide 7

Slide 7 text

SPACEGIF NASA Space Apps - October 2018 Creating gifs from NASA photography

Slide 8

Slide 8 text

NASA EARTH IMAGE REQUEST import requests import os import arrow import shutil blogdir = '/Users/williammckee/Developer/spacegif-output' thedate = '2019-05-20' rqnat = requests.get('https://epic.gsfc.nasa.gov/api/ natural/date/' + thedate + '?api_key=DEMO_KEY') rjsn = rqnat.json() lenet = len(rjsn) somnewd = arrow.get(rjsn[0]['date']) images = [] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

MERGE OF EARTH + MARS dateinput = arrow.get(thedate) foldate = dateinput.strftime('%Y/%m/%d') spaceimg = os.listdir('{}/galleries/{}/template/'.format(bl ranc = random.choice(os.listdir('{}/galleries/{}/rovers/'.f rancam = '{}/galleries/{}/rovers/{}/'.format(blogdir, folda fileran = random.choice(os.listdir(rancam)) ranmar = '{}/{}'.format(rancam, fileran) marimg = PIL.Image.open('{}'.format(ranmar)) marimg = marimg.resize([512,512]) marimg = marimg.convert('RGB') for spci in spaceimg: earimg = PIL.Image.open('{}/galleries/{}/template/{}'.for earimg= earimg.resize([512,512]) earimg = earimg.convert('RGB') 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

INPUT TEXT & GENERATE GIF msg = 'hello apidaysau' dateinput = arrow.get(thedate) msgslug = msg.replace(' ', '-') spaceimg = os.listdir(blogdir + '/galleries/' + dateinput.strftime('%Y/%m/%d') + '/blend/') for spci in spaceimg: earim = PIL.Image.open(blogdir + '/galleries/' + dateinput.strftime('%Y/%m/%d') + '/blend/' + spci) earsm = earim.resize([512,512]) earimg = earsm.convert("RGBA") font = ImageFont.truetype(fontdir,42) draw = ImageDraw.Draw(earimg) image_width, image_height = earimg.size y_text = 256 lines = textwrap.wrap(msg, width=20) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

RESULT

Slide 15

Slide 15 text

Wrap the app with FastAPI

Slide 16

Slide 16 text

TECHNICAL ME CONT. Moved back to NZ Wanted something fresh so learnt: Then learnt (and continue to use):

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

SPAMSCAMEMAIL Terrible Ideas Hackathon - July 2021 Generate scam emails

Slide 19

Slide 19 text

GENERATING FAKE PERSON AND A CURRENCY Ellen Jacobs of Wells, United Kingdom | ENS func Requestperson() (string, error) { url := "https://randomuser.me/api/" res, err := http.Get(url) if err != nil { return "", err } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { return "", err } var data struct { Results []Person `json:"results"` } err = json.Unmarshal(body, &data) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Slide 20

Slide 20 text

GETTING A RANDOM COMPANY THE FAIRFIELD CHASE CENTRE PTY LTD func getCompanyName() (string, error) { rand.Seed(time.Now().UnixNano()) rannm := rand.Intn(3075362) + 1 url := "https://data.gov.au/data/api/3/action/datastore_s resp, err := http.Get(url) if err != nil { return "", err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return "", err } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Slide 21

Slide 21 text

LATEST AW WEBSITE VISIT & PUTTING IT TOGETHER func Requestweb() string { url := `http://localhost:5600/api/0/` + `buckets/aw-watcher-web-chrome/events?limit=1` res, err := http.Get(url) if err != nil { fmt.Println(err) } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Slide 22

Slide 22 text

RESULT OUTPUT Wrap the function in Gin. Frontend built in React sends email with EmailJS. { "message": Hello, My name is Ellen Jacobs of Wells, United Kin My company is THE FAIRFIELD CHASE CENTRE PTY LTD. On Fri, 22 S 2023 05:44:19 you visited the url http://localhost:8080/body. You must send 100,000,000 ENS via this link: example.com withi 7 days. If you do not I will tell your friends and family that visited the site. Be kind, Ellen Jacobs of Wells, United Kingd }

Slide 23

Slide 23 text

HUGMORTY So you think you can hack - May 18 till Jun 18, 2023 AI image generator with Rick & Morty prompts

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

GENERATE SENTENCE FROM R&M "Evolved Narnian Disguised as Morty the Male Humanoid from Narnia Dimension is Alive." import { NextApiRequest, NextApiResponse } from "next"; import { HfInference } from '@huggingface/inference' const hf = new HfInference(process.env.HF_ACCESS_TOKEN) import { getCharacter } from 'rickmortyapi' import { writeFileSync } from 'fs'; import { Amplify, Storage } from 'aws-amplify'; import awsconfig from '../../aws-exports'; Amplify.configure(awsconfig); export default async function handler(req: NextApiRequest, const { query: { prompt}, method, } = req; const randomChar = Math.random() * (826 - 1) + 1; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Slide 26

Slide 26 text

"a painting of a woman with a cat on her head " const fetchImg = await fetch(char.data.image) const arrayBuffer = await fetchImg.arrayBuffer(); const buffer = Buffer.from(arrayBuffer); const imgclas = await hf.imageToText({ data: buffer, model: 'nlpconnect/vit-gpt2-image-captioning' }) 1 2 3 4 5 6 7 8

Slide 27

Slide 27 text

const imgCap = await hf.textToImage({ inputs: sentence + " " + imgclas.generated_text + " " + p //model: 'ogkalu/Comic-Diffusion', model: 'DucHaiten/DH_ClassicAnime' }) const aBuffer = await imgCap.arrayBuffer(); const timestamp = Number(new Date()); const fileUrl = output.input + '-' + timestamp + ".png" Storage.put(fileUrl, aBuffer, {contentType: "image/png"}); const signedURL = await Storage.get(fileUrl); res.status(200).json({'imageurl': signedURL}); 1 2 3 4 5 6 7 8 9 10 11 12 13 14

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

LEARNINGS Great opotunity to learn new languages or libraries Collabration is key. Relax. Not every hackathon works out. There is always next time.

Slide 30

Slide 30 text

HACKATHON RESOURCES Directory HackAUS - Hackathons - DevPost - Upcoming NASA Space Apps - October. Terrible Ideas Hackathon - 8-10 December 2023. NZ/AU/UK GovHack - August(?) 2024. https://www.hackathonsaustralia.com/ https://www.hackathons.com.au/ https://devpost.com/ https://terriblehack.com/

Slide 31

Slide 31 text

CONTACT / QA

Slide 32

Slide 32 text

Email: Linkedin: [email protected] https://www.linkedin.com/in/w-mckee/

Slide 33

Slide 33 text

No content