gt4python: Working with Python inside Glamorous Toolkit

esug 42 views 11 slides Sep 25, 2024
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

Talk from ESUG 2024

"gt4python: Working with Python inside Glamorous Toolkit"

PDF: http://archive.esug.org/ESUG2024/day4/03-gt4python.pdf


Slide Content

Python Examples |

prine(*nere 4s this going?)

Python Examples Il

from collections 4
counter = Coumter()

for $ An range(100)
counter [random.randint(0, 10)

Python Examples Ill

Prine #iteraeh)

Python Debugger

boapptication := PRapptics

Parpplication uniquelnstance: pbipptication
ef 4 recurse(o)
pbbreak()
sarecurse(a*})

_recurse(a)

PythonBridge custom views for pandas DataFrame
and Series

Dore otthemastwellhnow Python > rates pans a at anis and manipulation oo

‘Thefllowing Python sourcecode fie adds number o remos Plow iews forthe min Dtaframe

internal consul ang gens tote esting Python pads Uataframe an eres ass

The flaca defined ex mpeetito see th contents
pandasviews := FileLocator: gtResource. / ‘Feenkcon’ / *gt4python' /
"python" 7 "view pandas.py"

Gin he ath above, we can adhe code programma it the aba tpl esto

Pekgplication isRuming Sffalse: [ Padpptication start
Poapplication uniquetnstance instal UtoduLe: "pandas:

PanppLication do: [ tapplication |
application newComandStringractory
Sendhnawase ]

Youcantetthe views by lading ad inspen DstaFrame from an example CSV fe

moviercavPath := Filelocator gtResource / 'feerkcom" / gtootkit-denos!

moviercavPathString := noviesCevPath resolve pathString

import: pandas
pandas rend, cav(noviescevPathstring)

Inspecting Python objects with custom inspectors

[moro Toot wore th other runtime. For example, we can work Python » though
Prnenörige > But what might be lesbos is that we can alo eed the nepectr ing
Python

csvFile +2 (FileLocator gtResource / ‘feenkcon! /

Had y 'movies.cov!) fulilane

eto twith sands, and d at west setup the Python runtime by instant pardas
module (8: Youmigh nd instal pipe fst)

Parpplication- isRunning» ifFalse: [ PaApplication. star

From gtoolkit_beidge Import gtView

def _ init__(self, series)
rares = series

etview
(def gevtewescription(self, builder)
text = builder. tenteditor()
text. tte ("Description")
text aetString(str(self.serser))

def geviewetafte(self, builder)
Uist = builder columedt ist,
elise. title(*Deeatls")
elise priority(20)
USE. Mons (lambda Uist (sel serses.tndex))
‘CUist column("Key", Lambda each: each)
Ast.columnt Value’, Lambda each: str (self series(each)))
eList set accessor (Lambda each: setf.sertes[each])

def Lime Get, dataFrone)
Tera = datarrone

size(seur)
return Len(seUf df index)

rovieatPosition(self, Inder)
return Hovie(self-dF” Loc index)

Values = self-df Directors") .astypeste) unique ()
valves. sore()

Visualizing tokenization

Dea pubs Loin, open-source Pan ray ha tokens input strings siti one
Ananas the produc. Ti me forestmaing ss well ensrng put sy within,
ran bts (context windows ee) opera aa els on ns bay neral lor instance to
‘timate he costo ane tue po
To evaluate e eu o token with various mals youcan work ict wäh the doen
send feina the geooliie_iktokertze module:

PenppLication teRuming- ifFalse: [ PAApplication. start 1

Paapplication. uniqueinstance. instatiWoduler "toolkit ciktokentze"

odtenjuseveat the Python script
Import gtoolkit_eiktokenize

model = "gra
String = "ejim starti>systenlin.sepl>You are a helpful asststantc| m_end|><]
in.start|>asstatante|in-sep|>How con I help Yourcl im_end]><] in. start ]puser<]
can os ad to ond uo fr ma elo

GelinTokenizer new
Tokenizehessages: (GtLlasystenMessage new content: "You are a helpful
GELImUserlessoge new content: "Can you add two and two for me?)

on
Exploring the execution of a Python LampSort
algorithm

Potente ne an np mate

Setup

random. somple(range(209

einen the bon spe ato shad stow an cv Pon conection,

(rare plementation Quant Quer

Fesult 2 Lonpsort0 Lanpsor® (numbers copy())-sort()