Spaces:
Runtime error
Runtime error
File size: 1,475 Bytes
8907dd8 2605ea7 8907dd8 2605ea7 8907dd8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import redis
import gspread
redis_url = 'redis://default:[email protected]:7369'
r = redis.from_url(redis_url)
gc = gspread.service_account()
# Open a sheet from a spreadsheet in one go
wks = gc.open("Labels").sheet1
rows = [['image id', 'label id', 'author', 'author_id', 'role', 'submitted_on', 'label', 'confidence (0 = low, 1 = medium, 2 = high)', 'image url', 'dashboard url', 'image preview']]
redis_keys = r.keys('label:image:*')
for i_key in redis_keys:
image_data_bytes = r.hgetall(i_key)
image_data = {k.decode('utf-8'): v.decode('utf-8') for k, v in image_data_bytes.items()}
image_id = i_key.decode().split(':')[-2]
raw_image_data_bytes = r.hgetall(f'image:{image_id}'.encode('utf-8'))
raw_image_data = {k.decode('utf-8'): v.decode('utf-8') for k, v in raw_image_data_bytes.items()}
path = f'https://gainforest-transparency-dashboard.s3.amazonaws.com/{raw_image_data["awsCID"]}'
dashboard_url = f'https://gainforest.app/observations/{raw_image_data["uuid"]}'
row = [image_id, i_key.decode().split(':')[-1], image_data['author'], image_data['author_id'], image_data['role'], image_data['timestamp'], image_data['label'], image_data['confidence'], path, dashboard_url,'=IMAGE("{}", 2)'.format(path)]
rows.append(row)
# Update a range of cells using the top left corner address
wks.update('A1', rows, value_input_option='USER_ENTERED')
wks.format('A1:I1', {'textFormat': {'bold': True}}) |