CoolFace
Apppublic

wldmr/transcriptifier-st-hf7

sourceHugging Facecc-by-nc-3.0updated 3y agoView on Hugging Face
0likes
mysheet.py42 linesDownload Raw Back to root
1import streamlit as st2#from google.oauth2 import service_account3import pandas as pd4import gspread5import json6 7def get_gspread_connection():8    # Create a connection object.9    # credentials = service_account.Credentials.from_service_account_info(10    #     st.secrets["gcp_service_account"],11    #     scopes=[12    #         "https://www.googleapis.com/auth/spreadsheets",13    #     ],14    # )15    #client = gspread.authorize(credentials)16 17    st_credentials = st.secrets["gcp_service_account"]18    if type(st_credentials) is str:19        print("INFO: transforming str to dict")20        credentials_dict = json.loads(st_credentials, strict=False)21        client = gspread.service_account_from_dict(credentials_dict)22    else:23        print("INFO: using credentials in dict")24        client = gspread.service_account_from_dict(st_credentials)25 26 27    st_sheet_url = st.secrets["private_gsheets_url"]28    spreadsheet = client.open_by_url(st_sheet_url)29    worksheet = spreadsheet.get_worksheet(0)30    return worksheet31 32#@st.cache_data33def read_gspread():34    worksheet = get_gspread_connection()35    df = pd.DataFrame(worksheet.get_all_records())36    return df37 38def write_gspread(df):39    #df.loc[len(df)] = ['Mia','worst']40    worksheet = get_gspread_connection()41    worksheet.update([df.columns.values.tolist()] + df.values.tolist())42