Download components/gradio/api.py from finding0/app: direct link, hf CLI and curl.
- Browser
- Download file 7.05 kB
-
https://huggingface.co/spaces/finding0/app/resolve/main/components/gradio/api.py
- Command line
-
hf download hf://spaces/finding0/app/components/gradio/api.py
-
curl -L -o api.py https://huggingface.co/spaces/finding0/app/resolve/main/components/gradio/api.py
7.05 kB
| 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 | |