File size: 7,047 Bytes
e7a3196 | 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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | import os
import json
from gradio_client import Client
# from gradio_client_updated import Client
'''LOAD ENVIRONMENT VARIABLES'''
from dotenv import load_dotenv
load_dotenv()
APP_API_ENDPOINT = os.getenv('APP_API_ENDPOINT')
ADMIN_USER = os.getenv('ADMIN_USERNAME')
ADMIN_PWD = os.getenv('ADMIN_PASSWORD')
HF_TOKEN = os.getenv('APP_API_HF_TOKEN')
'''APP APIs'''
def googleAuth_api(access_token, user, scope, session_data):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
access_token_json=json.dumps(access_token),
user_json=json.dumps(user),
scope=scope,
session_data_json=json.dumps(session_data),
api_name="/predict")
api.close()
return response
def checkDB_api(row_id_value=None, column=None, table=None, row_id_type=None, null_check=False, all=False):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
row_id_value=row_id_value,
column=column,
table=table,
row_id_type=row_id_type,
null_check=null_check,
all=all,
api_name="/predict_1")
api.close()
return response
def checkUser_api(row_id_value,row_id_type):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
row_id_value=row_id_value,
row_id_type=row_id_type,
api_name="/predict_2")
api.close()
return response
def syncNotion_api(row_id_value,row_id_type,refresh,max_depth):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
row_id_value=row_id_value,
row_id_type=row_id_type,
refresh=refresh,
max_depth=max_depth,
api_name="/predict_3")
api.close()
return response
def updateDB_api(row_id_value,update_data,table,row_id_type,column):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
row_id_value=row_id_value,
update_data_json=json.dumps(update_data),
table=table,
row_id_type=row_id_type,
column=column,
api_name="/predict_4")
api.close()
return response
def notionAuth_api(access_code,redirect_uri,session_data):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
access_code=access_code,
redirect_uri=redirect_uri,
session_data_json=json.dumps(session_data),
api_name="/predict_5")
api.close()
return response
def notionCreatePage_api(parent_page_id, page_title, icon, properties_json, notion_access_token, parent_page_type):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
parent_page_id=parent_page_id,
page_title=page_title,
icon=icon,
properties_json=json.dumps(properties_json),
notion_access_token=notion_access_token,
parent_page_type=parent_page_type,
api_name="/predict_6")
api.close()
return response
def notionUpdatePage_api(parent_id, block_json, notion_access_token, parent_block_type):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
parent_id=parent_id,
block_json=json.dumps(block_json),
notion_access_token=notion_access_token,
parent_block_type=parent_block_type,
api_name="/predict_7")
api.close()
return response
def invokeLLM_api(description,force_json,temperature,top_p,llm,model,llm_key,def_env_var,custom_data):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
description=description,
force_json=force_json,
temperature=temperature,
top_p=top_p,
llm=llm,
model=model,
llm_key=llm_key,
def_env_var=def_env_var,
custom_data=custom_data,
api=True,
api_name="/predict_8")
api.close()
return response
def getLabels_api(userinfo_json):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
userinfo_json=json.dumps(userinfo_json),
api_name="/predict_9")
api.close()
return response
def addSession_api(curr_user_id, id_type, session_json):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
curr_user_id=curr_user_id,
id_type=id_type,
session_json=json.dumps(session_json),
api_name="/predict_10")
api.close()
return response
def deleteUser_api(curr_user_id, id_type, session_data_json):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
curr_user_id=curr_user_id,
id_type=id_type,
session_data_json=json.dumps(session_data_json),
api_name="/predict_11")
api.close()
return response
def insertDB_api(data_json:dict, table:str):
if ('/app1/' in APP_API_ENDPOINT) or ('/app/' in APP_API_ENDPOINT):
api = Client(APP_API_ENDPOINT,auth=(ADMIN_USER,ADMIN_PWD),hf_token=HF_TOKEN)
api = Client(APP_API_ENDPOINT,hf_token=HF_TOKEN)
response = api.predict(
table=table,
data_json=json.dumps(data_json),
api_name="/predict_12")
api.close()
return response
|