added apis page
Browse files89 unmodified lines9091929394951005 unmodified lines1101110211031104110511061107712 unmodified lines1820182118221823182418251826182789 unmodified linesDEMO_USERPWD = 'f0_demo_pwd'SAMPLE_NOTION_TOKEN = 'secret_ab9XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'SAMPLE_NOTION_PAGE_ID = f'EXAMPLE PAGEID: {PUBLIC_NOTION_PAGE_ID}''''CODE'''1005 unmodified lines# _public_queries, _public_titles = get_sample_queries(_action_id,filtered_data,data_type='USER')# return _public_queries, _public_titles# APP PAGES (GRADIO)with gr.Blocks(theme='gradio/base',712 unmodified linesfn=load_demo_view,inputs=None,outputs=[email0,connect_to_notion2])# main_demo.queue(max_size=5)app = gr.mount_gradio_app(app, main_app, path=APP_URL, auth_dependency=get_user)app = gr.mount_gradio_app(app, main_app, path=APP_ALTERNATE_ROUTE, auth=pwd_auth)89 unmodified lines909192939495961005 unmodified lines110211031104110511061107712 unmodified lines1820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197789 unmodified linesDEMO_USERPWD = 'f0_demo_pwd'SAMPLE_NOTION_TOKEN = 'secret_ab9XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'SAMPLE_NOTION_PAGE_ID = f'EXAMPLE PAGEID: {PUBLIC_NOTION_PAGE_ID}'API_URL = "/apis"'''CODE'''1005 unmodified lines# _public_queries, _public_titles = get_sample_queries(_action_id,filtered_data,data_type='USER')# return _public_queries, _public_titles# APP PAGES (GRADIO)with gr.Blocks(theme='gradio/base',712 unmodified linesfn=load_demo_view,inputs=None,outputs=[email0,connect_to_notion2])# main_app.queue(max_size=5)# API PAGES (GRADIO)with gr.Blocks() as api_page:with gr.Tabs() as tabs:with gr.TabItem(label="APIs", id=0, interactive=False) as gr_apis:def google_auth_api(access_token_json: str, user_json: str, scope: str, session_data_json: json):access_token = json.loads(access_token_json)user = json.loads(user_json)session_data = json.loads(session_data_json)result = google_auth_db_sync(access_token, user, scope, session_data)return resultgoogleAuth_api = gr.Interface(fn=google_auth_api,inputs=["text", "text", "text", "json"], # JSON strings for access_token and useroutputs="json")def check_with_db_api(row_id_value: str, column: str, table: str, row_id_type: str, null_check: bool, all: bool):data, count = check_data(row_id_value, column, table, row_id_type, null_check, all)return datacheckDB_api = gr.Interface(fn=check_with_db_api,inputs=["text", "text", "text", "text",gr.Checkbox(label="Null Check for Row ID", value=False),gr.Checkbox(label="All Rows", value=False)], # Inputs for email, column, table, and row_id_typeoutputs="json")def check_user_api(row_id_value: str, row_id_type: str):data, count = check_user(row_id_value, type=row_id_type)return datacheckUser_api = gr.Interface(fn=check_user_api,inputs=["text", "text"], # Inputs for email & row_id_typeoutputs="json")def sync_notion_pages_api(row_id_value:str,row_id_type:str,refresh:bool,max_depth:int):return parse_user_pages(row_id_value,user_type=row_id_type,refresh=refresh,max_depth=max_depth)syncNotion_api = gr.Interface(fn=sync_notion_pages_api,inputs=["text","text",gr.Checkbox(label="Refresh", value=False),gr.Number(label="Max Depth", value=2, step=1)],outputs="json")def update_db_api(row_id_value:str,update_data_json:json,table:str,row_id_type:str,column:str):data_to_update = json.loads(update_data_json)data, count = update_data(row_id=row_id_value,data=data_to_update,table=table,row_id_type=row_id_type,column=column)return dataupdateDB_api = gr.Interface(fn=update_db_api,inputs=["text","json","text","text","text"],outputs="json")def notion_auth_api(access_code:str,redirect_uri:str,session_data_json:json):session_data = json.loads(session_data_json)notion_auth_db_sync(access_code,redirect_uri,session_data)return NonenotionAuth_api = gr.Interface(fn=notion_auth_api,inputs=["text","text","json"],outputs=None)def create_notionPage_api(parent_page_id:str, page_title:str, icon:str, properties_json:json, notion_access_token:str, parent_page_type:str):try:properties = json.loads(properties_json)new_page = create_page(parent_id=parent_page_id, title=page_title, icon=icon, properties=properties, cover_image=True, notion_key=notion_access_token, parent_type=parent_page_type)return new_pageexcept Exception as e:print(str(e))return {"Error": str(e)}createNotionPage_api = gr.Interface(fn=create_notionPage_api,inputs=["text","text","text","json","text","text"],outputs="json")def update_notionPage_api(parent_id:str, block_json:json, notion_access_token:str, parent_block_type:str):try:block_json = json.loads(block_json)process_blueprint(parent_id=parent_id, block_json=block_json, notion_key=notion_access_token, parent_type=parent_block_type)return {"Success": True}except Exception as e:print(str(e))return {"Success": False, "Error": str(e)}updateNotionPage_api = gr.Interface(fn=update_notionPage_api,inputs=["text","json","text","text"],outputs="json")def invoke_llm_api(description:str,force_json:bool,temperature:float,top_p:float,llm:str,model:str,llm_key:str,def_env_var:bool,custom_data:str,api:bool):try:if api:response, chunks = invoke_llm(description,force_json,temperature,top_p,llm,model,llm_key,def_env_var,custom_data,api=api)return chunkselse:response = invoke_llm(description,force_json,temperature,top_p,llm,model,llm_key,def_env_var,custom_data,api=api)return responseexcept Exception as e:print(str(e))return {"Error": str(e)}invokeLLM_api = gr.Interface(fn=invoke_llm_api,inputs=["text",gr.Checkbox(),gr.Number(),gr.Number(),"text","text","text",gr.Checkbox(),"text",gr.Checkbox()],outputs="json")def get_labels_api(userinfo_json:json):userinfo = json.loads(userinfo_json)return get_labels(userinfo=userinfo)getLabels_api = gr.Interface(fn=get_labels_api,inputs="json",outputs=gr.DataFrame())def add_session_api(curr_user_id:str, id_type:str, session_json:json):try:session = json.loads(session_json)session_data = add_session(curr_user_id, id_type, session)return {"Success": True, "session_data": session_data}except Exception as e:print(str(e))return {"Success": False, "Error": str(e)}addSession_api = gr.Interface(fn=add_session_api,inputs=["text", "text", "json"],outputs="json")def delete_user_api(curr_user_id:str, id_type:str, session_data_json:json):try:session_data = json.loads(session_data_json)delete_user(curr_user_id,id_type,session_data)return {"Success": True}except Exception as e:print(str(e))return {"Success": False, "Error": str(e)}deleteUser_api = gr.Interface(fn=delete_user_api,inputs=["text", "text", "json"],outputs="json")def insert_data_api(table:str,data_json:json):try:data = json.loads(data_json)insert_data(data,table)return {"Success": True}except Exception as e:print(str(e))return {"Success": False, "Error": str(e)}insertDB_api = gr.Interface(fn=insert_data_api,inputs=["text","json"],outputs="json")app = gr.mount_gradio_app(app, api_page, path=API_URL)app = gr.mount_gradio_app(app, main_app, path=APP_URL, auth_dependency=get_user)app = gr.mount_gradio_app(app, main_app, path=APP_ALTERNATE_ROUTE, auth=pwd_auth)
app.py+152-2