init commit
Browse filesFiles changed (31)
- .DS_Store
- README.md+5-5
- app.py
- components/__init__.pyDeleted
- components/emails/pi_redactor.pyDeleted-1
- components/emails/emails.py → components/fetch_emails.pyRenamed+36-126
- components/gen_ai/linkedin_bio.pyDeleted-1
- components/gen_ai/notion_gen.pyDeleted-153
- components/gradio/api.pyAdded+183
- components/gradio/guides/get_started_guide.mdDeleted-15
- components/notion/architect.py → components/llm_response.pyRenamed+48-143
- components/notion/__init__.pyDeleted
- components/notion/auth.pyDeleted-190
- components/notion/blocks.pyDeleted-654
- components/notion/notion_json.pyDeleted-6
- components/notion/test_scripts/generate_content.pyDeleted-27
- components/notion/test_scripts/process_page.pyDeleted-22
- components/notion/test_scripts/utils.pyDeleted-164
- components/supabase/__init__.pyDeleted
- components/supabase/auth.pyDeleted-30
- components/supabase/db.pyDeleted-146
- components/supabase/storage.pyDeleted-1
- components/test_scripts/fastapi.pyDeleted-13
- components/test_scripts/gmail.pyDeleted-217
- data/google_auth/client_secret.jsonDeleted-1
- data/google_auth/client_secret_desktop.jsonDeleted-1
- data/google_auth/storage.jsonDeleted-1
- data/images/logo.pngDeleted
- data/sample.pyAdded+35
- components/storage/tables.py → data/tables.pyRenamed
- gradio_client_updated.pyAdded+1638
12345678910---title: Finding0emoji: 🔍colorFrom: graycolorTo: bluesdk: dockerpinned: false---Read more about finding0 [here](https://linkedin.com/company/finding0)12345678910---title: Appemoji: 🌍colorFrom: bluecolorTo: greensdk: dockerpinned: false---Read more about finding0 [here](https://linkedin.com/company/finding0)
1# TODO - Create a redactor to remove all personal information like emails, names, profile links, keys, etc.12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777811 unmodified lines909192939495962 unmodified lines9910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116252 unmodified lines21521621721821922099 unmodified lines320321322323324325326327328329330331332import jsonfrom oauth2client import file, client, toolsfrom apiclient import discoveryfrom httplib2 import Httpimport dateutil.parser as parserfrom dateutil import tzimport pandas as pdimport base64import reimport timeimport mathimport osfrom components.supabase.db import check_datafrom dotenv import load_dotenvload_dotenv()SCOPES = ['https://www.googleapis.com/auth/gmail.readonly'] # we are using modify and not readonly, as we will be marking the messages Read# CLIENT_SECRET_FILE = "data/google_auth/client_secret.json"# ACCESS_TOKEN_FILE = os.getenv('ACCESS_TOKEN_FILE') # REPLACE WITH DB_TOOLLABEL_COLS = ['label_id','label_name','messagesTotal','messagesUnread','label_type']LABEL_SAMPLES = [['CATEGORY_PROMOTIONS','CATEGORY_PROMOTIONS',100000,99999,'system']]LABEL_DB = pd.DataFrame(LABEL_SAMPLES, columns=LABEL_COLS)EMAIL_COLS = ['id','label','date','from','email','domain','subject','unsub_links']EMAIL_SAMPLES = [['iAmAAlphaNumericID','CATEGORY_PROMOTIONS','2009-04-01T00:00:00+00:00','SomeBank','creditcardoffer@somebank.com','somebank.com','Go on vacation. Enjoy & come back with debt 😉.','https://somebank.com/weWillHideTheUnsubscribeButtonToTheVeryEndBecauseWeThinkYouHaveShortAttentionSpan&WouldForgetToUnsubscribe']]EMAIL_DB = pd.DataFrame(EMAIL_SAMPLES, columns=EMAIL_COLS)PROCESSING_ERRORS_COLS = ['error']+EMAIL_COLSPROCESSING_ERRORS_SAMPLES = [['Unknown string format: Sun, 1 Apr 2009 00:00:00 +0000 (GMT+00:00)']+EMAIL_SAMPLES[0]]PROCESSING_ERRORS_DB = pd.DataFrame(PROCESSING_ERRORS_SAMPLES, columns=PROCESSING_ERRORS_COLS)EMAIL_SUMMARY_COLS = ['label','from','emailCount']DOMAIN_SUMMARY_SAMPLES = [['CATEGORY_PROMOTIONS','somebank.com',10000]]EMAIL_SUMMARY_DB = pd.DataFrame(DOMAIN_SUMMARY_SAMPLES, columns=EMAIL_SUMMARY_COLS)SENDER_SUMMARY_SAMPLES = [['CATEGORY_PROMOTIONS','creditcardoffer@somebank.com',9999]]SENDER_SUMMARY_DB = pd.DataFrame(SENDER_SUMMARY_SAMPLES, columns=EMAIL_SUMMARY_COLS)UNSUB_COLS = ['label','domain', 'email', 'from', 'emailCount', 'unsub_link']UNSUB_SAMPLES = [['CATEGORY_PROMOTIONS','somebank.com','creditcardoffer@somebank.com','SomeBank',9999,'https://somebank.com/unsubscribeButDontWorryWeWillFindYou']]UNSUB_DB = pd.DataFrame(UNSUB_SAMPLES, columns=UNSUB_COLS)# URL REGEX for finding all types of links:# SUBDOMAIN_REGEX = r"(?:(?<!@)[a-z0-9.\-]+(?:\.[a-z0-9.\-]+)+)"# TLD_REGEX = r"(?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)"# URL_REGEX = r"""(?i)\b((?:https?:(?:/{{1,3}}|[a-z0-9%])|{subdomain_regex}+[.](?:{tld_regex})/)(?:[^\s()<>{{}}\[\]]*|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{{}};:'".,<>?«»“”‘’])|(?:(?<!@)[a-z0-9]+(?:[.\-][a-z0-9]+)*[.]{tld_regex}())\b)""".format(# subdomain_regex=SUBDOMAIN_REGEX, tld_regex=TLD_REGEX)A_TAG_REGEX = r'<a\s+(?:[^>]*?\s+)?href=["\']([^"\']*)["\']([^>]*)>(.*?)<\/a>'# Analyses Gmail0 generates:ANALYSIS_TYPES = ['Sender-wise Unread Emails Analysis','Domain-wise Unread Emails Analysis','Unread Emails','Unsubscribe Links for Unread Emails','Email Processing Errors','Overall']FILE_PATHS = ['data/emails_data/[Gmail0_SAMPLE]_CATEGORY_PROMOTIONS_Sender-wise Unread Emails Analysis.csv','data/emails_data/[Gmail0_SAMPLE]_CATEGORY_PROMOTIONS_Domain-wise Unread Emails Analysis.csv','data/emails_data/[Gmail0_SAMPLE]_CATEGORY_PROMOTIONS_Unread Emails.csv','data/emails_data/[Gmail0_SAMPLE]_CATEGORY_PROMOTIONS_Unsubscribe Links for Unread Emails.csv','data/emails_data/[Gmail0_SAMPLE]_CATEGORY_PROMOTIONS_Email Processing Errors.csv','data/emails_data/[Gmail0_SAMPLE]_CATEGORY_PROMOTIONS_Overall.xlsx']def authenticate_gmail(userinfo:dict=None, refresh:bool=False):""" Authenticates with Gmail API and returns the service object """print("Initiating Gmail authentication flow....")# credentials = pd.read_pickle(CLIENT_SECRET_FILE)# service = build('gmail', 'v1', credentials=credentials)# store = file.Storage(ACCESS_TOKEN_FILE)# creds = store.get()# if not creds or creds.invalid:# flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)# creds = tools.run_flow(flow, store)curr_user = userinfo.get('user','')curr_user_email = curr_user.get('email','')creds_json, count = check_data(curr_user_email, column="gmail_token", table="users", row_id_type="email")if creds_json:_missing_scopes = []for _scope in SCOPES:11 unmodified linesif not creds.invalid:print("Credentials refreshed successfully.")creds_json = creds.to_json()pretty_print_blueprint(creds_json)# TODO - Update auth_response in the databaseexcept client.AccessTokenRefreshError:print("Failed to refresh access token.")2 unmodified linesreturn servicereturn Nonedef pretty_print_blueprint(blueprint_json):print(json.dumps(blueprint_json, indent=4))def get_labels(userinfo:dict):""" Fetches label info including messagesTotal & messagesUnread """print("Fetching labels....")service = authenticate_gmail(userinfo)if service:labels_response = service.users().labels().list(userId='me').execute()labels = labels_response['labels']excluded_labels = []label_db = pd.DataFrame(columns=LABEL_COLS)label_ids = {}for label in labels:if label['name'] not in excluded_labels:# and label['type'] == 'system':label_ids[label['name']] = label['id']label_ = pd.DataFrame.from_dict([{'label_name': label['name'], 'label_type': label['type'], 'label_id': label['id']}])label_db = pd.concat([label_db, label_.reset_index(drop=True)], ignore_index=True)for index, label in label_db.iterrows():try:list_response = service.users().labels().get(userId='me', id=label_ids[label['label_name']]).execute()except Exception as error:print(f"Error fetching label '{label['label_name']}': {error}")list_response = {'name': label['label_name'], 'messagesTotal': -1, 'messagesUnread': -1, 'type': label['label_type'], 'id': label['label_name']}label_db.at[index, 'messagesTotal'] = list_response['messagesTotal']label_db.at[index, 'messagesUnread'] = list_response.get('messagesUnread', 0) # Handle missing 'messagesUnread' keylabel_db = label_db.sort_values(by=['messagesUnread','messagesTotal'], ascending=False)# my_profile = service.users().getProfile(userId='me').execute()# print(my_profile)excluded_labels = ['DRAFT','SENT','STARRED','IMPORTANT','CHAT','UNREAD','TRASH']label_db = label_db[~label_db['label_name'].isin(excluded_labels)]# excluded_types = ['user']# label_db = label_db[~label_db['label_type'].isin(excluded_types)]return label_dbreturn None# Function to extract email from the sender fielddef extract_email(sender):match = re.search(r'<(.+?)>|([^<>\s]+@[^<>\s]+)', sender)if match:email = match.group(1) if match.group(1) else match.group(2)return emailreturn None# Function to extract domain from the sender fielddef extract_domain(sender):email = extract_email(sender)domain = email.split('@')[1] if email else Nonereturn domaindef extract_email_and_domain(sender):email = extract_email(sender)domain = email.split('@')[1] if email else Nonesender_name = sender.replace(email,'')sender_name = sender_name.replace(' <','')sender_name = sender_name.replace('>','')return email, domain, sender_namedef parse_email(service, msg_id, label_id):email = {'id': msg_id,52 unmodified linesemail['unsub_links'] = list(set(unsubscribe_links))return emaildef get_emails(label_id = 'INBOX', num_emails = 20, max_results = 10, userinfo = None):""" Fetches unread emails for a specific label """print(f"Fetching '{num_emails}' unread emails for label '{label_id}'....")99 unmodified linesyield update, sender_counts.head(25), domain_counts.head(25), df.head(25), unsub_db.head(25), error_db.head(25)else:yield "🔴 Error! No connection with GmailAPI. Please reconnect & try again.", sender_counts.head(25), domain_counts.head(25), df.head(25), unsub_db.head(25), error_db.head(25)def get_domain_analysis(emails_by_sender):df = pd.DataFrame(columns=EMAIL_SUMMARY_COLS,data=emails_by_sender)df['domain'] = df['from'].apply(extract_domain)response_db = df.groupby('from')['emailCount'].sum().reset_index(name='emailCount')response_db = response_db.sort_values(by='emailCount', ascending=False)yield response_dbif __name__ == "__main__":pass123456789101112131415161718192021222324252627282930313233343511 unmodified lines4748495051522 unmodified lines55565758596052 unmodified lines11311411511611711811912012112212312412512612712812913013113213313413513613713813914099 unmodified lines240241242import jsonfrom oauth2client import clientfrom apiclient import discoveryfrom httplib2 import Httpimport pandas as pdimport dateutil.parser as parserfrom dateutil import tzimport base64import reimport timeimport mathfrom data.sample import (LABEL_COLS, LABEL_DB,EMAIL_COLS, EMAIL_DB,EMAIL_SUMMARY_COLS, EMAIL_SUMMARY_DB, SENDER_SUMMARY_DB,UNSUB_COLS, UNSUB_DB,PROCESSING_ERRORS_COLS, PROCESSING_ERRORS_DB,ANALYSIS_TYPES, FILE_PATHS)from components.gradio.api import checkDB_apiSCOPES = ['https://www.googleapis.com/auth/gmail.readonly'] # we are using modify and not readonly, as we will be marking the messages ReadA_TAG_REGEX = r'<a\s+(?:[^>]*?\s+)?href=["\']([^"\']*)["\']([^>]*)>(.*?)<\/a>'def authenticate_gmail(userinfo:dict=None, refresh:bool=False):""" Authenticates with Gmail API and returns the service object """print("Initiating Gmail authentication flow....")curr_user = userinfo.get('user','')curr_user_email = curr_user.get('email','')creds_json = Noneresponse = checkDB_api(row_id_value=curr_user_email, column="gmail_token", table="users", row_id_type="email")if response:creds_json = responseif creds_json:_missing_scopes = []for _scope in SCOPES:11 unmodified linesif not creds.invalid:print("Credentials refreshed successfully.")creds_json = creds.to_json()# TODO - Update auth_response in the databaseexcept client.AccessTokenRefreshError:print("Failed to refresh access token.")2 unmodified linesreturn servicereturn Nonedef parse_email(service, msg_id, label_id):email = {'id': msg_id,52 unmodified linesemail['unsub_links'] = list(set(unsubscribe_links))return email# Function to extract email from the sender fielddef extract_email(sender):match = re.search(r'<(.+?)>|([^<>\s]+@[^<>\s]+)', sender)if match:email = match.group(1) if match.group(1) else match.group(2)return emailreturn None# Function to extract domain from the sender fielddef extract_domain(sender):email = extract_email(sender)domain = email.split('@')[1] if email else Nonereturn domaindef extract_email_and_domain(sender):email = extract_email(sender)domain = email.split('@')[1] if email else Nonesender_name = sender.replace(email,'')sender_name = sender_name.replace(' <','')sender_name = sender_name.replace('>','')return email, domain, sender_namedef get_emails(label_id = 'INBOX', num_emails = 20, max_results = 10, userinfo = None):""" Fetches unread emails for a specific label """print(f"Fetching '{num_emails}' unread emails for label '{label_id}'....")99 unmodified linesyield update, sender_counts.head(25), domain_counts.head(25), df.head(25), unsub_db.head(25), error_db.head(25)else:yield "🔴 Error! No connection with GmailAPI. Please reconnect & try again.", sender_counts.head(25), domain_counts.head(25), df.head(25), unsub_db.head(25), error_db.head(25)
1# Inspiration: https://github.com/disciple0/twitterbio123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153import osimport jsonimport codecsfrom openai import OpenAI
# OBJECTIVE - Email categorization into a project management Notion template along with quick summary (insights, sell, request/ask, etc.) of each email# TODO - Use a local fine-tuned model like Ollama & before sending any information to a llm model, redact the information
# https://platform.openai.com/docs/api-reference
'''LOAD ENVIRONMENT VARIABLES'''from dotenv import load_dotenvload_dotenv()OPENAI_KEY = os.getenv('OPENAI_API_KEY')MODEL_NAME = os.getenv('MODEL_NAME')
'''CODE'''def invoke_llm(description, force_json=False, temperature=0.7, top_p=0.2, llm='openai', model=MODEL_NAME, llm_key=None, def_env_var=True, custom_data=None, api=False): print(llm, model) # TO-DO: TRY OLLAMA LOCALLY OR/AND OPEN-SOURCE FINE-TUNED MODELS ON HUGGINGFACE if llm == 'openai': '''LOAD API CLIENT''' _api_key = OPENAI_KEY if not def_env_var: _api_key = os.getenv('OPENAI_API_KEY') if llm_key: _api_key = llm_key client = OpenAI(api_key=_api_key) response = client.chat.completions.create( model=model, response_format={"type": "json_object" if force_json else "text"}, messages=[ { "role": "system", "content": "You are NotionGen, a state-of-the-art template designer for Notion, programmed to create custom JSON blueprints that represent detailed, organized, and highly functional Notion templates. Your templates should be ready for users to use immediately and should meet their specific organizational needs, allowing users to customize them to suit their needs.\n\nYour response must be formatted as a valid JSON object with the following structure:\n{\n \"response\": \"Description of the Notion page based on the user's request.\"\n \"blueprint\": \"Structured JSON blueprint of the Notion page layout according to the provided schema.\"\n}\n\n\"blueprint\" should be a JSON object representing the Notion page you want to create, defined as per the following schema:\n\n```\n{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"definitions\":{\"page\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"page\"]},\"title\":{\"type\":\"string\"},\"children\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/page\"},{\"$ref\":\"#/definitions/database\"},{\"$ref\":\"#/definitions/divider\"},{\"$ref\":\"#/definitions/table_of_contents\"},{\"$ref\":\"#/definitions/heading\"},{\"$ref\":\"#/definitions/paragraph\"},{\"$ref\":\"#/definitions/list\"},{\"$ref\":\"#/definitions/to_do_list\"},{\"$ref\":\"#/definitions/toggle\"},{\"$ref\":\"#/definitions/column_list\"},{\"$ref\":\"#/definitions/callout\"},{\"$ref\":\"#/definitions/quote\"}]}}},\"required\":[\"type\",\"title\",\"children\"],\"additionalProperties\":false},\"database\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"database\"]},\"title\":{\"type\":\"string\"},\"icon\":{\"type\":\"string\"},\"is_inline\":{\"type\":\"boolean\",\"default\":false},\"schema\":{\"type\":\"object\",\"patternProperties\":{\".*\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"checkbox\",\"created_by\",\"created_time\",\"date\",\"email\",\"files\",\"last_edited_by\",\"last_edited_time\",\"multi_select\",\"number\",\"people\",\"phone_number\",\"rich_text\",\"select\",\"title\",\"url\"]},\"format\":{\"type\":\"string\",\"enum\":[\"argentinepeso\",\"baht\",\"australiandollar\",\"canadiandollar\",\"chileanpeso\",\"colombianpeso\",\"danishkrone\",\"dirham\",\"dollar\",\"euro\",\"forint\",\"franc\",\"hongkongdollar\",\"koruna\",\"krona\",\"leu\",\"lira\",\"mexicanpeso\",\"newtaiwandollar\",\"newzealanddollar\",\"norwegiankrone\",\"number\",\"numberwithcommas\",\"percent\",\"philippinepeso\",\"pound\",\"peruviansol\",\"rand\",\"real\",\"ringgit\",\"riyal\",\"ruble\",\"rupee\",\"rupiah\",\"shekel\",\"singaporedollar\",\"uruguayanpeso\",\"yen\",\"yuan\",\"won\",\"zloty\"]},\"options\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"},\"color\":{\"type\":\"string\",\"enum\":[\"blue\",\"brown\",\"default\",\"gray\",\"green\",\"orange\",\"pink\",\"purple\",\"red\",\"yellow\"]}},\"required\":[\"name\",\"color\"]}}},\"dependencies\":{\"format\":{\"properties\":{\"type\":{\"const\":\"number\"}}},\"options\":{\"properties\":{\"type\":{\"enum\":[\"select\",\"multi_select\"]}}}},\"additionalProperties\":false}},\"additionalProperties\":false,\"minProperties\":1}},\"required\":[\"type\",\"title\",\"icon\",\"schema\"],\"additionalProperties\":false},\"divider\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"divider\"]}},\"required\":[\"type\"],\"additionalProperties\":false},\"table_of_contents\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"table_of_contents\"]}},\"required\":[\"type\"],\"additionalProperties\":false},\"heading\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"heading_1\",\"heading_2\",\"heading_3\"]},\"text\":{\"type\":\"string\"}},\"required\":[\"type\",\"text\"],\"additionalProperties\":false},\"paragraph\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"paragraph\"]},\"content\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"string\"},\"style\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"enum\":[\"bold\",\"italic\",\"strikethrough\",\"underline\",\"code\"]},\"default\":[]}},\"required\":[\"text\",\"style\"],\"additionalProperties\":false}}},\"required\":[\"type\",\"content\"],\"additionalProperties\":false},\"list\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"bulleted_list\",\"numbered_list\"]},\"items\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}}},\"required\":[\"type\",\"items\"],\"additionalProperties\":false},\"to_do_list\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"to_do_list\"]},\"items\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"string\"},\"checked\":{\"type\":\"boolean\"}},\"required\":[\"text\",\"checked\"],\"additionalProperties\":false}}},\"required\":[\"type\",\"items\"],\"additionalProperties\":false},\"toggle\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"toggle\"]},\"text\":{\"type\":\"string\"},\"children\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/divider\"},{\"$ref\":\"#/definitions/table_of_contents\"},{\"$ref\":\"#/definitions/heading\"},{\"$ref\":\"#/definitions/paragraph\"},{\"$ref\":\"#/definitions/list\"},{\"$ref\":\"#/definitions/to_do_list\"},{\"$ref\":\"#/definitions/toggle\"},{\"$ref\":\"#/definitions/column_list\"},{\"$ref\":\"#/definitions/callout\"},{\"$ref\":\"#/definitions/quote\"}]}}},\"required\":[\"type\",\"text\",\"children\"],\"additionalProperties\":false},\"column_list\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"column_list\"]},\"columns\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"column\"]},\"children\":{\"type\":\"array\",\"items\":{\"oneOf\":[{\"$ref\":\"#/definitions/divider\"},{\"$ref\":\"#/definitions/table_of_contents\"},{\"$ref\":\"#/definitions/heading\"},{\"$ref\":\"#/definitions/paragraph\"},{\"$ref\":\"#/definitions/list\"},{\"$ref\":\"#/definitions/to_do_list\"},{\"$ref\":\"#/definitions/toggle\"},{\"$ref\":\"#/definitions/callout\"},{\"$ref\":\"#/definitions/quote\"}]}}},\"required\":[\"type\",\"children\"],\"additionalProperties\":false}}},\"required\":[\"type\",\"columns\"],\"additionalProperties\":false},\"callout\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"callout\"]},\"icon\":{\"type\":\"string\"},\"color\":{\"type\":\"string\",\"enum\":[\"blue_background\",\"brown_background\",\"default\",\"gray_background\",\"green_background\",\"orange_background\",\"pink_background\",\"purple_background\",\"red_background\",\"yellow_background\"]},\"content\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"string\"},\"style\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"enum\":[\"bold\",\"italic\",\"strikethrough\",\"underline\",\"code\"]},\"default\":[]}},\"required\":[\"text\",\"style\"],\"additionalProperties\":false}}},\"required\":[\"type\",\"icon\",\"color\",\"content\"],\"additionalProperties\":false},\"quote\":{\"type\":\"object\",\"properties\":{\"type\":{\"type\":\"string\",\"enum\":[\"quote\"]},\"content\":{\"type\":\"array\",\"items\":{\"type\":\"object\",\"properties\":{\"text\":{\"type\":\"string\"},\"style\":{\"type\":\"array\",\"items\":{\"type\":\"string\",\"enum\":[\"bold\",\"italic\",\"strikethrough\",\"underline\",\"code\"]},\"default\":[]}},\"required\":[\"text\",\"style\"],\"additionalProperties\":false}}},\"required\":[\"type\",\"content\"],\"additionalProperties\":false}}}\n```\n\nAdditionally, when creating databases, note that there must be exactly one property in the \"schema\" object with the type \"title\", which will always be a rich text field. For example:\n\n\"Name\": {\n \"type\": \"title\"\n}" }, { "role": "user", "content": "I'm the CEO of Acme Inc., a company dedicated to helping people plan and organize, and I want a system to manage my marketing campaign. I want to store key documents, plan our strategy, handle deliverables and track performance." }, { "role": "assistant", "content": "{\"response\":\"Great, I will create a Notion page titled \\\"Campaign Brief\\\" for Acme Inc. to manage your upcoming marketing campaign. Here's a sneak peek of what you can expect:\\n\\n1. Overview: A brief summary of the campaign's objectives to get others up to speed, with an example to get you started.\\n2. Documents: A hub with linked essential documents like the product roadmap, weekly updates, performance reports, budget plans, and more.\\n3. Strategy: Details on campaign goals, target audience, and channel strategy to aid in strategic planning.\\n4. Execution: A section to track deliverables and monitor key campaign performance metrics effectively.\\n\\nThis organized structure will help you manage key documents, strategize effectively, track progress, and analyze campaign performance for a successful marketing push. Now, I’ll create this exact structure in Notion.\",\"blueprint\":{\"type\":\"page\",\"title\":\"Campaign Brief\",\"icon\":\"📋\",\"children\":[{\"type\":\"heading_1\",\"text\":\"Overview\"},{\"type\":\"callout\",\"icon\":\"➡️\",\"color\":\"purple_background\",\"content\":[{\"text\":\"Provide a summary of the campaign. At a glance, others should be able to quickly get up to speed on the project’s “what” and “why”, as well as the “why now”.\",\"style\":[]}],\"children\":[{\"type\":\"paragraph\",\"content\":[{\"text\":\"Example:\",\"style\":[\"bold\"]},{\"text\":\" In Q4, Acme Inc. will launch an awareness campaign for personal users across key global markets to drive new site visits and account creation. The campaign will focus on highlighting the customizability of Acme and how it can be used for planning, organizing, and managing one's life. The primary objectives of the campaign are to increase brand awareness and drive traffic to the site. The campaign will showcase Acme's organization and goal-setting features, including databases, to-do lists, and calendars, as well as its sharing and collaboration capabilities.\",\"style\":[]}]}]},{\"type\":\"paragraph\",\"content\":[]},{\"type\":\"toggle\",\"title\":\"Table of Contents\",\"children\":[{\"type\":\"table_of_contents\"}]},{\"type\":\"heading_1\",\"text\":\"📘 Documents\"},{\"type\":\"divider\"},{\"type\":\"paragraph\",\"content\":[{\"text\":\"Link to all key documents that are relevant for this campaign.\",\"style\":[]}]},{\"type\":\"page\",\"title\":\"Documents Hub\",\"icon\":\"📘\",\"children\":[{\"type\":\"database\",\"title\":\"Product roadmap\",\"icon\":\"🎯\",\"schema\":{\"Project\":{\"type\":\"title\"},\"Assign\":{\"type\":\"people\"},\"Date\":{\"type\":\"date\"},\"Status\":{\"type\":\"select\",\"options\":[{\"name\":\"Not started\",\"color\":\"red\"},{\"name\":\"In progress\",\"color\":\"yellow\"},{\"name\":\"Completed\",\"color\":\"green\"}]}}},{\"type\":\"database\",\"title\":\"Weekly product update\",\"icon\":\"📄\",\"schema\":{\"Name\":{\"type\":\"title\"},\"Author\":{\"type\":\"people\"}}},{\"type\":\"page\",\"title\":\"Performance report\",\"icon\":\"📈\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Tip:\",\"style\":[\"bold\"]},{\"text\":\" Add more details right in this page, including toggles, images, and more. Break up the page by using different header options so that it’s easier to read.\",\"style\":[]}]}]},{\"type\":\"page\",\"title\":\"Budget plan\",\"icon\":\"💸\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Tip:\",\"style\":[\"bold\"]},{\"text\":\" Add more details right in this page, including toggles, images, and more. Break up the page by using different header options so that it’s easier to read.\",\"style\":[]}]}]},{\"type\":\"page\",\"title\":\"Editorial calendar\",\"icon\":\"📅\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Overview:\",\"style\":[\"bold\"]},{\"text\":\" Add more details right in this page, including toggles, images, and more. Break up the page by using different header options so that it’s easier to read.\",\"style\":[]}]}]},{\"type\":\"page\",\"title\":\"Content strategy\",\"icon\":\"📝\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Tip:\",\"style\":[\"bold\"]},{\"text\":\" Add more details right in this page, including toggles, images, and more. Break up the page by using different header options so that it’s easier to read.\",\"style\":[]}]}]}]},{\"type\":\"heading_1\",\"text\":\"🧭 Strategy\"},{\"type\":\"divider\"},{\"type\":\"heading_2\",\"text\":\"Goals & objectives\"},{\"type\":\"paragraph\",\"content\":[{\"text\":\"Use this section to list all campaign goals and objectives. \",\"style\":[]}]},{\"type\":\"paragraph\",\"content\":[{\"text\":\"Campaign objectives:\",\"style\":[\"bold\"]}]},{\"type\":\"numbered_list\",\"items\":[\"Increasing awareness of brand\",\"Driving traffic to site\"]},{\"type\":\"paragraph\",\"content\":[{\"text\":\"Product goals:\",\"style\":[\"bold\"]}]},{\"type\":\"numbered_list\",\"items\":[\"Showcase organization and goal-setting in Acme with databases, to-do lists, calendars, and other productivity features\",\"Highlight sharing and collaborating with friends and family\"]},{\"type\":\"paragraph\",\"content\":[{\"text\":\"Company goals:\",\"style\":[\"bold\"]}]},{\"type\":\"numbered_list\",\"items\":[\"Show Acme’s product flexibility\",\"Increase overall signups \"]},{\"type\":\"heading_2\",\"text\":\"Target audience(s)\"},{\"type\":\"paragraph\",\"content\":[{\"text\":\"Provide a summary of your target audience(s) in as much detail as possible. The more defined your audience is, the more targeted your campaign will be. The toggle below includes a few additional questions to ask when narrowing in on your target audience.\",\"style\":[]}]},{\"type\":\"toggle\",\"title\":\"Additional audience insights:\",\"children\":[{\"type\":\"bulleted_list\",\"items\":[\"What do they think and how do they behave?\",\"What problem or challenge are we trying to solve for them?\",\"What makes their experience with Acme unique?\",\"Why are they not doing what we want them to?\",\"What challenges of theirs can Acme help solve?\",\"What channels does this audience or community interact with most?\",\"What unique behaviors do we want to focus on as part of our marketing effort?\"]}]},{\"type\":\"paragraph\",\"content\":[{\"text\":\"The target audience will include personal users across various demographics and regions, with a focus on those who are seeking a more efficient and customizable productivity tool. \",\"style\":[]}]},{\"type\":\"bulleted_list\",\"items\":[\"Prospects that don’t use Acme for Personal or Teams → Try Acme!\",\"Personal users that don’t use Acme at work → Plan personal and work goals with Acme!\"]},{\"type\":\"heading_1\",\"text\":\"📨 Channel strategy\"},{\"type\":\"divider\"},{\"type\":\"heading_2\",\"text\":\"Overview\"},{\"type\":\"paragraph\",\"content\":[{\"text\":\"Use this section to summarize at a glance the major campaign moments and deliverables.\",\"style\":[]},{\"text\":\" \",\"style\":[]}]},{\"type\":\"bulleted_list\",\"items\":[\"Identify potential partners for cross-promotion, such as productivity and lifestyle influencers\",\"Create social media content that highlights Acme's customization and collaboration features, targeting personal users who are seeking a more efficient productivity tool\",\"Utilize email marketing to drive traffic to the site and showcase Acme's organization and goal-setting features, including databases, to-do lists, and calendars\",\"Host webinars and workshops to educate new users on how to use Acme for personal productivity and organization\",\"Use targeted ads on social media platforms and search engines to reach potential users who are searching for productivity tools\",\"Develop partnerships with relevant organizations or companies to offer Acme as a productivity tool for their employees or members\"]},{\"type\":\"heading_1\",\"text\":\"🚀 Execution\"},{\"type\":\"divider\"},{\"type\":\"heading_2\",\"text\":\"Deliverables tracker\"},{\"type\":\"paragraph\",\"content\":[{\"text\":\"Use this section to track any actions or deliverables needed to launch the campaign. Use the “Channel” column to link deliverables to the relevant channel.\",\"style\":[]}]},{\"type\":\"database\",\"title\":\"Deliverables tracker\",\"icon\":\"🕒\",\"is_inline\":true,\"schema\":{\"Deliverable\":{\"type\":\"title\"},\"Status\":{\"type\":\"select\",\"options\":[{\"name\":\"Not started\",\"color\":\"red\"},{\"name\":\"In progress\",\"color\":\"yellow\"},{\"name\":\"Design in progress\",\"color\":\"yellow\"},{\"name\":\"Design finished\",\"color\":\"orange\"},{\"name\":\"Sent to vendor\",\"color\":\"blue\"},{\"name\":\"Ordered\",\"color\":\"blue\"},{\"name\":\"Shipped\",\"color\":\"blue\"},{\"name\":\"Received\",\"color\":\"green\"},{\"name\":\"Complete\",\"color\":\"green\"}]},\"Assignee\":{\"type\":\"people\"},\"Contributors\":{\"type\":\"people\"},\"Due\":{\"type\":\"date\"},\"Channel\":{\"type\":\"select\",\"options\":[{\"name\":\"Community\",\"color\":\"purple\"},{\"name\":\"Social Media\",\"color\":\"green\"},{\"name\":\"Content\",\"color\":\"pink\"},{\"name\":\"Events\",\"color\":\"brown\"},{\"name\":\"Communications\",\"color\":\"gray\"},{\"name\":\"Performance\",\"color\":\"yellow\"},{\"name\":\"Product Marketing\",\"color\":\"default\"},{\"name\":\"Demand Gen\",\"color\":\"orange\"}]}}},{\"type\":\"heading_1\",\"text\":\"📈 Campaign performance\"},{\"type\":\"divider\"},{\"type\":\"paragraph\",\"content\":[{\"text\":\"Add post-campaign performance reports and metrics here.\",\"style\":[]}]},{\"type\":\"callout\",\"icon\":\"✨\",\"color\":\"default\",\"content\":[{\"text\":\"Overall goal:\",\"style\":[\"bold\"]}]},{\"type\":\"callout\",\"icon\":\"✍️\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Executive Summary\",\"style\":[\"bold\"]}]},{\"type\":\"heading_2\",\"text\":\"Conversions\"},{\"type\":\"divider\"},{\"type\":\"heading_2\",\"text\":\"Impressions\"},{\"type\":\"divider\"},{\"type\":\"heading_2\",\"text\":\"Web traffic\"},{\"type\":\"divider\"},{\"type\":\"heading_2\",\"text\":\"Email\"},{\"type\":\"divider\"},{\"type\":\"heading_2\",\"text\":\"Social & Influencers\"},{\"type\":\"divider\"},{\"type\":\"heading_2\",\"text\":\"Internal Team Retro\"},{\"type\":\"divider\"}]}}" }, { "role": "user", "content": "I run a CS club and want a centralized dashboard where I can list events, store a repository of resources, and have a news section. Oh, and a place for club photos would also be nice, just so it looks more aesthetic." }, { "role": "assistant", "content": "{\"response\":\"Certainly! I'll make a centralized Notion dashboard for your club titled \\\"Computer Science Club Home.\\\" This page will serve as a central hub where you can manage and showcase various aspects of your club. It will also include sections for upcoming events, a repository of resources, the latest news, and a gallery for club photos to enhance the aesthetic appeal.\\n\\nWe’ll start with the welcome message in a callout box at the top, that will invite new and prospective members with an application link and a brief introduction to the club’s purpose. Then, we’ll follow up with your news section, which will be set up to feature updates and announcements that can be chronologically organized for ease of use. Additionally, events will be detailed on their individual pages linked from a main events section, ensuring that members know what, when, and where activities are happening.\\n\\nFor resources, there will be individual pages under one umbrella, each containing valuable materials ranging from internship opportunities to tech talks and software deals. This will be an invaluable asset for both new and existing members. Lastly, the photo gallery will serve as a vibrant collage of recent activities and memorable moments from the club, encouraging a sense of community and belonging! Now, I’ll go ahead and create your computer science club dashboard in Notion.\",\"blueprint\":{\"type\":\"page\",\"title\":\"Computer science club home\",\"icon\":\"🤖\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Template Overview: \",\"style\":[\"bold\"]},{\"text\":\"Use this template if you’re running a club at school and need a homepage to showcase your events, news, resources, and more! This template is specifically designed for Computer Science or Engineering-themed clubs, but you can adapt it for any group that runs programming and events.\",\"style\":[]}]},{\"type\":\"column_list\",\"columns\":[{\"type\":\"column\",\"children\":[{\"type\":\"callout\",\"icon\":\"💾\",\"color\":\"blue_background\",\"content\":[{\"text\":\"Hello world!\",\"style\":[\"code\"]},{\"text\":\" Welcome to our computer science club homepage. Want to join? Fill this form out:\",\"style\":[]},{\"text\":\"…attach link here\",\"style\":[\"italic\"]},{\"text\":\"Scroll down to learn more about our club and check out some useful resources. Check out recent news, upcoming events, club photos, and more! \",\"style\":[]}]}]},{\"type\":\"column\",\"children\":[{\"type\":\"quote\",\"content\":[{\"text\":\"Table of contents\",\"style\":[\"bold\"]}],\"children\":[{\"type\":\"table_of_contents\"}]}]}]},{\"type\":\"heading_1\",\"text\":\"News\"},{\"type\":\"database\",\"title\":\"News\",\"icon\":\"📰\",\"is_inline\":true,\"schema\":{\"Name\":{\"type\":\"title\"},\"Date\":{\"type\":\"date\"}}},{\"type\":\"heading_1\",\"text\":\"Events\"},{\"type\":\"page\",\"title\":\"Code party — September 2, 2022 7:00 PM (EDT)\",\"icon\":\"🎉\",\"children\":[{\"type\":\"heading_2\",\"text\":\"What?\"},{\"type\":\"paragraph\",\"content\":[{\"text\":\"We’re hosting a code party for anyone and everyone! Use the time to work on your CS homework, a side project, or just hang out with the crew 😎\",\"style\":[]}]},{\"type\":\"paragraph\",\"content\":[{\"text\":\"We’ll also have some snacks available free of charge! Come one, come all!\",\"style\":[]}]},{\"type\":\"heading_2\",\"text\":\"When?\"},{\"type\":\"paragraph\",\"content\":[{\"text\":\"September 2, 2022 7:00 PM (EDT)\",\"style\":[]}]},{\"type\":\"heading_2\",\"text\":\"Where?\"},{\"type\":\"paragraph\",\"content\":[{\"text\":\"MN Building — Room 112\",\"style\":[]}]},{\"type\":\"heading_2\",\"text\":\"Who?\"},{\"type\":\"paragraph\",\"content\":[{\"text\":\"Anyone and everyone!\",\"style\":[]}]},{\"type\":\"paragraph\",\"content\":[]}]},{\"type\":\"page\",\"title\":\"Capture the flag — September 7, 2022 7:00 PM (EDT)\",\"icon\":\"🏴☠️\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Template Tip: \",\"style\":[\"bold\"]},{\"text\":\"Use this space below to provide more details about this event. You can also add the event schedule, embed a form, or even videos of past events.\",\"style\":[]}]}]},{\"type\":\"page\",\"title\":\"Python 101 — September 9, 2022 7:00 PM (EDT)\",\"icon\":\"🐍\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Template Tip: \",\"style\":[\"bold\"]},{\"text\":\"Use this space below to provide more details about this event. You can also add the event schedule, embed a form, or even videos of past events.\",\"style\":[]}]}]},{\"type\":\"heading_1\",\"text\":\"Resources\"},{\"type\":\"page\",\"title\":\"Internships 2022\",\"icon\":\"🏢\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Template Tip:\",\"style\":[\"bold\"]},{\"text\":\" Add more details right in this page, including toggles, images, and more. Break up the page by using our different header options so that it’s easier to read.\",\"style\":[]}]}]},{\"type\":\"page\",\"title\":\"Our services\",\"icon\":\"⚙️\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Template Tip:\",\"style\":[\"bold\"]},{\"text\":\" Add more details right in this page, including toggles, images, and more. Break up the page by using our different header options so that it’s easier to read.\",\"style\":[]}]}]},{\"type\":\"page\",\"title\":\"Tech talks\",\"icon\":\"🎤\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Template Tip:\",\"style\":[\"bold\"]},{\"text\":\" Add more details right in this page, including toggles, images, and more. Break up the page by using our different header options so that it’s easier to read.\",\"style\":[]}]}]},{\"type\":\"page\",\"title\":\"Meet the team\",\"icon\":\"👥\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Template Tip:\",\"style\":[\"bold\"]},{\"text\":\" Add more details right in this page, including toggles, images, and more. Break up the page by using our different header options so that it’s easier to read.\",\"style\":[]}]}]},{\"type\":\"page\",\"title\":\"Software deals\",\"icon\":\"💿\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Template Tip:\",\"style\":[\"bold\"]},{\"text\":\" Add more details right in this page, including toggles, images, and more. Break up the page by using our different header options so that it’s easier to read.\",\"style\":[]}]}]},{\"type\":\"page\",\"title\":\"First year guide\",\"icon\":\"🎒\",\"children\":[{\"type\":\"callout\",\"icon\":\"💡\",\"color\":\"gray_background\",\"content\":[{\"text\":\"Template Tip:\",\"style\":[\"bold\"]},{\"text\":\" Add more details right in this page, including toggles, images, and more. Break up the page by using our different header options so that it’s easier to read.\",\"style\":[]}]}]},{\"type\":\"heading_1\",\"text\":\"Photos\"},{\"type\":\"quote\",\"content\":[{\"text\":\"This is where you add photos of recent club meetups or events, be bold!\",\"style\":[]}]}]}}" }, { "role": "user", "content": description } # ,{ # "role": "assistant", # "content": json.dumps(custom_data) # Convert custom data to JSON string if necessary # } ], temperature=temperature, max_tokens=4096, top_p=top_p, frequency_penalty=0, presence_penalty=0, stream=True ) else: # '''LOAD API CLIENT''' # _api_key = HUGGINGFACEHUB_API_TOKEN # if not def_env_var: # _api_key = os.getenv('HUGGINGFACEHUB_API_TOKEN') # client = InferenceClient(model=model, token=_api_key) response = [] raise ValueError("Only 'openai' llms are supported.") if api: chunks = [] for _idx, chunk in enumerate(response): chunks.append(chunk.choices[0].delta.content) return response, chunks return response
def generate_blueprint(description, force_json=False, temperature=0.7, top_p=0.2, llm='openai', model=MODEL_NAME, def_env_var=True, llm_key=None, custom_data=None): response = invoke_llm( 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=False)
in_response = False accumulated_json = "" response_buffer = "" partial_newline = False
for chunk in response: # for chunk in chunks: # text = chunk text = chunk.choices[0].delta.content
if text is None: text = ""
accumulated_json += text
if partial_newline: if text.startswith("n"): response_buffer += "\n" text = text[1:] partial_newline = False
if text.endswith("\\"): partial_newline = True text = text[:-1]
text = text.replace("\\n", "\n")
if not in_response: response_start_index = accumulated_json[-20 - len(text):].find('"response":"') if response_start_index != -1: in_response = True start_index = len(accumulated_json) - (20 + len(text)) + response_start_index + len('"response":"') else: start_index = 0 else: start_index = 0
if in_response: if text and '\"' in text: _text = codecs.decode(text, 'unicode_escape') # print(f"{text} -> {_text}") response_buffer += _text[start_index:] else: response_buffer += text[start_index:]
end_index = response_buffer.find('",') if end_index != -1: yield response_buffer[:end_index] in_response = False response_buffer = "" else: yield response_buffer[start_index:] response_buffer = ""
content = json.loads(accumulated_json) yield content123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183import osimport jsonfrom gradio_client import Client# from gradio_client_updated import Client
'''LOAD ENVIRONMENT VARIABLES'''from dotenv import load_dotenvload_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 response123456789101112131415## <u>Get Quickly Started</u>
[](https://example.com/video.mp4)
### <span style="color:blue">Input</span>- Input 1- Input 2- Input 3### <span style="color:blue">Output</span>- Output(s)
#### `Note: This is an important note.`---## Do add the environment secrets/variables before clicking on the `Submit` button! 🎉---123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147import jsonimport randomimport emojiNOTION_VALID_EMOJIS = ["😀", "😃", "😄", "😁", "😆", "😅", "🤣", "😂", "🙂", "🙃", "🫠", "😉", "😊", "😇", "🥰", "😍", "🤩", "😘", "😗", "☺️", "☺", "😚", "😙", "🥲", "😋", "😛", "😜", "🤪", "😝", "🤑", "🤗", "🤭", "🫢", "🫣", "🤫", "🤔", "🫡", "🤐", "🤨", "😐", "😑", "😶", "🫥", "😶🌫️", "😶🌫", "😏", "😒", "🙄", "😬", "😮💨", "🤥", "😌", "😔", "😪", "🤤", "😴", "😷", "🤒", "🤕", "🤢", "🤮", "🤧", "🥵", "🥶", "🥴", "😵", "😵💫", "🤯", "🤠", "🥳", "🥸", "😎", "🤓", "🧐", "😕", "🫤", "😟", "🙁", "☹️", "☹", "😮", "😯", "😲", "😳", "🥺", "🥹", "😦", "😧", "😨", "😰", "😥", "😢", "😭", "😱", "😖", "😣", "😞", "😓", "😩", "😫", "🥱", "😤", "😡", "😠", "🤬", "😈", "👿", "💀", "☠️", "☠", "💩", "🤡", "👹", "👺", "👻", "👽", "👾", "🤖", "😺", "😸", "😹", "😻", "😼", "😽", "🙀", "😿", "😾", "🙈", "🙉", "🙊", "💋", "💌", "💘", "💝", "💖", "💗", "💓", "💞", "💕", "💟", "❣️", "❣", "💔", "❤️🔥", "❤🔥", "❤️🩹", "❤🩹", "❤️", "❤", "🧡", "💛", "💚", "💙", "💜", "🤎", "🖤", "🤍", "💯", "💢", "💥", "💫", "💦", "💨", "🕳️", "🕳", "💣", "💬", "👁️🗨️", "🗨️", "🗨", "🗯️", "🗯", "💭", "💤", "👋🏻", "👋🏼", "👋🏽", "👋🏾", "👋🏿", "👋", "🤚🏻", "🤚🏼", "🤚🏽", "🤚🏾", "🤚🏿", "🤚", "🖐🏻", "🖐🏼", "🖐🏽", "🖐🏾", "🖐🏿", "🖐️", "🖐", "✋🏻", "✋🏼", "✋🏽", "✋🏾", "✋🏿", "✋", "🖖🏻", "🖖🏼", "🖖🏽", "🖖🏾", "🖖🏿", "🖖", "🫱🏻", "🫱🏼", "🫱🏽", "🫱🏾", "🫱🏿", "🫱", "🫲🏻", "🫲🏼", "🫲🏽", "🫲🏾", "🫲🏿", "🫲", "🫳🏻", "🫳🏼", "🫳🏽", "🫳🏾", "🫳🏿", "🫳", "🫴🏻", "🫴🏼", "🫴🏽", "🫴🏾", "🫴🏿", "🫴", "👌🏻", "👌🏼", "👌🏽", "👌🏾", "👌🏿", "👌", "🤌🏻", "🤌🏼", "🤌🏽", "🤌🏾", "🤌🏿", "🤌", "🤏🏻", "🤏🏼", "🤏🏽", "🤏🏾", "🤏🏿", "🤏", "✌🏻", "✌🏼", "✌🏽", "✌🏾", "✌🏿", "✌️", "✌", "🤞🏻", "🤞🏼", "🤞🏽", "🤞🏾", "🤞🏿", "🤞", "🫰🏻", "🫰🏼", "🫰🏽", "🫰🏾", "🫰🏿", "🫰", "🤟🏻", "🤟🏼", "🤟🏽", "🤟🏾", "🤟🏿", "🤟", "🤘🏻", "🤘🏼", "🤘🏽", "🤘🏾", "🤘🏿", "🤘", "🤙🏻", "🤙🏼", "🤙🏽", "🤙🏾", "🤙🏿", "🤙", "👈🏻", "👈🏼", "👈🏽", "👈🏾", "👈🏿", "👈", "👉🏻", "👉🏼", "👉🏽", "👉🏾", "👉🏿", "👉", "👆🏻", "👆🏼", "👆🏽", "👆🏾", "👆🏿", "👆", "🖕🏻", "🖕🏼", "🖕🏽", "🖕🏾", "🖕🏿", "🖕", "👇🏻", "👇🏼", "👇🏽", "👇🏾", "👇🏿", "👇", "☝🏻", "☝🏼", "☝🏽", "☝🏾", "☝🏿", "☝️", "☝", "🫵🏻", "🫵🏼", "🫵🏽", "🫵🏾", "🫵🏿", "🫵", "👍🏻", "👍🏼", "👍🏽", "👍🏾", "👍🏿", "👍", "👎🏻", "👎🏼", "👎🏽", "👎🏾", "👎🏿", "👎", "✊🏻", "✊🏼", "✊🏽", "✊🏾", "✊🏿", "✊", "👊🏻", "👊🏼", "👊🏽", "👊🏾", "👊🏿", "👊", "🤛🏻", "🤛🏼", "🤛🏽", "🤛🏾", "🤛🏿", "🤛", "🤜🏻", "🤜🏼", "🤜🏽", "🤜🏾", "🤜🏿", "🤜", "👏🏻", "👏🏼", "👏🏽", "👏🏾", "👏🏿", "👏", "🙌🏻", "🙌🏼", "🙌🏽", "🙌🏾", "🙌🏿", "🙌", "🫶🏻", "🫶🏼", "🫶🏽", "🫶🏾", "🫶🏿", "🫶", "👐🏻", "👐🏼", "👐🏽", "👐🏾", "👐🏿", "👐", "🤲🏻", "🤲🏼", "🤲🏽", "🤲🏾", "🤲🏿", "🤲", "🤝🏻", "🤝🏼", "🤝🏽", "🤝🏾", "🤝🏿", "🫱🏻🫲🏼", "🫱🏻🫲🏽", "🫱🏻🫲🏾", "🫱🏻🫲🏿", "🫱🏼🫲🏻", "🫱🏼🫲🏽", "🫱🏼🫲🏾", "🫱🏼🫲🏿", "🫱🏽🫲🏻", "🫱🏽🫲🏼", "🫱🏽🫲🏾", "🫱🏽🫲🏿", "🫱🏾🫲🏻", "🫱🏾🫲🏼", "🫱🏾🫲🏽", "🫱🏾🫲🏿", "🫱🏿🫲🏻", "🫱🏿🫲🏼", "🫱🏿🫲🏽", "🫱🏿🫲🏾", "🤝", "🙏🏻", "🙏🏼", "🙏🏽", "🙏🏾", "🙏🏿", "🙏", "✍🏻", "✍🏼", "✍🏽", "✍🏾", "✍🏿", "✍️", "✍", "💅🏻", "💅🏼", "💅🏽", "💅🏾", "💅🏿", "💅", "🤳🏻", "🤳🏼", "🤳🏽", "🤳🏾", "🤳🏿", "🤳", "💪🏻", "💪🏼", "💪🏽", "💪🏾", "💪🏿", "💪", "🦾", "🦿", "🦵🏻", "🦵🏼", "🦵🏽", "🦵🏾", "🦵🏿", "🦵", "🦶🏻", "🦶🏼", "🦶🏽", "🦶🏾", "🦶🏿", "🦶", "👂🏻", "👂🏼", "👂🏽", "👂🏾", "👂🏿", "👂", "🦻🏻", "🦻🏼", "🦻🏽", "🦻🏾", "🦻🏿", "🦻", "👃🏻", "👃🏼", "👃🏽", "👃🏾", "👃🏿", "👃", "🧠", "🫀", "🫁", "🦷", "🦴", "👀", "👁️", "👁", "👅", "👄", "🫦", "👶🏻", "👶🏼", "👶🏽", "👶🏾", "👶🏿", "👶", "🧒🏻", "🧒🏼", "🧒🏽", "🧒🏾", "🧒🏿", "🧒", "👦🏻", "👦🏼", "👦🏽", "👦🏾", "👦🏿", "👦", "👧🏻", "👧🏼", "👧🏽", "👧🏾", "👧🏿", "👧", "🧑🏻", "🧑🏼", "🧑🏽", "🧑🏾", "🧑🏿", "🧑", "👱🏻", "👱🏼", "👱🏽", "👱🏾", "👱🏿", "👱", "👨🏻", "👨🏼", "👨🏽", "👨🏾", "👨🏿", "👨", "🧔🏻", "🧔🏼", "🧔🏽", "🧔🏾", "🧔🏿", "🧔", "🧔🏻♂️", "🧔🏼♂️", "🧔🏽♂️", "🧔🏾♂️", "🧔🏿♂️", "🧔♂️", "🧔♂", "🧔🏻♀️", "🧔🏼♀️", "🧔🏽♀️", "🧔🏾♀️", "🧔🏿♀️", "🧔♀️", "🧔♀", "👨🏻🦰", "👨🏼🦰", "👨🏽🦰", "👨🏾🦰", "👨🏿🦰", "👨🦰", "👨🏻🦱", "👨🏼🦱", "👨🏽🦱", "👨🏾🦱", "👨🏿🦱", "👨🦱", "👨🏻🦳", "👨🏼🦳", "👨🏽🦳", "👨🏾🦳", "👨🏿🦳", "👨🦳", "👨🏻🦲", "👨🏼🦲", "👨🏽🦲", "👨🏾🦲", "👨🏿🦲", "👨🦲", "👩🏻", "👩🏼", "👩🏽", "👩🏾", "👩🏿", "👩", "👩🏻🦰", "👩🏼🦰", "👩🏽🦰", "👩🏾🦰", "👩🏿🦰", "👩🦰", "🧑🏻🦰", "🧑🏼🦰", "🧑🏽🦰", "🧑🏾🦰", "🧑🏿🦰", "🧑🦰", "👩🏻🦱", "👩🏼🦱", "👩🏽🦱", "👩🏾🦱", "👩🏿🦱", "👩🦱", "🧑🏻🦱", "🧑🏼🦱", "🧑🏽🦱", "🧑🏾🦱", "🧑🏿🦱", "🧑🦱", "👩🏻🦳", "👩🏼🦳", "👩🏽🦳", "👩🏾🦳", "👩🏿🦳", "👩🦳", "🧑🏻🦳", "🧑🏼🦳", "🧑🏽🦳", "🧑🏾🦳", "🧑🏿🦳", "🧑🦳", "👩🏻🦲", "👩🏼🦲", "👩🏽🦲", "👩🏾🦲", "👩🏿🦲", "👩🦲", "🧑🏻🦲", "🧑🏼🦲", "🧑🏽🦲", "🧑🏾🦲", "🧑🏿🦲", "🧑🦲", "👱🏻♀️", "👱🏼♀️", "👱🏽♀️", "👱🏾♀️", "👱🏿♀️", "👱♀️", "👱♀", "👱🏻♂️", "👱🏼♂️", "👱🏽♂️", "👱🏾♂️", "👱🏿♂️", "👱♂️", "👱♂", "🧓🏻", "🧓🏼", "🧓🏽", "🧓🏾", "🧓🏿", "🧓", "👴🏻", "👴🏼", "👴🏽", "👴🏾", "👴🏿", "👴", "👵🏻", "👵🏼", "👵🏽", "👵🏾", "👵🏿", "👵", "🙍🏻", "🙍🏼", "🙍🏽", "🙍🏾", "🙍🏿", "🙍", "🙍🏻♂️", "🙍🏼♂️", "🙍🏽♂️", "🙍🏾♂️", "🙍🏿♂️", "🙍♂️", "🙍♂", "🙍🏻♀️", "🙍🏼♀️", "🙍🏽♀️", "🙍🏾♀️", "🙍🏿♀️", "🙍♀️", "🙍♀", "🙎🏻", "🙎🏼", "🙎🏽", "🙎🏾", "🙎🏿", "🙎", "🙎🏻♂️", "🙎🏼♂️", "🙎🏽♂️", "🙎🏾♂️", "🙎🏿♂️", "🙎♂️", "🙎♂", "🙎🏻♀️", "🙎🏼♀️", "🙎🏽♀️", "🙎🏾♀️", "🙎🏿♀️", "🙎♀️", "🙎♀", "🙅🏻", "🙅🏼", "🙅🏽", "🙅🏾", "🙅🏿", "🙅", "🙅🏻♂️", "🙅🏼♂️", "🙅🏽♂️", "🙅🏾♂️", "🙅🏿♂️", "🙅♂️", "🙅♂", "🙅🏻♀️", "🙅🏼♀️", "🙅🏽♀️", "🙅🏾♀️", "🙅🏿♀️", "🙅♀️", "🙅♀", "🙆🏻", "🙆🏼", "🙆🏽", "🙆🏾", "🙆🏿", "🙆", "🙆🏻♂️", "🙆🏼♂️", "🙆🏽♂️", "🙆🏾♂️", "🙆🏿♂️", "🙆♂️", "🙆♂", "🙆🏻♀️", "🙆🏼♀️", "🙆🏽♀️", "🙆🏾♀️", "🙆🏿♀️", "🙆♀️", "🙆♀", "💁🏻", "💁🏼", "💁🏽", "💁🏾", "💁🏿", "💁", "💁🏻♂️", "💁🏼♂️", "💁🏽♂️", "💁🏾♂️", "💁🏿♂️", "💁♂️", "💁♂", "💁🏻♀️", "💁🏼♀️", "💁🏽♀️", "💁🏾♀️", "💁🏿♀️", "💁♀️", "💁♀", "🙋🏻", "🙋🏼", "🙋🏽", "🙋🏾", "🙋🏿", "🙋", "🙋🏻♂️", "🙋🏼♂️", "🙋🏽♂️", "🙋🏾♂️", "🙋🏿♂️", "🙋♂️", "🙋♂", "🙋🏻♀️", "🙋🏼♀️", "🙋🏽♀️", "🙋🏾♀️", "🙋🏿♀️", "🙋♀️", "🙋♀", "🧏🏻", "🧏🏼", "🧏🏽", "🧏🏾", "🧏🏿", "🧏", "🧏🏻♂️", "🧏🏼♂️", "🧏🏽♂️", "🧏🏾♂️", "🧏🏿��️", "🧏♂️", "🧏♂", "🧏🏻♀️", "🧏🏼♀️", "🧏🏽♀️", "🧏🏾♀️", "🧏🏿♀️", "🧏♀️", "🧏♀", "🙇🏻", "🙇🏼", "🙇🏽", "🙇🏾", "🙇🏿", "🙇", "🙇🏻♂️", "🙇🏼♂️", "🙇🏽♂️", "🙇🏾♂️", "🙇🏿♂️", "🙇♂️", "🙇♂", "🙇🏻♀️", "🙇🏼♀️", "🙇🏽♀️", "🙇🏾♀️", "🙇🏿♀️", "🙇♀️", "🙇♀", "🤦🏻", "🤦🏼", "🤦🏽", "🤦🏾", "🤦🏿", "🤦", "🤦🏻♂️", "🤦🏼♂️", "🤦🏽♂️", "🤦🏾♂️", "🤦🏿♂️", "🤦♂️", "🤦♂", "🤦🏻♀️", "🤦🏼♀️", "🤦🏽♀️", "🤦🏾♀️", "🤦🏿♀️", "🤦♀️", "🤦♀", "🤷🏻", "🤷🏼", "🤷🏽", "🤷🏾", "🤷🏿", "🤷", "🤷🏻♂️", "🤷🏼♂️", "🤷🏽♂️", "🤷🏾♂️", "🤷🏿♂️", "🤷♂️", "🤷♂", "🤷🏻♀️", "🤷🏼♀️", "🤷🏽♀️", "🤷🏾♀️", "🤷🏿♀️", "🤷♀️", "🤷♀", "🧑🏻⚕️", "🧑🏼⚕️", "🧑🏽⚕️", "🧑🏾⚕️", "🧑🏿⚕️", "🧑⚕️", "🧑⚕", "👨🏻⚕️", "👨🏼⚕️", "👨🏽⚕️", "👨🏾⚕️", "👨🏿⚕️", "👨⚕️", "👨⚕", "👩🏻⚕️", "👩🏼⚕️", "👩🏽⚕️", "👩🏾⚕️", "👩🏿⚕️", "👩⚕️", "👩⚕", "🧑🏻🎓", "🧑🏼🎓", "🧑🏽🎓", "🧑🏾🎓", "🧑🏿🎓", "🧑🎓", "👨🏻🎓", "👨🏼🎓", "👨🏽🎓", "👨🏾🎓", "👨🏿🎓", "👨🎓", "👩🏻🎓", "👩🏼🎓", "👩🏽🎓", "👩🏾🎓", "👩🏿🎓", "👩🎓", "🧑🏻🏫", "🧑🏼🏫", "🧑🏽🏫", "🧑🏾🏫", "🧑🏿🏫", "🧑🏫", "👨🏻🏫", "👨🏼🏫", "👨🏽🏫", "👨🏾🏫", "👨🏿🏫", "👨🏫", "👩🏻🏫", "👩🏼🏫", "👩🏽🏫", "👩🏾🏫", "👩🏿🏫", "👩🏫", "🧑🏻⚖️", "🧑🏼⚖️", "🧑🏽⚖️", "🧑🏾⚖️", "🧑🏿⚖️", "🧑⚖️", "🧑⚖", "👨🏻⚖️", "👨🏼⚖️", "👨🏽⚖️", "👨🏾⚖️", "👨🏿⚖️", "👨⚖️", "👨⚖", "👩🏻⚖️", "👩🏼⚖️", "👩🏽⚖️", "👩🏾⚖️", "👩🏿⚖️", "👩⚖️", "👩⚖", "🧑🏻🌾", "🧑🏼🌾", "🧑🏽🌾", "🧑🏾🌾", "🧑🏿🌾", "🧑🌾", "👨🏻🌾", "👨🏼🌾", "👨🏽🌾", "👨🏾🌾", "👨🏿🌾", "👨🌾", "👩🏻🌾", "👩🏼🌾", "👩🏽🌾", "👩🏾🌾", "👩🏿🌾", "👩🌾", "🧑🏻🍳", "🧑🏼🍳", "🧑🏽🍳", "🧑🏾🍳", "🧑🏿🍳", "🧑🍳", "👨🏻🍳", "👨🏼🍳", "👨🏽🍳", "👨🏾🍳", "👨🏿🍳", "👨🍳", "👩🏻🍳", "👩🏼🍳", "👩🏽🍳", "👩🏾🍳", "👩🏿🍳", "👩🍳", "🧑🏻🔧", "🧑🏼🔧", "🧑🏽🔧", "🧑🏾🔧", "🧑🏿🔧", "🧑🔧", "👨🏻🔧", "👨🏼🔧", "👨🏽🔧", "👨🏾🔧", "👨🏿🔧", "👨🔧", "👩🏻🔧", "👩🏼🔧", "👩🏽🔧", "👩🏾🔧", "👩🏿🔧", "👩🔧", "🧑🏻🏭", "🧑🏼🏭", "🧑🏽🏭", "🧑🏾🏭", "🧑🏿🏭", "🧑🏭", "👨🏻🏭", "👨🏼🏭", "👨🏽🏭", "👨🏾🏭", "👨🏿🏭", "👨🏭", "👩🏻🏭", "👩🏼🏭", "👩🏽🏭", "👩🏾🏭", "👩🏿🏭", "👩🏭", "🧑🏻💼", "🧑🏼💼", "🧑🏽💼", "🧑🏾💼", "🧑🏿💼", "🧑💼", "👨🏻💼", "👨🏼💼", "👨🏽💼", "👨🏾💼", "👨🏿💼", "👨💼", "👩🏻💼", "👩🏼💼", "👩🏽💼", "👩🏾💼", "👩🏿💼", "👩💼", "🧑🏻🔬", "🧑🏼🔬", "🧑🏽🔬", "🧑🏾🔬", "🧑🏿🔬", "🧑🔬", "👨🏻🔬", "👨🏼🔬", "👨🏽🔬", "👨🏾🔬", "👨🏿🔬", "👨🔬", "👩🏻🔬", "👩🏼🔬", "👩🏽🔬", "👩🏾🔬", "👩🏿🔬", "👩🔬", "🧑🏻💻", "🧑🏼💻", "🧑🏽💻", "🧑🏾💻", "🧑🏿💻", "🧑💻", "👨🏻💻", "👨🏼💻", "👨🏽💻", "👨🏾💻", "👨🏿💻", "👨💻", "👩🏻💻", "👩🏼💻", "👩🏽💻", "👩🏾💻", "👩🏿💻", "👩💻", "🧑🏻🎤", "🧑🏼🎤", "🧑🏽🎤", "🧑🏾🎤", "🧑🏿🎤", "🧑🎤", "👨🏻🎤", "👨🏼��🎤", "👨🏽🎤", "👨🏾🎤", "👨🏿🎤", "👨🎤", "👩🏻🎤", "👩🏼🎤", "👩🏽🎤", "👩🏾🎤", "👩🏿🎤", "👩🎤", "🧑🏻🎨", "🧑🏼🎨", "🧑🏽🎨", "🧑🏾🎨", "🧑🏿🎨", "🧑🎨", "👨🏻🎨", "👨🏼🎨", "👨🏽🎨", "👨🏾🎨", "👨🏿🎨", "👨🎨", "👩🏻🎨", "👩🏼🎨", "👩🏽🎨", "👩🏾🎨", "👩🏿🎨", "👩🎨", "🧑🏻✈️", "🧑🏼✈️", "🧑🏽✈️", "🧑🏾✈️", "🧑🏿✈️", "🧑✈️", "🧑✈", "👨🏻✈️", "👨🏼✈️", "👨🏽✈️", "👨🏾✈️", "👨🏿✈️", "👨✈️", "👨✈", "👩🏻✈️", "👩🏼✈️", "👩🏽✈️", "👩🏾✈️", "👩🏿✈️", "👩✈️", "👩✈", "🧑🏻🚀", "🧑🏼🚀", "🧑🏽🚀", "🧑🏾🚀", "🧑🏿🚀", "🧑🚀", "👨🏻🚀", "👨🏼🚀", "👨🏽🚀", "👨🏾🚀", "👨🏿🚀", "👨🚀", "👩🏻🚀", "👩🏼🚀", "👩🏽🚀", "👩🏾🚀", "👩🏿🚀", "👩🚀", "🧑🏻🚒", "🧑🏼🚒", "🧑🏽🚒", "🧑🏾🚒", "🧑🏿🚒", "🧑🚒", "👨🏻🚒", "👨🏼🚒", "👨🏽🚒", "👨🏾🚒", "👨🏿🚒", "👨🚒", "👩🏻🚒", "👩🏼🚒", "👩🏽🚒", "👩🏾🚒", "👩🏿🚒", "👩🚒", "👮🏻", "👮🏼", "👮🏽", "👮🏾", "👮🏿", "👮", "👮🏻♂️", "👮🏼♂️", "👮🏽♂️", "👮🏾♂️", "👮🏿♂️", "👮♂️", "👮♂", "👮🏻♀️", "👮🏼♀️", "👮🏽♀️", "👮🏾♀️", "👮🏿♀️", "👮♀️", "👮♀", "🕵🏻", "🕵🏼", "🕵🏽", "🕵🏾", "🕵🏿", "🕵️", "🕵", "🕵🏻♂️", "🕵🏼♂️", "🕵🏽♂️", "🕵🏾♂️", "🕵🏿♂️", "🕵️♂️", "🕵🏻♀️", "🕵🏼♀️", "🕵🏽♀️", "🕵🏾♀️", "🕵🏿♀️", "🕵️♀️", "💂🏻", "💂🏼", "💂🏽", "💂🏾", "💂🏿", "💂", "💂🏻♂️", "💂🏼♂️", "💂🏽♂️", "💂🏾♂️", "💂🏿♂️", "💂♂️", "💂♂", "💂🏻♀️", "💂🏼♀️", "💂🏽♀️", "💂🏾♀️", "💂🏿♀️", "💂♀️", "💂♀", "🥷🏻", "🥷🏼", "🥷🏽", "🥷🏾", "🥷🏿", "🥷", "👷🏻", "👷🏼", "👷🏽", "👷🏾", "👷🏿", "👷", "👷🏻♂️", "👷🏼♂️", "👷🏽♂️", "👷🏾♂️", "👷🏿♂️", "👷♂️", "👷♂", "👷🏻♀️", "👷🏼♀️", "👷🏽♀️", "👷🏾♀️", "👷🏿♀️", "👷♀️", "👷♀", "🫅🏻", "🫅🏼", "🫅🏽", "🫅🏾", "🫅🏿", "🫅", "🤴🏻", "🤴🏼", "🤴🏽", "🤴🏾", "🤴🏿", "🤴", "👸🏻", "👸🏼", "👸🏽", "👸🏾", "👸🏿", "👸", "👳🏻", "👳🏼", "👳🏽", "👳🏾", "👳🏿", "👳", "👳🏻♂️", "👳🏼♂️", "👳🏽♂️", "👳🏾♂️", "👳🏿♂️", "👳♂️", "👳♂", "👳🏻♀️", "👳🏼♀️", "👳🏽♀️", "👳🏾♀️", "👳🏿♀️", "👳♀️", "👳♀", "👲🏻", "👲🏼", "👲🏽", "👲🏾", "👲🏿", "👲", "🧕🏻", "🧕🏼", "🧕🏽", "🧕🏾", "🧕🏿", "🧕", "🤵🏻", "🤵🏼", "🤵🏽", "🤵🏾", "🤵🏿", "🤵", "🤵🏻♂️", "🤵🏼♂️", "🤵🏽♂️", "🤵🏾♂️", "🤵🏿♂️", "🤵♂️", "🤵♂", "🤵🏻♀️", "🤵🏼♀️", "🤵🏽♀️", "🤵🏾♀️", "🤵🏿♀️", "🤵♀️", "🤵♀", "👰🏻", "👰🏼", "👰🏽", "👰🏾", "👰🏿", "👰", "👰🏻♂️", "👰🏼♂️", "👰🏽♂️", "👰🏾♂️", "👰🏿♂️", "👰♂️", "👰♂", "👰🏻♀️", "👰🏼♀️", "👰🏽♀️", "👰🏾♀️", "👰🏿♀️", "👰♀️", "👰♀", "🤰🏻", "🤰🏼", "🤰🏽", "🤰🏾", "🤰🏿", "🤰", "🫃🏻", "🫃🏼", "🫃🏽", "🫃🏾", "🫃🏿", "🫃", "🫄🏻", "🫄🏼", "🫄🏽", "🫄🏾", "🫄🏿", "🫄", "🤱🏻", "🤱🏼", "🤱🏽", "🤱🏾", "🤱🏿", "🤱", "👩🏻🍼", "👩🏼🍼", "👩🏽🍼", "👩🏾🍼", "👩🏿🍼", "👩🍼", "👨🏻🍼", "👨🏼🍼", "👨🏽🍼", "👨🏾🍼", "👨🏿🍼", "👨🍼", "🧑🏻🍼", "🧑🏼🍼", "🧑🏽🍼", "🧑🏾🍼", "🧑🏿🍼", "🧑🍼", "👼🏻", "👼🏼", "👼🏽", "👼🏾", "👼🏿", "👼", "🎅🏻", "🎅🏼", "🎅🏽", "🎅🏾", "🎅🏿", "🎅", "🤶🏻", "🤶🏼", "🤶🏽", "🤶🏾", "🤶🏿", "🤶", "🧑🏻🎄", "🧑🏼🎄", "🧑🏽🎄", "🧑🏾🎄", "🧑🏿🎄", "🧑🎄", "🦸🏻", "🦸🏼", "🦸🏽", "🦸🏾", "🦸🏿", "🦸", "🦸🏻♂️", "🦸🏼♂️", "🦸🏽♂️", "🦸🏾♂️", "🦸🏿♂️", "🦸♂️", "🦸♂", "🦸🏻♀️", "🦸🏼♀️", "🦸🏽♀️", "🦸🏾♀️", "🦸🏿♀️", "🦸♀️", "🦸♀", "🦹🏻", "🦹🏼", "🦹🏽", "🦹🏾", "🦹🏿", "🦹", "🦹🏻♂️", "🦹🏼♂️", "🦹🏽♂️", "🦹🏾♂️", "🦹🏿♂️", "🦹♂️", "🦹♂", "🦹🏻♀️", "🦹🏼♀️", "🦹🏽♀️", "🦹🏾♀️", "🦹🏿♀️", "🦹♀️", "🦹♀", "🧙🏻", "🧙🏼", "🧙🏽", "🧙🏾", "🧙🏿", "🧙", "🧙🏻♂️", "🧙🏼♂️", "🧙🏽♂️", "🧙🏾♂️", "🧙🏿♂️", "🧙♂️", "🧙♂", "🧙🏻♀️", "🧙🏼♀️", "🧙🏽♀️", "🧙🏾♀️", "🧙🏿♀️", "🧙♀️", "🧙♀", "🧚🏻", "🧚🏼", "🧚🏽", "🧚🏾", "🧚🏿", "🧚", "🧚🏻♂️", "🧚🏼♂️", "🧚🏽♂️", "🧚🏾♂️", "🧚🏿♂️", "🧚♂️", "🧚♂", "🧚🏻♀️", "🧚🏼♀️", "🧚🏽♀️", "🧚🏾♀️", "🧚🏿♀️", "🧚♀️", "🧚♀", "🧛🏻", "🧛🏼", "🧛🏽", "🧛🏾", "🧛🏿", "🧛", "🧛🏻♂️", "🧛🏼♂️", "🧛🏽♂️", "🧛🏾♂️", "🧛🏿♂️", "🧛♂️", "🧛♂", "🧛🏻♀️", "🧛🏼♀️", "🧛🏽♀️", "🧛🏾♀️", "🧛🏿♀️", "🧛♀️", "🧛♀", "🧜🏻", "🧜🏼", "🧜🏽", "🧜🏾", "🧜🏿", "🧜", "🧜🏻♂️", "🧜🏼♂️", "🧜🏽♂️", "🧜🏾♂️", "🧜🏿♂️", "🧜♂️", "🧜♂", "🧜🏻♀️", "🧜🏼♀️", "🧜🏽♀️", "🧜🏾♀️", "🧜🏿♀️", "🧜♀️", "🧜♀", "🧝🏻", "🧝🏼", "🧝🏽", "🧝🏾", "🧝🏿", "🧝", "🧝🏻♂️", "🧝🏼♂️", "🧝🏽♂️", "🧝🏾♂️", "🧝🏿♂️", "🧝♂️", "🧝♂", "🧝🏻♀️", "🧝🏼♀️", "🧝🏽♀️", "🧝🏾♀️", "🧝🏿♀️", "🧝♀️", "🧝♀", "🧞", "🧞♂️", "🧞♂", "🧞♀️", "🧞♀", "🧟", "🧟♂️", "🧟♂", "🧟♀️", "🧟♀", "🧌", "💆🏻", "💆🏼", "💆🏽", "💆🏾", "💆🏿", "💆", "💆🏻♂️", "💆🏼♂️", "💆🏽♂️", "💆🏾♂️", "💆🏿♂️", "💆♂️", "💆♂", "💆🏻♀️", "💆🏼♀️", "💆🏽♀️", "💆🏾♀️", "💆🏿♀️", "💆♀️", "💆♀", "💇🏻", "💇🏼", "💇🏽", "💇🏾", "💇🏿", "💇", "💇🏻♂️", "💇🏼♂️", "💇🏽♂️", "💇🏾♂️", "💇🏿♂️", "💇♂️", "💇♂", "💇🏻♀️", "💇🏼♀️", "💇🏽♀️", "💇🏾♀️", "💇🏿♀️", "💇♀️", "💇♀", "🚶🏻", "🚶🏼", "🚶🏽", "🚶🏾", "🚶🏿", "🚶", "🚶🏻♂️", "🚶🏼♂️", "🚶🏽♂️", "🚶🏾♂️", "🚶🏿♂️", "🚶♂️", "🚶♂", "🚶🏻♀️", "🚶🏼♀️", "🚶🏽♀️", "🚶🏾♀️", "🚶🏿♀️", "🚶♀️", "🚶♀", "🧍🏻", "🧍🏼", "🧍🏽", "🧍🏾", "🧍🏿", "🧍", "🧍🏻♂️", "🧍🏼♂️", "🧍🏽♂️", "🧍🏾♂️", "🧍🏿♂️", "🧍♂️", "🧍♂", "🧍🏻♀️", "🧍🏼♀️", "🧍🏽♀️", "🧍🏾♀️", "🧍🏿♀️", "🧍♀️", "🧍♀", "🧎🏻", "🧎🏼", "🧎🏽", "🧎🏾", "🧎🏿", "🧎", "🧎🏻♂️", "🧎🏼♂️", "🧎🏽♂️", "🧎🏾♂️", "🧎🏿♂️", "🧎♂️", "🧎♂", "🧎🏻♀️", "🧎🏼♀️", "🧎🏽♀️", "🧎🏾♀️", "🧎🏿♀️", "🧎♀️", "🧎♀", "🧑🏻🦯", "🧑🏼🦯", "🧑🏽🦯", "🧑🏾🦯", "🧑🏿🦯", "🧑🦯", "👨🏻🦯", "👨🏼🦯", "👨🏽🦯", "👨🏾🦯", "👨🏿🦯", "👨🦯", "👩🏻🦯", "👩🏼🦯", "👩🏽🦯", "👩🏾🦯", "👩🏿🦯", "👩🦯", "🧑🏻🦼", "🧑🏼🦼", "🧑🏽🦼", "🧑🏾🦼", "🧑🏿🦼", "🧑🦼", "👨🏻🦼", "👨🏼🦼", "👨🏽🦼", "👨🏾🦼", "👨🏿🦼", "👨🦼", "👩🏻🦼", "👩🏼🦼", "👩🏽🦼", "👩🏾🦼", "👩🏿🦼", "👩🦼", "🧑🏻🦽", "🧑🏼🦽", "🧑🏽🦽", "🧑🏾���", "🧑🏿🦽", "🧑🦽", "👨🏻🦽", "👨🏼🦽", "👨🏽🦽", "👨🏾🦽", "👨🏿🦽", "👨🦽", "👩🏻🦽", "👩🏼🦽", "👩🏽🦽", "👩🏾🦽", "👩🏿🦽", "👩🦽", "🏃🏻", "🏃🏼", "🏃🏽", "🏃🏾", "🏃🏿", "🏃", "🏃🏻♂️", "🏃🏼♂️", "🏃🏽♂️", "🏃🏾♂️", "🏃🏿♂️", "🏃♂️", "🏃♂", "🏃🏻♀️", "🏃🏼♀️", "🏃🏽♀️", "🏃🏾♀️", "🏃🏿♀️", "🏃♀️", "🏃♀", "💃🏻", "💃🏼", "💃🏽", "💃🏾", "💃🏿", "💃", "🕺🏻", "🕺🏼", "🕺🏽", "🕺🏾", "🕺🏿", "🕺", "🕴🏻", "🕴🏼", "🕴🏽", "🕴🏾", "🕴🏿", "🕴️", "🕴", "👯", "👯♂️", "👯♂", "👯♀️", "👯♀", "🧖🏻", "🧖🏼", "🧖🏽", "🧖🏾", "🧖🏿", "🧖", "🧖🏻♂️", "🧖🏼♂️", "🧖🏽♂️", "🧖🏾♂️", "🧖🏿♂️", "🧖♂️", "🧖♂", "🧖🏻♀️", "🧖🏼♀️", "🧖🏽♀️", "🧖🏾♀️", "🧖🏿♀️", "🧖♀️", "🧖♀", "🧗🏻", "🧗🏼", "🧗🏽", "🧗🏾", "🧗🏿", "🧗", "🧗🏻♂️", "🧗🏼♂️", "🧗🏽♂️", "🧗🏾♂️", "🧗🏿♂️", "🧗♂️", "🧗♂", "🧗🏻♀️", "🧗🏼♀️", "🧗🏽♀️", "🧗🏾♀️", "🧗🏿♀️", "🧗♀️", "🧗♀", "🤺", "🏇🏻", "🏇🏼", "🏇🏽", "🏇🏾", "🏇🏿", "🏇", "⛷️", "⛷", "🏂🏻", "🏂🏼", "🏂🏽", "🏂🏾", "🏂🏿", "🏂", "🏌🏻", "🏌🏼", "🏌🏽", "🏌🏾", "🏌🏿", "🏌️", "🏌", "🏌🏻♂️", "🏌🏼♂️", "🏌🏽♂️", "🏌🏾♂️", "🏌🏿♂️", "🏌️♂️", "🏌🏻♀️", "🏌🏼♀️", "🏌🏽♀️", "🏌🏾♀️", "🏌🏿♀️", "🏌️♀️", "🏄🏻", "🏄🏼", "🏄🏽", "🏄🏾", "🏄🏿", "🏄", "🏄🏻♂️", "🏄🏼♂️", "🏄🏽♂️", "🏄🏾♂️", "🏄🏿♂️", "🏄♂️", "🏄♂", "🏄🏻♀️", "🏄🏼♀️", "🏄🏽♀️", "🏄🏾♀️", "🏄🏿♀️", "🏄♀️", "🏄♀", "🚣🏻", "🚣🏼", "🚣🏽", "🚣🏾", "🚣🏿", "🚣", "🚣🏻♂️", "🚣🏼♂️", "🚣🏽♂️", "🚣🏾♂️", "🚣🏿♂️", "🚣♂️", "🚣♂", "🚣🏻♀️", "🚣🏼♀️", "🚣🏽♀️", "🚣🏾♀️", "🚣🏿♀️", "🚣♀️", "🚣♀", "🏊🏻", "🏊🏼", "🏊🏽", "🏊🏾", "🏊🏿", "🏊", "🏊🏻♂️", "🏊🏼♂️", "🏊🏽♂️", "🏊🏾♂️", "🏊🏿♂️", "🏊♂️", "🏊♂", "🏊🏻♀️", "🏊🏼♀️", "🏊🏽♀️", "🏊🏾♀️", "🏊🏿♀️", "🏊♀️", "🏊♀", "⛹🏻", "⛹🏼", "⛹🏽", "⛹🏾", "⛹🏿", "⛹️", "⛹", "⛹🏻♂️", "⛹🏼♂️", "⛹🏽♂️", "⛹🏾♂️", "⛹🏿♂️", "⛹️♂️", "⛹🏻♀️", "⛹🏼♀️", "⛹🏽♀️", "⛹🏾♀️", "⛹🏿♀️", "⛹️♀️", "🏋🏻", "🏋🏼", "🏋🏽", "🏋🏾", "🏋🏿", "🏋️", "🏋", "🏋🏻♂️", "🏋🏼♂️", "🏋🏽♂️", "🏋🏾♂️", "🏋🏿♂️", "🏋️♂️", "🏋🏻♀️", "🏋🏼♀️", "🏋🏽♀️", "🏋🏾♀️", "🏋🏿♀️", "🏋️♀️", "🚴🏻", "🚴🏼", "🚴🏽", "🚴🏾", "🚴🏿", "🚴", "🚴🏻♂️", "🚴🏼♂️", "🚴🏽♂️", "🚴🏾♂️", "🚴🏿♂️", "🚴♂️", "🚴♂", "🚴🏻♀️", "🚴🏼♀️", "🚴🏽♀️", "🚴🏾♀️", "🚴🏿♀️", "🚴♀️", "🚴♀", "🚵🏻", "🚵🏼", "🚵🏽", "🚵🏾", "🚵🏿", "🚵", "🚵🏻♂️", "🚵🏼♂️", "🚵🏽♂️", "🚵🏾♂️", "🚵🏿♂️", "🚵♂️", "🚵♂", "🚵🏻♀️", "🚵🏼♀️", "🚵🏽♀️", "🚵🏾♀️", "🚵🏿♀️", "🚵♀️", "🚵♀", "🤸🏻", "🤸🏼", "🤸🏽", "🤸🏾", "🤸🏿", "🤸", "🤸🏻♂️", "🤸🏼♂️", "🤸🏽♂️", "🤸🏾♂️", "🤸🏿♂️", "🤸♂️", "🤸♂", "🤸🏻♀️", "🤸🏼♀️", "🤸🏽♀️", "🤸🏾♀️", "🤸🏿♀️", "🤸♀️", "🤸♀", "🤼", "🤼♂️", "🤼♂", "🤼♀️", "🤼♀", "🤽🏻", "🤽🏼", "🤽🏽", "🤽🏾", "🤽🏿", "🤽", "🤽🏻♂️", "🤽🏼♂️", "🤽🏽♂️", "🤽🏾♂️", "🤽🏿♂️", "🤽♂️", "🤽♂", "🤽🏻♀️", "🤽🏼♀️", "🤽🏽♀️", "🤽🏾♀️", "🤽🏿♀️", "🤽♀️", "🤽♀", "🤾🏻", "🤾🏼", "🤾🏽", "🤾🏾", "🤾🏿", "🤾", "🤾🏻♂️", "🤾🏼♂️", "🤾🏽♂️", "🤾🏾♂️", "🤾🏿♂️", "🤾♂️", "🤾♂", "🤾🏻♀️", "🤾🏼♀️", "🤾🏽♀️", "🤾🏾♀️", "🤾🏿♀️", "🤾♀️", "🤾♀", "🤹🏻", "🤹🏼", "🤹🏽", "🤹🏾", "🤹🏿", "🤹", "🤹🏻♂️", "🤹🏼♂️", "🤹🏽♂️", "🤹🏾♂️", "🤹🏿♂️", "🤹♂️", "🤹♂", "🤹🏻♀️", "🤹🏼♀️", "🤹🏽♀️", "🤹🏾♀️", "🤹🏿♀️", "🤹♀️", "🤹♀", "🧘🏻", "🧘🏼", "🧘🏽", "🧘🏾", "🧘🏿", "🧘", "🧘🏻♂️", "🧘🏼♂️", "🧘🏽♂️", "🧘🏾♂️", "🧘🏿♂️", "🧘♂️", "🧘♂", "🧘🏻♀️", "🧘🏼♀️", "🧘🏽♀️", "🧘🏾♀️", "🧘🏿♀️", "🧘♀️", "🧘♀", "🛀🏻", "🛀🏼", "🛀🏽", "🛀🏾", "🛀🏿", "🛀", "🛌🏻", "🛌🏼", "🛌🏽", "🛌🏾", "🛌🏿", "🛌", "🧑🏻🤝🧑🏻", "🧑🏻🤝🧑🏼", "🧑🏻🤝🧑🏽", "🧑🏻🤝🧑🏾", "🧑🏻🤝🧑🏿", "🧑🏼🤝🧑🏻", "🧑🏼🤝🧑🏼", "🧑🏼🤝🧑🏽", "🧑🏼🤝🧑🏾", "🧑🏼🤝🧑🏿", "🧑🏽🤝🧑🏻", "🧑🏽🤝🧑🏼", "🧑🏽🤝🧑🏽", "🧑🏽🤝🧑🏾", "🧑🏽🤝🧑🏿", "🧑🏾🤝🧑🏻", "🧑🏾🤝🧑🏼", "🧑🏾🤝🧑🏽", "🧑🏾🤝🧑🏾", "🧑🏾🤝🧑🏿", "🧑🏿🤝🧑🏻", "🧑🏿🤝🧑🏼", "🧑🏿🤝🧑🏽", "🧑🏿🤝🧑🏾", "🧑🏿🤝🧑🏿", "🧑🤝🧑", "👭", "👫", "👬", "💏", "💑", "👪", "👨👩👦", "👨👩👧", "👨👩👧👦", "👨👩👦👦", "👨👩👧👧", "👨👨👦", "👨👨👧", "👨👨👧👦", "👨👨👦👦", "👨👨👧👧", "👩👩👦", "👩👩👧", "👩👩👧👦", "👩👩👦👦", "👩👩👧👧", "👨👦", "👨👦👦", "👨👧", "👨👧👦", "👨👧👧", "👩👦", "👩👦👦", "👩👧", "👩👧👦", "👩👧👧", "🗣️", "🗣", "👤", "👥", "🫂", "👣", "🐵", "🐒", "🦍", "🦧", "🐶", "🐕", "🦮", "🐕🦺", "🐩", "🐺", "🦊", "🦝", "🐱", "🐈", "🐈⬛", "🦁", "🐯", "🐅", "🐆", "🐴", "🐎", "🦄", "🦓", "🦌", "🦬", "🐮", "🐂", "🐃", "🐄", "🐷", "🐖", "🐗", "🐽", "🐏", "🐑", "🐐", "🐪", "🐫", "🦙", "🦒", "🐘", "🦣", "🦏", "🦛", "🐭", "🐁", "🐀", "🐹", "🐰", "🐇", "🐿️", "🐿", "🦫", "🦔", "🦇", "🐻", "🐻❄️", "🐻❄", "🐨", "🐼", "🦥", "🦦", "🦨", "🦘", "🦡", "🐾", "🦃", "🐔", "🐓", "🐣", "🐤", "🐥", "🐦", "🐧", "🕊️", "🕊", "🦅", "🦆", "🦢", "🦉", "🦤", "🪶", "🦩", "🦚", "🦜", "🐸", "🐊", "🐢", "🦎", "🐍", "🐲", "🐉", "🦕", "🦖", "🐳", "🐋", "🐬", "🦭", "🐟", "🐠", "🐡", "🦈", "🐙", "🐚", "🪸", "🐌", "🦋", "🐛", "🐜", "🐝", "🪲", "🐞", "🦗", "🪳", "🕷️", "🕷", "🕸️", "🕸", "🦂", "🦟", "🪰", "🪱", "🦠", "💐", "🌸", "💮", "🪷", "🏵️", "🏵", "🌹", "🥀", "🌺", "🌻", "🌼", "🌷", "🌱", "🪴", "🌲", "🌳", "🌴", "🌵", "🌾", "🌿", "☘️", "☘", "🍀", "🍁", "🍂", "🍃", "🪹", "🪺", "🍇", "🍈", "🍉", "🍊", "🍋", "🍌", "🍍", "🥭", "🍎", "🍏", "🍐", "🍑", "🍒", "🍓", "🫐", "🥝", "🍅", "🫒", "🥥", "🥑", "🍆", "🥔", "🥕", "🌽", "🌶️", "🌶", "🫑", "🥒", "🥬", "🥦", "🧄", "🧅", "🍄", "🥜", "🫘", "🌰", "🍞", "🥐", "🥖", "🫓", "🥨", "🥯", "🥞", "🧇", "🧀", "🍖", "🍗", "🥩", "🥓", "🍔", "🍟", "🍕", "🌭", "🥪", "🌮", "🌯", "🫔", "🥙", "🧆", "🥚", "🍳", "🥘", "🍲", "🫕", "🥣", "🥗", "🍿", "🧈", "🧂", "🥫", "🍱", "🍘", "🍙", "🍚", "🍛", "🍜", "🍝", "🍠", "🍢", "🍣", "🍤", "🍥", "🥮", "🍡", "🥟", "🥠", "🥡", "🦀", "🦞", "🦐", "🦑", "🦪", "🍦", "🍧", "🍨", "🍩", "🍪", "🎂", "🍰", "🧁", "🥧", "🍫", "🍬", "🍭", "🍮", "🍯", "🍼", "🥛", "☕", "🫖", "🍵", "🍶", "🍾", "🍷", "🍸", "🍹", "🍺", "🍻", "🥂", "🥃", "🫗", "🥤", "🧋", "🧃", "🧉", "🧊", "🥢", "🍽️", "🍽", "🍴", "🥄", "🔪", "🫙", "🏺", "🌍", "🌎", "🌏", "🌐", "🗺️", "🗺", "🗾", "🧭", "🏔️", "🏔", "⛰️", "⛰", "🌋", "🗻", "🏕️", "🏕", "🏖️", "🏖", "🏜️", "🏜", "🏝️", "🏝", "🏞️", "🏞", "🏟️", "🏟", "🏛️", "🏛", "🏗️", "🏗", "🧱", "🪨", "🪵", "🛖", "🏘️", "🏘", "🏚️", "🏚", "🏠", "🏡", "🏢", "🏣", "🏤", "🏥", "🏦", "🏨", "🏩", "🏪", "🏫", "🏬", "🏭", "🏯", "🏰", "💒", "🗼", "🗽", "⛪", "🕌", "🛕", "🕍", "⛩️", "⛩", "🕋", "⛲", "⛺", "🌁", "🌃", "🏙️", "🏙", "🌄", "🌅", "🌆", "🌇", "🌉", "♨️", "♨", "🎠", "🛝", "🎡", "🎢", "💈", "🎪", "🚂", "🚃", "🚄", "🚅", "🚆", "🚇", "🚈", "🚉", "🚊", "🚝", "🚞", "🚋", "🚌", "🚍", "🚎", "🚐", "🚑", "🚒", "🚓", "🚔", "🚕", "🚖", "🚗", "🚘", "🚙", "🛻", "🚚", "🚛", "🚜", "🏎️", "🏎", "🏍️", "🏍", "🛵", "🦽", "🦼", "🛺", "🚲", "🛴", "🛹", "🛼", "🚏", "🛣️", "🛣", "🛤️", "🛤", "🛢️", "🛢", "⛽", "🛞", "🚨", "🚥", "🚦", "🛑", "🚧", "⚓", "🛟", "⛵", "🛶", "🚤", "🛳️", "🛳", "⛴️", "⛴", "🛥️", "🛥", "🚢", "✈️", "✈", "🛩️", "🛩", "🛫", "🛬", "🪂", "💺", "🚁", "🚟", "🚠", "🚡", "🛰️", "🛰", "🚀", "🛸", "🛎️", "🛎", "🧳", "⌛", "⏳", "⌚", "⏰", "⏱️", "⏱", "⏲️", "⏲", "🕰️", "🕰", "🕛", "🕧", "🕐", "🕜", "🕑", "🕝", "🕒", "🕞", "🕓", "🕟", "🕔", "🕠", "🕕", "🕡", "🕖", "🕢", "🕗", "🕣", "🕘", "🕤", "🕙", "🕥", "🕚", "🕦", "🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘", "🌙", "🌚", "🌛", "🌜", "🌡️", "🌡", "☀️", "☀", "🌝", "🌞", "🪐", "⭐", "🌟", "🌠", "🌌", "☁️", "☁", "⛅", "⛈️", "⛈", "🌤️", "🌤", "🌥️", "🌥", "🌦️", "🌦", "🌧️", "🌧", "🌨️", "🌨", "🌩️", "🌩", "🌪️", "🌪", "🌫️", "🌫", "🌬️", "🌬", "🌀", "🌈", "🌂", "☂️", "☂", "☔", "⛱️", "⛱", "⚡", "❄️", "❄", "☃️", "☃", "⛄", "☄️", "☄", "🔥", "💧", "🌊", "🎃", "🎄", "🎆", "🎇", "🧨", "✨", "🎈", "🎉", "🎊", "🎋", "🎍", "🎎", "🎏", "🎐", "🎑", "🧧", "🎀", "🎁", "🎗️", "🎗", "🎟️", "🎟", "🎫", "🎖️", "🎖", "🏆", "🏅", "🥇", "🥈", "🥉", "⚽", "⚾", "🥎", "🏀", "🏐", "🏈", "🏉", "🎾", "🥏", "🎳", "🏏", "🏑", "🏒", "🥍", "🏓", "🏸", "🥊", "🥋", "🥅", "⛳", "⛸️", "⛸", "🎣", "🤿", "🎽", "🎿", "🛷", "🥌", "🎯", "🪀", "🪁", "🎱", "🔮", "🪄", "🧿", "🪬", "🎮", "🕹️", "🕹", "🎰", "🎲", "🧩", "🧸", "🪅", "🪩", "🪆", "♠️", "♠", "♥️", "♥", "♦️", "♦", "♣️", "♣", "♟️", "♟", "🃏", "🀄", "🎴", "🎭", "🖼️", "🖼", "🎨", "🧵", "🪡", "🧶", "🪢", "👓", "🕶️", "🕶", "🥽", "🥼", "🦺", "👔", "👕", "👖", "🧣", "🧤", "🧥", "🧦", "👗", "👘", "🥻", "🩱", "🩲", "🩳", "👙", "👚", "👛", "👜", "👝", "🛍️", "🛍", "🎒", "🩴", "👞", "👟", "🥾", "🥿", "👠", "👡", "🩰", "👢", "👑", "👒", "🎩", "🎓", "🧢", "🪖", "⛑️", "⛑", "📿", "💄", "💍", "💎", "🔇", "🔈", "🔉", "🔊", "📢", "📣", "📯", "🔔", "🔕", "🎼", "🎵", "🎶", "🎙️", "🎙", "🎚️", "🎚", "🎛️", "🎛", "🎤", "🎧", "📻", "🎷", "🪗", "🎸", "🎹", "🎺", "🎻", "🪕", "🥁", "🪘", "📱", "📲", "☎️", "☎", "📞", "📟", "📠", "🔋", "🪫", "🔌", "💻", "🖥️", "🖥", "🖨️", "🖨", "⌨️", "⌨", "🖱️", "🖱", "🖲️", "🖲", "💽", "💾", "💿", "📀", "🧮", "🎥", "🎞️", "🎞", "📽️", "📽", "🎬", "📺", "📷", "📸", "📹", "📼", "🔍", "🔎", "🕯️", "🕯", "💡", "🔦", "🏮", "🪔", "📔", "📕", "📖", "📗", "📘", "📙", "📚", "📓", "📒", "📃", "📜", "📄", "📰", "🗞️", "🗞", "📑", "🔖", "🏷️", "🏷", "💰", "🪙", "💴", "💵", "💶", "💷", "💸", "💳", "🧾", "💹", "✉️", "✉", "📧", "📨", "📩", "📤", "📥", "📦", "📫", "📪", "📬", "📭", "📮", "🗳️", "🗳", "✏️", "✏", "✒️", "✒", "🖋️", "🖋", "🖊️", "🖊", "🖌️", "🖌", "🖍️", "🖍", "📝", "💼", "📁", "📂", "🗂️", "🗂", "📅", "📆", "🗒️", "🗒", "🗓️", "🗓", "📇", "📈", "📉", "📊", "📋", "📌", "📍", "📎", "🖇️", "🖇", "📏", "📐", "✂️", "✂", "🗃️", "🗃", "🗄️", "🗄", "🗑️", "🗑", "🔒", "🔓", "🔏", "🔐", "🔑", "🗝️", "🗝", "🔨", "🪓", "⛏️", "⛏", "⚒️", "⚒", "🛠️", "🛠", "🗡️", "🗡", "⚔️", "⚔", "🔫", "🪃", "🏹", "🛡️", "🛡", "🪚", "🔧", "🪛", "🔩", "⚙️", "⚙", "🗜️", "🗜", "⚖️", "⚖", "🦯", "🔗", "⛓️", "⛓", "🪝", "🧰", "🧲", "🪜", "⚗️", "⚗", "🧪", "🧫", "🧬", "🔬", "🔭", "📡", "💉", "🩸", "💊", "🩹", "🩼", "🩺", "����", "🚪", "🛗", "🪞", "🪟", "🛏️", "🛏", "🛋️", "🛋", "🪑", "🚽", "🪠", "🚿", "🛁", "🪤", "🪒", "🧴", "🧷", "🧹", "🧺", "🧻", "🪣", "🧼", "🫧", "🪥", "🧽", "🧯", "🛒", "🚬", "⚰️", "⚰", "🪦", "⚱️", "⚱", "🗿", "🪧", "🪪", "🏧", "🚮", "🚰", "♿", "🚹", "🚺", "🚻", "🚼", "🚾", "🛂", "🛃", "🛄", "🛅", "⚠️", "⚠", "🚸", "⛔", "🚫", "🚳", "🚭", "🚯", "🚱", "🚷", "📵", "🔞", "☢️", "☢", "☣️", "☣", "⬆️", "⬆", "↗️", "↗", "➡️", "➡", "↘️", "↘", "⬇️", "⬇", "↙️", "↙", "⬅️", "⬅", "↖️", "↖", "↕️", "↕", "↔️", "↩️", "↩", "↪️", "↪", "⤴️", "⤴", "⤵️", "⤵", "🔃", "🔄", "🔙", "🔚", "🔛", "🔜", "🔝", "🛐", "⚛️", "⚛", "🕉️", "🕉", "✡️", "✡", "☸️", "☸", "☯️", "☯", "✝️", "✝", "☦️", "☦", "☪️", "☪", "☮️", "☮", "🕎", "🔯", "♈", "♉", "♊", "♋", "♌", "♍", "♎", "♏", "♐", "♑", "♒", "♓", "⛎", "🔀", "🔁", "🔂", "▶️", "⏩", "⏭️", "⏭", "⏯️", "⏯", "◀️", "⏪", "⏮️", "⏮", "🔼", "⏫", "🔽", "⏬", "⏸️", "⏸", "⏹️", "⏹", "⏺️", "⏺", "⏏️", "⏏", "🎦", "🔅", "🔆", "📶", "📳", "📴", "♀️", "♀", "♂️", "♂", "⚧️", "⚧", "✖️", "✖", "➕", "➖", "➗", "🟰", "♾️", "♾", "‼️", "‼", "⁉️", "⁉", "❓", "❔", "❕", "❗", "〰️", "〰", "💱", "💲", "⚕️", "⚕", "♻️", "♻", "⚜️", "⚜", "🔱", "📛", "🔰", "⭕", "✅", "☑️", "☑", "✔️", "✔", "❌", "❎", "➰", "➿", "〽️", "〽", "✳️", "✳", "✴️", "✴", "❇️", "❇", "©️", "©", "®️", "®", "™️", "#️⃣", "#⃣", "*️⃣", "*⃣", "0️⃣", "0⃣", "1️⃣", "1⃣", "2️⃣", "2⃣", "3️⃣", "3⃣", "4️⃣", "4⃣", "5️⃣", "5⃣", "6️⃣", "6⃣", "7️⃣", "7⃣", "8️⃣", "8⃣", "9️⃣", "9⃣", "🔟", "🔠", "🔡", "🔢", "🔣", "🔤", "🅰️", "🅰", "🆎", "🅱️", "🅱", "🆑", "🆒", "🆓", "ℹ️", "ℹ", "🆔", "Ⓜ️", "Ⓜ", "🆕", "🆖", "🅾️", "🅾", "🆗", "🅿️", "🅿", "🆘", "🆙", "🆚", "🈁", "🈂️", "🈂", "🈷️", "🈷", "🈶", "🈯", "🉐", "🈹", "🈚", "🈲", "🉑", "🈸", "🈴", "🈳", "㊗️", "㊗", "㊙️", "㊙", "🈺", "🈵", "🔴", "🟠", "🟡", "🟢", "🔵", "🟣", "🟤", "⚫", "⚪", "🟥", "🟧", "🟨", "🟩", "🟦", "🟪", "🟫", "⬛", "⬜", "◼️", "◼", "◻️", "◻", "◾", "◽", "▪️", "▪", "▫️", "▫", "🔶", "🔷", "🔸", "🔹", "🔺", "🔻", "💠", "🔘", "🔳", "🔲", "🏁", "🚩", "🎌", "🏴", "🏳️", "🏳", "🏳️🌈", "🏳🌈", "🏳️⚧️", "🏴☠️", "🏴☠", "🇦🇨", "🇦🇩", "🇦🇪", "🇦🇫", "🇦🇬", "🇦🇮", "🇦🇱", "🇦🇲", "🇦🇴", "🇦🇶", "🇦🇷", "🇦🇸", "🇦🇹", "🇦🇺", "🇦🇼", "🇦🇽", "🇦🇿", "🇧🇦", "🇧🇧", "🇧🇩", "🇧🇪", "🇧🇫", "🇧🇬", "🇧🇭", "🇧🇮", "🇧🇯", "🇧🇱", "🇧🇲", "🇧🇳", "🇧🇴", "🇧🇶", "🇧🇷", "🇧🇸", "🇧🇹", "🇧🇻", "🇧🇼", "🇧🇾", "🇧🇿", "🇨🇦", "🇨🇨", "🇨🇩", "🇨🇫", "🇨🇬", "🇨🇭", "🇨🇮", "🇨🇰", "🇨🇱", "🇨🇲", "🇨🇳", "🇨🇴", "🇨🇵", "🇨🇷", "🇨🇺", "🇨🇻", "🇨🇼", "🇨🇽", "🇨🇾", "🇨🇿", "🇩🇪", "🇩🇬", "🇩🇯", "🇩🇰", "🇩🇲", "🇩🇴", "🇩🇿", "🇪🇦", "🇪🇨", "🇪🇪", "🇪🇬", "🇪🇭", "🇪🇷", "🇪🇸", "🇪🇹", "🇪🇺", "🇫🇮", "🇫🇯", "🇫🇰", "🇫🇲", "🇫🇴", "🇫🇷", "🇬🇦", "🇬🇧", "🇬🇩", "🇬🇪", "🇬🇫", "🇬🇬", "🇬🇭", "🇬🇮", "🇬🇱", "🇬🇲", "🇬🇳", "🇬🇵", "🇬🇶", "🇬🇷", "🇬🇸", "🇬🇹", "🇬🇺", "🇬🇼", "🇬🇾", "🇭🇰", "🇭🇲", "🇭🇳", "🇭🇷", "🇭🇹", "🇭🇺", "🇮🇨", "🇮🇩", "🇮🇪", "🇮🇱", "🇮🇲", "🇮🇳", "🇮🇴", "🇮🇶", "🇮🇷", "🇮🇸", "🇮🇹", "🇯🇪", "🇯🇲", "🇯🇴", "🇯🇵", "🇰🇪", "🇰🇬", "🇰🇭", "🇰🇮", "🇰🇲", "🇰🇳", "🇰🇵", "🇰🇷", "🇰🇼", "🇰🇾", "🇰🇿", "🇱🇦", "🇱🇧", "🇱🇨", "🇱🇮", "🇱🇰", "🇱🇷", "🇱🇸", "🇱🇹", "🇱🇺", "🇱🇻", "🇱🇾", "🇲🇦", "🇲🇨", "🇲🇩", "🇲🇪", "🇲🇫", "🇲🇬", "🇲🇭", "🇲🇰", "🇲🇱", "🇲🇲", "🇲🇳", "🇲🇴", "🇲🇵", "🇲🇶", "🇲🇷", "🇲🇸", "🇲🇹", "🇲🇺", "🇲🇻", "🇲🇼", "🇲🇽", "🇲🇾", "🇲🇿", "🇳🇦", "🇳🇨", "🇳🇪", "🇳🇫", "🇳🇬", "🇳🇮", "🇳🇱", "🇳🇴", "🇳🇵", "🇳🇷", "🇳🇺", "🇳🇿", "🇴🇲", "🇵🇦", "🇵🇪", "🇵🇫", "🇵🇬", "🇵🇭", "🇵🇰", "🇵🇱", "🇵🇲", "🇵🇳", "🇵🇷", "🇵🇸", "🇵🇹", "🇵🇼", "🇵🇾", "🇶🇦", "🇷🇪", "🇷🇴", "🇷🇸", "🇷🇺", "🇷🇼", "🇸🇦", "🇸🇧", "🇸🇨", "🇸🇩", "🇸🇪", "🇸🇬", "🇸🇭", "🇸🇮", "🇸🇯", "🇸🇰", "🇸🇱", "🇸🇲", "🇸🇳", "🇸🇴", "🇸🇷", "🇸🇸", "🇸🇹", "🇸🇻", "🇸🇽", "🇸🇾", "🇸🇿", "🇹🇦", "🇹🇨", "🇹🇩", "🇹🇫", "🇹🇬", "🇹🇭", "🇹🇯", "🇹🇰", "🇹🇱", "🇹🇲", "🇹🇳", "🇹🇴", "🇹🇷", "🇹🇹", "🇹🇻", "🇹🇼", "🇹🇿", "🇺🇦", "🇺🇬", "🇺🇲", "🇺🇳", "🇺🇸", "🇺🇾", "🇺🇿", "🇻🇦", "🇻🇨", "🇻🇪", "🇻🇬", "🇻🇮", "🇻🇳", "🇻🇺", "🇼🇫", "🇼🇸", "🇽🇰", "🇾🇪", "🇾🇹", "🇿🇦", "🇿🇲", "🇿🇼", "🏴", "🏴", "🏴"]from components.notion.blocks import (create_page, create_database, create_divider, create_table_of_contents, create_heading,create_paragraph, create_list, create_todo_list, create_toggle, create_column_list, create_callout,create_quote, create_table)def pretty_print_blueprint(blueprint_json):print(json.dumps(blueprint_json, indent=4))def process_blueprint(parent_id, block_json, def_env_var=True, notion_key=None, parent_type=None):block_type = block_json["type"]page_id = parent_idprint(f"Processing block_type '{block_type}' inside parent_type '{parent_type}' with id '{page_id}'")if block_type == "page":title = block_json.get("title", "Untitled Page")emojis = [em for em in emoji.EMOJI_DATA if not any(char in em for char in ["🏻", "🏼", "🏽", "🏾", "🏿", "\u200d"]) and not em.startswith(("🇦", "🇧", "🇨", "🇩", "🇪", "🇫", "🇬", "🇭", "🇮", "🇯", "🇰", "🇱", "🇲", "🇳", "🇴", "🇵", "🇶", "🇷", "🇸", "🇹", "🇺", "🇻", "🇼", "🇽", "🇾", "🇿"))]icon = block_json.get("icon", random.choice(emojis))is_valid_icon = icon in NOTION_VALID_EMOJISif not is_valid_icon:icon = random.choice(emojis)properties = block_json.get("properties", {})page_id = create_page(parent_id, title, icon, properties, cover_image=True, def_env_var=def_env_var, notion_key=notion_key, parent_type=parent_type)["id"]for child in block_json.get("children", []):process_blueprint(page_id, child, def_env_var=def_env_var, notion_key=notion_key, parent_type=block_type)# TODO - Create child pages inside the databaseelif block_type == "database":title = block_json.get("title", "Untitled Database")emojis = [em for em in emoji.EMOJI_DATA if not any(char in em for char in ["🏻", "🏼", "🏽", "🏾", "🏿", "\u200d"]) and not em.startswith(("🇦", "🇧", "🇨", "🇩", "🇪", "🇫", "🇬", "🇭", "🇮", "🇯", "🇰", "🇱", "🇲", "🇳", "🇴", "🇵", "🇶", "🇷", "🇸", "🇹", "🇺", "🇻", "🇼", "🇽", "🇾", "🇿"))]icon = block_json.get("icon", random.choice(emojis))schema = block_json.get("schema", {})is_inline = block_json.get("is_inline", False)create_database(parent_id, title, icon, schema, is_inline=is_inline, cover_image=True, def_env_var=def_env_var, notion_key=notion_key, parent_type=parent_type)elif block_type == "divider":create_divider(parent_id, notion_key=notion_key, parent_type=parent_type)elif block_type == "table_of_contents":create_table_of_contents(parent_id, notion_key=notion_key, parent_type=parent_type)elif block_type.startswith("heading_"):text = block_json.get("text", "")level = int(block_type.split("_")[1])create_heading(parent_id, text, level, notion_key=notion_key, parent_type=parent_type)elif block_type == "paragraph":text_blocks = block_json.get("content", [])create_paragraph(parent_id, text_blocks, notion_key=notion_key, parent_type=parent_type)elif block_type in ["bulleted_list", "numbered_list"]:items = block_json.get("items", [])create_list(parent_id, items, bulleted=True if block_type == "bulleted_list" else False, notion_key=notion_key, parent_type=parent_type)elif block_type == "to_do_list":items = block_json.get("items", [])create_todo_list(parent_id, items, notion_key=notion_key, parent_type=parent_type)elif block_type == "toggle":title = block_json.get("title", "Untitled Toggle")toggle_id = create_toggle(parent_id, title, notion_key=notion_key, parent_type=parent_type)["results"][0]["id"]for child in block_json.get("children", []):process_blueprint(toggle_id, child, def_env_var=def_env_var, notion_key=notion_key, parent_type=block_type)elif block_type == "column_list":num_columns = len(block_json.get("columns", []))column_ids = create_column_list(parent_id, num_columns, notion_key=notion_key, parent_type=parent_type)for i, column in enumerate(block_json.get("columns", [])):for child in column.get("children", []):process_blueprint(column_ids[i], child, def_env_var=def_env_var, notion_key=notion_key, parent_type=block_type)elif block_type == "callout":text_blocks = block_json.get("content", [])icon = block_json.get("icon", "💡")color = block_json.get("color", "default")callout_id = create_callout(parent_id, text_blocks, icon, color, notion_key=notion_key, parent_type=parent_type)["results"][0]["id"]for child in block_json.get("children", []):process_blueprint(callout_id, child, def_env_var=def_env_var, notion_key=notion_key, parent_type=block_type)elif block_type == "quote":text_blocks = block_json.get("content", [])quote_id = create_quote(parent_id, text_blocks, notion_key=notion_key, parent_type=parent_type)["results"][0]["id"]for child in block_json.get("children", []):process_blueprint(quote_id, child, def_env_var=def_env_var, notion_key=notion_key, parent_type=block_type)elif block_type == "table":rows = block_json.get("rows", [])table_id = create_table(parent_id, rows, notion_key=notion_key, parent_type=parent_type)["results"][0]["id"]# for child in block_json.get("children", []):# process_blueprint(table_id, child, def_env_var=def_env_var, notion_key=notion_key, parent_type=parent_type)return page_iddef to_notion(page_json,notion_key,parent_page_id,parent_page_type):# print(type(page_json))# pretty_print_blueprint(page_json)page_title = page_json.get("title", "Untitled Page")new_page_id = process_blueprint(parent_id=parent_page_id,block_json=page_json,notion_key=notion_key,parent_type=parent_page_type)new_page_link = f"https://notion.so/{new_page_id.replace('-','')}"# page_link = f"""🟢 🎉 <span style="color:#006400">Success! Generated Notion Page Link:</span> [{page_title}](https://notion.so/{new_page_id.replace('-','')})"""# print(f"""🟢 🎉 Success! Generated Notion Page Link: [{page_title}](https://notion.so/{new_page_id.replace('-','')})""")return new_page_id, page_title, new_page_link # DO NOT 'YIELD' WHEN USING AS LAMBDAdef to_notion_new(page_json,notion_key,parent_page_id,parent_page_type):# print(type(page_json))# pretty_print_blueprint(page_json)try:page_type = page_json["type"]if page_type == "page":page_title = page_json.get("title", "Untitled Page")print(f"🟡 ⏳ Creating {page_type} '{page_title}' inside parent_type '{parent_page_type}'")emojis = [em for em in emoji.EMOJI_DATA if not any(char in em for char in ["🏻", "🏼", "🏽", "🏾", "🏿", "\u200d"]) and not em.startswith(("🇦", "🇧", "🇨", "🇩", "🇪", "🇫", "🇬", "🇭", "🇮", "🇯", "🇰", "🇱", "🇲", "🇳", "🇴", "🇵", "🇶", "🇷", "🇸", "🇹", "🇺", "🇻", "🇼", "🇽", "🇾", "🇿"))]icon = page_json.get("icon", random.choice(emojis))is_valid_icon = icon in NOTION_VALID_EMOJISif not is_valid_icon:icon = random.choice(emojis)properties = page_json.get("properties", {})new_page_id = create_page(parent_page_id, page_title, icon, properties, cover_image=True, notion_key=notion_key, parent_type=parent_page_type)["id"]print(f"🟢 🎉 Created {page_type} '{page_title}' inside parent_type '{parent_page_type}'")new_page_link = f"https://notion.so/{new_page_id.replace('-','')}"yield page_type, new_page_id, page_title, new_page_link # DO NOT 'YIELD' WHEN USING AS LAMBDAfor child in page_json.get("children", []):block_type = child["type"]process_blueprint(parent_id=new_page_id,block_json=child,notion_key=notion_key,parent_type=page_type)yield block_type, new_page_id, page_title, new_page_linkyield "end", new_page_id, page_title, new_page_linkelse:yield f"unsupported {page_type}", None, None, Noneexcept Exception as e:yield f"error {e}", None, None, None12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import jsonimport codecsNOTION_VALID_EMOJIS = ["😀", "😃", "😄", "😁", "😆", "😅", "🤣", "😂", "🙂", "🙃", "🫠", "😉", "😊", "😇", "🥰", "😍", "🤩", "😘", "😗", "☺️", "☺", "😚", "😙", "🥲", "😋", "😛", "😜", "🤪", "😝", "🤑", "🤗", "🤭", "🫢", "🫣", "🤫", "🤔", "🫡", "🤐", "🤨", "😐", "😑", "😶", "🫥", "😶🌫️", "😶🌫", "😏", "😒", "🙄", "😬", "😮💨", "🤥", "😌", "😔", "😪", "🤤", "😴", "😷", "🤒", "🤕", "🤢", "🤮", "🤧", "🥵", "🥶", "🥴", "😵", "😵💫", "🤯", "🤠", "🥳", "🥸", "😎", "🤓", "🧐", "😕", "🫤", "😟", "🙁", "☹️", "☹", "😮", "😯", "😲", "😳", "🥺", "🥹", "😦", "😧", "😨", "😰", "😥", "😢", "😭", "😱", "😖", "😣", "😞", "😓", "😩", "😫", "🥱", "😤", "😡", "😠", "🤬", "😈", "👿", "💀", "☠️", "☠", "💩", "🤡", "👹", "👺", "👻", "👽", "👾", "🤖", "😺", "😸", "😹", "😻", "😼", "😽", "🙀", "😿", "😾", "🙈", "🙉", "🙊", "💋", "💌", "💘", "💝", "💖", "💗", "💓", "💞", "💕", "💟", "❣️", "❣", "💔", "❤️🔥", "❤🔥", "❤️🩹", "❤🩹", "❤️", "❤", "🧡", "💛", "💚", "💙", "💜", "🤎", "🖤", "🤍", "💯", "💢", "💥", "💫", "💦", "💨", "🕳️", "🕳", "💣", "💬", "👁️🗨️", "🗨️", "🗨", "🗯️", "🗯", "💭", "💤", "👋🏻", "👋🏼", "👋🏽", "👋🏾", "👋🏿", "👋", "🤚🏻", "🤚🏼", "🤚🏽", "🤚🏾", "🤚🏿", "🤚", "🖐🏻", "🖐🏼", "🖐🏽", "🖐🏾", "🖐🏿", "🖐️", "🖐", "✋🏻", "✋🏼", "✋🏽", "✋🏾", "✋🏿", "✋", "🖖🏻", "🖖🏼", "🖖🏽", "🖖🏾", "🖖🏿", "🖖", "🫱🏻", "🫱🏼", "🫱🏽", "🫱🏾", "🫱🏿", "🫱", "🫲🏻", "🫲🏼", "🫲🏽", "🫲🏾", "🫲🏿", "🫲", "🫳🏻", "🫳🏼", "🫳🏽", "🫳🏾", "🫳🏿", "🫳", "🫴🏻", "🫴🏼", "🫴🏽", "🫴🏾", "🫴🏿", "🫴", "👌🏻", "👌🏼", "👌🏽", "👌🏾", "👌🏿", "👌", "🤌🏻", "🤌🏼", "🤌🏽", "🤌🏾", "🤌🏿", "🤌", "🤏🏻", "🤏🏼", "🤏🏽", "🤏🏾", "🤏🏿", "🤏", "✌🏻", "✌🏼", "✌🏽", "✌🏾", "✌🏿", "✌️", "✌", "🤞🏻", "🤞🏼", "🤞🏽", "🤞🏾", "🤞🏿", "🤞", "🫰🏻", "🫰🏼", "🫰🏽", "🫰🏾", "🫰🏿", "🫰", "🤟🏻", "🤟🏼", "🤟🏽", "🤟🏾", "🤟🏿", "🤟", "🤘🏻", "🤘🏼", "🤘🏽", "🤘🏾", "🤘🏿", "🤘", "🤙🏻", "🤙🏼", "🤙🏽", "🤙🏾", "🤙🏿", "🤙", "👈🏻", "👈🏼", "👈🏽", "👈🏾", "👈🏿", "👈", "👉🏻", "👉🏼", "👉🏽", "👉🏾", "👉🏿", "👉", "👆🏻", "👆🏼", "👆🏽", "👆🏾", "👆🏿", "👆", "🖕🏻", "🖕🏼", "🖕🏽", "🖕🏾", "🖕🏿", "🖕", "👇🏻", "👇🏼", "👇🏽", "👇🏾", "👇🏿", "👇", "☝🏻", "☝🏼", "☝🏽", "☝🏾", "☝🏿", "☝️", "☝", "🫵🏻", "🫵🏼", "🫵🏽", "🫵🏾", "🫵🏿", "🫵", "👍🏻", "👍🏼", "👍🏽", "👍🏾", "👍🏿", "👍", "👎🏻", "👎🏼", "👎🏽", "👎🏾", "👎🏿", "👎", "✊🏻", "✊🏼", "✊🏽", "✊🏾", "✊🏿", "✊", "👊🏻", "👊🏼", "👊🏽", "👊🏾", "👊🏿", "👊", "🤛🏻", "🤛🏼", "🤛🏽", "🤛🏾", "🤛🏿", "🤛", "🤜🏻", "🤜🏼", "🤜🏽", "🤜🏾", "🤜🏿", "🤜", "👏🏻", "👏🏼", "👏🏽", "👏🏾", "👏🏿", "👏", "🙌🏻", "🙌🏼", "🙌🏽", "🙌🏾", "🙌🏿", "🙌", "🫶🏻", "🫶🏼", "🫶🏽", "🫶🏾", "🫶🏿", "🫶", "👐🏻", "👐🏼", "👐🏽", "👐🏾", "👐🏿", "👐", "🤲🏻", "🤲🏼", "🤲🏽", "🤲🏾", "🤲🏿", "🤲", "🤝🏻", "🤝🏼", "🤝🏽", "🤝🏾", "🤝🏿", "🫱🏻🫲🏼", "🫱🏻🫲🏽", "🫱🏻🫲🏾", "🫱🏻🫲🏿", "🫱🏼🫲🏻", "🫱🏼🫲🏽", "🫱🏼🫲🏾", "🫱🏼🫲🏿", "🫱🏽🫲🏻", "🫱🏽🫲🏼", "🫱🏽🫲🏾", "🫱🏽🫲🏿", "🫱🏾🫲🏻", "🫱🏾🫲🏼", "🫱🏾🫲🏽", "🫱🏾🫲🏿", "🫱🏿🫲🏻", "🫱🏿🫲🏼", "🫱🏿🫲🏽", "🫱🏿🫲🏾", "🤝", "🙏🏻", "🙏🏼", "🙏🏽", "🙏🏾", "🙏🏿", "🙏", "✍🏻", "✍🏼", "✍🏽", "✍🏾", "✍🏿", "✍️", "✍", "💅🏻", "💅🏼", "💅🏽", "💅🏾", "💅🏿", "💅", "🤳🏻", "🤳🏼", "🤳🏽", "🤳🏾", "🤳🏿", "🤳", "💪🏻", "💪🏼", "💪🏽", "💪🏾", "💪🏿", "💪", "🦾", "🦿", "🦵🏻", "🦵🏼", "🦵🏽", "🦵🏾", "🦵🏿", "🦵", "🦶🏻", "🦶🏼", "🦶🏽", "🦶🏾", "🦶🏿", "🦶", "👂🏻", "👂🏼", "👂🏽", "👂🏾", "👂🏿", "👂", "🦻🏻", "🦻🏼", "🦻🏽", "🦻🏾", "🦻🏿", "🦻", "👃🏻", "👃🏼", "👃🏽", "👃🏾", "👃🏿", "👃", "🧠", "🫀", "🫁", "🦷", "🦴", "👀", "👁️", "👁", "👅", "👄", "🫦", "👶🏻", "👶🏼", "👶🏽", "👶🏾", "👶🏿", "👶", "🧒🏻", "🧒🏼", "🧒🏽", "🧒🏾", "🧒🏿", "🧒", "👦🏻", "👦🏼", "👦🏽", "👦🏾", "👦🏿", "👦", "👧🏻", "👧🏼", "👧🏽", "👧🏾", "👧🏿", "👧", "🧑🏻", "🧑🏼", "🧑🏽", "🧑🏾", "🧑🏿", "🧑", "👱🏻", "👱🏼", "👱🏽", "👱🏾", "👱🏿", "👱", "👨🏻", "👨🏼", "👨🏽", "👨🏾", "👨🏿", "👨", "🧔🏻", "🧔🏼", "🧔🏽", "🧔🏾", "🧔🏿", "🧔", "🧔🏻♂️", "🧔🏼♂️", "🧔🏽♂️", "🧔🏾♂️", "🧔🏿♂️", "🧔♂️", "🧔♂", "🧔🏻♀️", "🧔🏼♀️", "🧔🏽♀️", "🧔🏾♀️", "🧔🏿♀️", "🧔♀️", "🧔♀", "👨🏻🦰", "👨🏼🦰", "👨🏽🦰", "👨🏾🦰", "👨🏿🦰", "👨🦰", "👨🏻🦱", "👨🏼🦱", "👨🏽🦱", "👨🏾🦱", "👨🏿🦱", "👨🦱", "👨🏻🦳", "👨🏼🦳", "👨🏽🦳", "👨🏾🦳", "👨🏿🦳", "👨🦳", "👨🏻🦲", "👨🏼🦲", "👨🏽🦲", "👨🏾🦲", "👨🏿🦲", "👨🦲", "👩🏻", "👩🏼", "👩🏽", "👩🏾", "👩🏿", "👩", "👩🏻🦰", "👩🏼🦰", "👩🏽🦰", "👩🏾🦰", "👩🏿🦰", "👩🦰", "🧑🏻🦰", "🧑🏼🦰", "🧑🏽🦰", "🧑🏾🦰", "🧑🏿🦰", "🧑🦰", "👩🏻🦱", "👩🏼🦱", "👩🏽🦱", "👩🏾🦱", "👩🏿🦱", "👩🦱", "🧑🏻🦱", "🧑🏼🦱", "🧑🏽🦱", "🧑🏾🦱", "🧑🏿🦱", "🧑🦱", "👩🏻🦳", "👩🏼🦳", "👩🏽🦳", "👩🏾🦳", "👩🏿🦳", "👩🦳", "🧑🏻🦳", "🧑🏼🦳", "🧑🏽🦳", "🧑🏾🦳", "🧑🏿🦳", "🧑🦳", "👩🏻🦲", "👩🏼🦲", "👩🏽🦲", "👩🏾🦲", "👩🏿🦲", "👩🦲", "🧑🏻🦲", "🧑🏼🦲", "🧑🏽🦲", "🧑🏾🦲", "🧑🏿🦲", "🧑🦲", "👱🏻♀️", "👱🏼♀️", "👱🏽♀️", "👱🏾♀️", "👱🏿♀️", "👱♀️", "👱♀", "👱🏻♂️", "👱🏼♂️", "👱🏽♂️", "👱🏾♂️", "👱🏿♂️", "👱♂️", "👱♂", "🧓🏻", "🧓🏼", "🧓🏽", "🧓🏾", "🧓🏿", "🧓", "👴🏻", "👴🏼", "👴🏽", "👴🏾", "👴🏿", "👴", "👵🏻", "👵🏼", "👵🏽", "👵🏾", "👵🏿", "👵", "🙍🏻", "🙍🏼", "🙍🏽", "🙍🏾", "🙍🏿", "🙍", "🙍🏻♂️", "🙍🏼♂️", "🙍🏽♂️", "🙍🏾♂️", "🙍🏿♂️", "🙍♂️", "🙍♂", "🙍🏻♀️", "🙍🏼♀️", "🙍🏽♀️", "🙍🏾♀️", "🙍🏿♀️", "🙍♀️", "🙍♀", "🙎🏻", "🙎🏼", "🙎🏽", "🙎🏾", "🙎🏿", "🙎", "🙎🏻♂️", "🙎🏼♂️", "🙎🏽♂️", "🙎🏾♂️", "🙎🏿♂️", "🙎♂️", "🙎♂", "🙎🏻♀️", "🙎🏼♀️", "🙎🏽♀️", "🙎🏾♀️", "🙎🏿♀️", "🙎♀️", "🙎♀", "🙅🏻", "🙅🏼", "🙅🏽", "🙅🏾", "🙅🏿", "🙅", "🙅🏻♂️", "🙅🏼♂️", "🙅🏽♂️", "🙅🏾♂️", "🙅🏿♂️", "🙅♂️", "🙅♂", "🙅🏻♀️", "🙅🏼♀️", "🙅🏽♀️", "🙅🏾♀️", "🙅🏿♀️", "🙅♀️", "🙅♀", "🙆🏻", "🙆🏼", "🙆🏽", "🙆🏾", "🙆🏿", "🙆", "🙆🏻♂️", "🙆🏼♂️", "🙆🏽♂️", "🙆🏾♂️", "🙆🏿♂️", "🙆♂️", "🙆♂", "🙆🏻♀️", "🙆🏼♀️", "🙆🏽♀️", "🙆🏾♀️", "🙆🏿♀️", "🙆♀️", "🙆♀", "💁🏻", "💁🏼", "💁🏽", "💁🏾", "💁🏿", "💁", "💁🏻♂️", "💁🏼♂️", "💁🏽♂️", "💁🏾♂️", "💁🏿♂️", "💁♂️", "💁♂", "💁🏻♀️", "💁🏼♀️", "💁🏽♀️", "💁🏾♀️", "💁🏿♀️", "💁♀️", "💁♀", "🙋🏻", "🙋🏼", "🙋🏽", "🙋🏾", "🙋🏿", "🙋", "🙋🏻♂️", "🙋🏼♂️", "🙋🏽♂️", "🙋🏾♂️", "🙋🏿♂️", "🙋♂️", "🙋♂", "🙋🏻♀️", "🙋🏼♀️", "🙋🏽♀️", "🙋🏾♀️", "🙋🏿♀️", "🙋♀️", "🙋♀", "🧏🏻", "🧏🏼", "🧏🏽", "🧏🏾", "🧏🏿", "🧏", "🧏🏻♂️", "🧏🏼♂️", "🧏🏽♂️", "🧏🏾♂️", "🧏🏿��️", "🧏♂️", "🧏♂", "🧏🏻♀️", "🧏🏼♀️", "🧏🏽♀️", "🧏🏾♀️", "🧏🏿♀️", "🧏♀️", "🧏♀", "🙇🏻", "🙇🏼", "🙇🏽", "🙇🏾", "🙇🏿", "🙇", "🙇🏻♂️", "🙇🏼♂️", "🙇🏽♂️", "🙇🏾♂️", "🙇🏿♂️", "🙇♂️", "🙇♂", "🙇🏻♀️", "🙇🏼♀️", "🙇🏽♀️", "🙇🏾♀️", "🙇🏿♀️", "🙇♀️", "🙇♀", "🤦🏻", "🤦🏼", "🤦🏽", "🤦🏾", "🤦🏿", "🤦", "🤦🏻♂️", "🤦🏼♂️", "🤦🏽♂️", "🤦🏾♂️", "🤦🏿♂️", "🤦♂️", "🤦♂", "🤦🏻♀️", "🤦🏼♀️", "🤦🏽♀️", "🤦🏾♀️", "🤦🏿♀️", "🤦♀️", "🤦♀", "🤷🏻", "🤷🏼", "🤷🏽", "🤷🏾", "🤷🏿", "🤷", "🤷🏻♂️", "🤷🏼♂️", "🤷🏽♂️", "🤷🏾♂️", "🤷🏿♂️", "🤷♂️", "🤷♂", "🤷🏻♀️", "🤷🏼♀️", "🤷🏽♀️", "🤷🏾♀️", "🤷🏿♀️", "🤷♀️", "🤷♀", "🧑🏻⚕️", "🧑🏼⚕️", "🧑🏽⚕️", "🧑🏾⚕️", "🧑🏿⚕️", "🧑⚕️", "🧑⚕", "👨🏻⚕️", "👨🏼⚕️", "👨🏽⚕️", "👨🏾⚕️", "👨🏿⚕️", "👨⚕️", "👨⚕", "👩🏻⚕️", "👩🏼⚕️", "👩🏽⚕️", "👩🏾⚕️", "👩🏿⚕️", "👩⚕️", "👩⚕", "🧑🏻🎓", "🧑🏼🎓", "🧑🏽🎓", "🧑🏾🎓", "🧑🏿🎓", "🧑🎓", "👨🏻🎓", "👨🏼🎓", "👨🏽🎓", "👨🏾🎓", "👨🏿🎓", "👨🎓", "👩🏻🎓", "👩🏼🎓", "👩🏽🎓", "👩🏾🎓", "👩🏿🎓", "👩🎓", "🧑🏻🏫", "🧑🏼🏫", "🧑🏽🏫", "🧑🏾🏫", "🧑🏿🏫", "🧑🏫", "👨🏻🏫", "👨🏼🏫", "👨🏽🏫", "👨🏾🏫", "👨🏿🏫", "👨🏫", "👩🏻🏫", "👩🏼🏫", "👩🏽🏫", "👩🏾🏫", "👩🏿🏫", "👩🏫", "🧑🏻⚖️", "🧑🏼⚖️", "🧑🏽⚖️", "🧑🏾⚖️", "🧑🏿⚖️", "🧑⚖️", "🧑⚖", "👨🏻⚖️", "👨🏼⚖️", "👨🏽⚖️", "👨🏾⚖️", "👨🏿⚖️", "👨⚖️", "👨⚖", "👩🏻⚖️", "👩🏼⚖️", "👩🏽⚖️", "👩🏾⚖️", "👩🏿⚖️", "👩⚖️", "👩⚖", "🧑🏻🌾", "🧑🏼🌾", "🧑🏽🌾", "🧑🏾🌾", "🧑🏿🌾", "🧑🌾", "👨🏻🌾", "👨🏼🌾", "👨🏽🌾", "👨🏾🌾", "👨🏿🌾", "👨🌾", "👩🏻🌾", "👩🏼🌾", "👩🏽🌾", "👩🏾🌾", "👩🏿🌾", "👩🌾", "🧑🏻🍳", "🧑🏼🍳", "🧑🏽🍳", "🧑🏾🍳", "🧑🏿🍳", "🧑🍳", "👨🏻🍳", "👨🏼🍳", "👨🏽🍳", "👨🏾🍳", "👨🏿🍳", "👨🍳", "👩🏻🍳", "👩🏼🍳", "👩🏽🍳", "👩🏾🍳", "👩🏿🍳", "👩🍳", "🧑🏻🔧", "🧑🏼🔧", "🧑🏽🔧", "🧑🏾🔧", "🧑🏿🔧", "🧑🔧", "👨🏻🔧", "👨🏼🔧", "👨🏽🔧", "👨🏾🔧", "👨🏿🔧", "👨🔧", "👩🏻🔧", "👩🏼🔧", "👩🏽🔧", "👩🏾🔧", "👩🏿🔧", "👩🔧", "🧑🏻🏭", "🧑🏼🏭", "🧑🏽🏭", "🧑🏾🏭", "🧑🏿🏭", "🧑🏭", "👨🏻🏭", "👨🏼🏭", "👨🏽🏭", "👨🏾🏭", "👨🏿🏭", "👨🏭", "👩🏻🏭", "👩🏼🏭", "👩🏽🏭", "👩🏾🏭", "👩🏿🏭", "👩🏭", "🧑🏻💼", "🧑🏼💼", "🧑🏽💼", "🧑🏾💼", "🧑🏿💼", "🧑💼", "👨🏻💼", "👨🏼💼", "👨🏽💼", "👨🏾💼", "👨🏿💼", "👨💼", "👩🏻💼", "👩🏼💼", "👩🏽💼", "👩🏾💼", "👩🏿💼", "👩💼", "🧑🏻🔬", "🧑🏼🔬", "🧑🏽🔬", "🧑🏾🔬", "🧑🏿🔬", "🧑🔬", "👨🏻🔬", "👨🏼🔬", "👨🏽🔬", "👨🏾🔬", "👨🏿🔬", "👨🔬", "👩🏻🔬", "👩🏼🔬", "👩🏽🔬", "👩🏾🔬", "👩🏿🔬", "👩🔬", "🧑🏻💻", "🧑🏼💻", "🧑🏽💻", "🧑🏾💻", "🧑🏿💻", "🧑💻", "👨🏻💻", "👨🏼💻", "👨🏽💻", "👨🏾💻", "👨🏿💻", "👨💻", "👩🏻💻", "👩🏼💻", "👩🏽💻", "👩🏾💻", "👩🏿💻", "👩💻", "🧑🏻🎤", "🧑🏼🎤", "🧑🏽🎤", "🧑🏾🎤", "🧑🏿🎤", "🧑🎤", "👨🏻🎤", "👨🏼��🎤", "👨🏽🎤", "👨🏾🎤", "👨🏿🎤", "👨🎤", "👩🏻🎤", "👩🏼🎤", "👩🏽🎤", "👩🏾🎤", "👩🏿🎤", "👩🎤", "🧑🏻🎨", "🧑🏼🎨", "🧑🏽🎨", "🧑🏾🎨", "🧑🏿🎨", "🧑🎨", "👨🏻🎨", "👨🏼🎨", "👨🏽🎨", "👨🏾🎨", "👨🏿🎨", "👨🎨", "👩🏻🎨", "👩🏼🎨", "👩🏽🎨", "👩🏾🎨", "👩🏿🎨", "👩🎨", "🧑🏻✈️", "🧑🏼✈️", "🧑🏽✈️", "🧑🏾✈️", "🧑🏿✈️", "🧑✈️", "🧑✈", "👨🏻✈️", "👨🏼✈️", "👨🏽✈️", "👨🏾✈️", "👨🏿✈️", "👨✈️", "👨✈", "👩🏻✈️", "👩🏼✈️", "👩🏽✈️", "👩🏾✈️", "👩🏿✈️", "👩✈️", "👩✈", "🧑🏻🚀", "🧑🏼🚀", "🧑🏽🚀", "🧑🏾🚀", "🧑🏿🚀", "🧑🚀", "👨🏻🚀", "👨🏼🚀", "👨🏽🚀", "👨🏾🚀", "👨🏿🚀", "👨🚀", "👩🏻🚀", "👩🏼🚀", "👩🏽🚀", "👩🏾🚀", "👩🏿🚀", "👩🚀", "🧑🏻🚒", "🧑🏼🚒", "🧑🏽🚒", "🧑🏾🚒", "🧑🏿🚒", "🧑🚒", "👨🏻🚒", "👨🏼🚒", "👨🏽🚒", "👨🏾🚒", "👨🏿🚒", "👨🚒", "👩🏻🚒", "👩🏼🚒", "👩🏽🚒", "👩🏾🚒", "👩🏿🚒", "👩🚒", "👮🏻", "👮🏼", "👮🏽", "👮🏾", "👮🏿", "👮", "👮🏻♂️", "👮🏼♂️", "👮🏽♂️", "👮🏾♂️", "👮🏿♂️", "👮♂️", "👮♂", "👮🏻♀️", "👮🏼♀️", "👮🏽♀️", "👮🏾♀️", "👮🏿♀️", "👮♀️", "👮♀", "🕵🏻", "🕵🏼", "🕵🏽", "🕵🏾", "🕵🏿", "🕵️", "🕵", "🕵🏻♂️", "🕵🏼♂️", "🕵🏽♂️", "🕵🏾♂️", "🕵🏿♂️", "🕵️♂️", "🕵🏻♀️", "🕵🏼♀️", "🕵🏽♀️", "🕵🏾♀️", "🕵🏿♀️", "🕵️♀️", "💂🏻", "💂🏼", "💂🏽", "💂🏾", "💂🏿", "💂", "💂🏻♂️", "💂🏼♂️", "💂🏽♂️", "💂🏾♂️", "💂🏿♂️", "💂♂️", "💂♂", "💂🏻♀️", "💂🏼♀️", "💂🏽♀️", "💂🏾♀️", "💂🏿♀️", "💂♀️", "💂♀", "🥷🏻", "🥷🏼", "🥷🏽", "🥷🏾", "🥷🏿", "🥷", "👷🏻", "👷🏼", "👷🏽", "👷🏾", "👷🏿", "👷", "👷🏻♂️", "👷🏼♂️", "👷🏽♂️", "👷🏾♂️", "👷🏿♂️", "👷♂️", "👷♂", "👷🏻♀️", "👷🏼♀️", "👷🏽♀️", "👷🏾♀️", "👷🏿♀️", "👷♀️", "👷♀", "🫅🏻", "🫅🏼", "🫅🏽", "🫅🏾", "🫅🏿", "🫅", "🤴🏻", "🤴🏼", "🤴🏽", "🤴🏾", "🤴🏿", "🤴", "👸🏻", "👸🏼", "👸🏽", "👸🏾", "👸🏿", "👸", "👳🏻", "👳🏼", "👳🏽", "👳🏾", "👳🏿", "👳", "👳🏻♂️", "👳🏼♂️", "👳🏽♂️", "👳🏾♂️", "👳🏿♂️", "👳♂️", "👳♂", "👳🏻♀️", "👳🏼♀️", "👳🏽♀️", "👳🏾♀️", "👳🏿♀️", "👳♀️", "👳♀", "👲🏻", "👲🏼", "👲🏽", "👲🏾", "👲🏿", "👲", "🧕🏻", "🧕🏼", "🧕🏽", "🧕🏾", "🧕🏿", "🧕", "🤵🏻", "🤵🏼", "🤵🏽", "🤵🏾", "🤵🏿", "🤵", "🤵🏻♂️", "🤵🏼♂️", "🤵🏽♂️", "🤵🏾♂️", "🤵🏿♂️", "🤵♂️", "🤵♂", "🤵🏻♀️", "🤵🏼♀️", "🤵🏽♀️", "🤵🏾♀️", "🤵🏿♀️", "🤵♀️", "🤵♀", "👰🏻", "👰🏼", "👰🏽", "👰🏾", "👰🏿", "👰", "👰🏻♂️", "👰🏼♂️", "👰🏽♂️", "👰🏾♂️", "👰🏿♂️", "👰♂️", "👰♂", "👰🏻♀️", "👰🏼♀️", "👰🏽♀️", "👰🏾♀️", "👰🏿♀️", "👰♀️", "👰♀", "🤰🏻", "🤰🏼", "🤰🏽", "🤰🏾", "🤰🏿", "🤰", "🫃🏻", "🫃🏼", "🫃🏽", "🫃🏾", "🫃🏿", "🫃", "🫄🏻", "🫄🏼", "🫄🏽", "🫄🏾", "🫄🏿", "🫄", "🤱🏻", "🤱🏼", "🤱🏽", "🤱🏾", "🤱🏿", "🤱", "👩🏻🍼", "👩🏼🍼", "👩🏽🍼", "👩🏾🍼", "👩🏿🍼", "👩🍼", "👨🏻🍼", "👨🏼🍼", "👨🏽🍼", "👨🏾🍼", "👨🏿🍼", "👨🍼", "🧑🏻🍼", "🧑🏼🍼", "🧑🏽🍼", "🧑🏾🍼", "🧑🏿🍼", "🧑🍼", "👼🏻", "👼🏼", "👼🏽", "👼🏾", "👼🏿", "👼", "🎅🏻", "🎅🏼", "🎅🏽", "🎅🏾", "🎅🏿", "🎅", "🤶🏻", "🤶🏼", "🤶🏽", "🤶🏾", "🤶🏿", "🤶", "🧑🏻🎄", "🧑🏼🎄", "🧑🏽🎄", "🧑🏾🎄", "🧑🏿🎄", "🧑🎄", "🦸🏻", "🦸🏼", "🦸🏽", "🦸🏾", "🦸🏿", "🦸", "🦸🏻♂️", "🦸🏼♂️", "🦸🏽♂️", "🦸🏾♂️", "🦸🏿♂️", "🦸♂️", "🦸♂", "🦸🏻♀️", "🦸🏼♀️", "🦸🏽♀️", "🦸🏾♀️", "🦸🏿♀️", "🦸♀️", "🦸♀", "🦹🏻", "🦹🏼", "🦹🏽", "🦹🏾", "🦹🏿", "🦹", "🦹🏻♂️", "🦹🏼♂️", "🦹🏽♂️", "🦹🏾♂️", "🦹🏿♂️", "🦹♂️", "🦹♂", "🦹🏻♀️", "🦹🏼♀️", "🦹🏽♀️", "🦹🏾♀️", "🦹🏿♀️", "🦹♀️", "🦹♀", "🧙🏻", "🧙🏼", "🧙🏽", "🧙🏾", "🧙🏿", "🧙", "🧙🏻♂️", "🧙🏼♂️", "🧙🏽♂️", "🧙🏾♂️", "🧙🏿♂️", "🧙♂️", "🧙♂", "🧙🏻♀️", "🧙🏼♀️", "🧙🏽♀️", "🧙🏾♀️", "🧙🏿♀️", "🧙♀️", "🧙♀", "🧚🏻", "🧚🏼", "🧚🏽", "🧚🏾", "🧚🏿", "🧚", "🧚🏻♂️", "🧚🏼♂️", "🧚🏽♂️", "🧚🏾♂️", "🧚🏿♂️", "🧚♂️", "🧚♂", "🧚🏻♀️", "🧚🏼♀️", "🧚🏽♀️", "🧚🏾♀️", "🧚🏿♀️", "🧚♀️", "🧚♀", "🧛🏻", "🧛🏼", "🧛🏽", "🧛🏾", "🧛🏿", "🧛", "🧛🏻♂️", "🧛🏼♂️", "🧛🏽♂️", "🧛🏾♂️", "🧛🏿♂️", "🧛♂️", "🧛♂", "🧛🏻♀️", "🧛🏼♀️", "🧛🏽♀️", "🧛🏾♀️", "🧛🏿♀️", "🧛♀️", "🧛♀", "🧜🏻", "🧜🏼", "🧜🏽", "🧜🏾", "🧜🏿", "🧜", "🧜🏻♂️", "🧜🏼♂️", "🧜🏽♂️", "🧜🏾♂️", "🧜🏿♂️", "🧜♂️", "🧜♂", "🧜🏻♀️", "🧜🏼♀️", "🧜🏽♀️", "🧜🏾♀️", "🧜🏿♀️", "🧜♀️", "🧜♀", "🧝🏻", "🧝🏼", "🧝🏽", "🧝🏾", "🧝🏿", "🧝", "🧝🏻♂️", "🧝🏼♂️", "🧝🏽♂️", "🧝🏾♂️", "🧝🏿♂️", "🧝♂️", "🧝♂", "🧝🏻♀️", "🧝🏼♀️", "🧝🏽♀️", "🧝🏾♀️", "🧝🏿♀️", "🧝♀️", "🧝♀", "🧞", "🧞♂️", "🧞♂", "🧞♀️", "🧞♀", "🧟", "🧟♂️", "🧟♂", "🧟♀️", "🧟♀", "🧌", "💆🏻", "💆🏼", "💆🏽", "💆🏾", "💆🏿", "💆", "💆🏻♂️", "💆🏼♂️", "💆🏽♂️", "💆🏾♂️", "💆🏿♂️", "💆♂️", "💆♂", "💆🏻♀️", "💆🏼♀️", "💆🏽♀️", "💆🏾♀️", "💆🏿♀️", "💆♀️", "💆♀", "💇🏻", "💇🏼", "💇🏽", "💇🏾", "💇🏿", "💇", "💇🏻♂️", "💇🏼♂️", "💇🏽♂️", "💇🏾♂️", "💇🏿♂️", "💇♂️", "💇♂", "💇🏻♀️", "💇🏼♀️", "💇🏽♀️", "💇🏾♀️", "💇🏿♀️", "💇♀️", "💇♀", "🚶🏻", "🚶🏼", "🚶🏽", "🚶🏾", "🚶🏿", "🚶", "🚶🏻♂️", "🚶🏼♂️", "🚶🏽♂️", "🚶🏾♂️", "🚶🏿♂️", "🚶♂️", "🚶♂", "🚶🏻♀️", "🚶🏼♀️", "🚶🏽♀️", "🚶🏾♀️", "🚶🏿♀️", "🚶♀️", "🚶♀", "🧍🏻", "🧍🏼", "🧍🏽", "🧍🏾", "🧍🏿", "🧍", "🧍🏻♂️", "🧍🏼♂️", "🧍🏽♂️", "🧍🏾♂️", "🧍🏿♂️", "🧍♂️", "🧍♂", "🧍🏻♀️", "🧍🏼♀️", "🧍🏽♀️", "🧍🏾♀️", "🧍🏿♀️", "🧍♀️", "🧍♀", "🧎🏻", "🧎🏼", "🧎🏽", "🧎🏾", "🧎🏿", "🧎", "🧎🏻♂️", "🧎🏼♂️", "🧎🏽♂️", "🧎🏾♂️", "🧎🏿♂️", "🧎♂️", "🧎♂", "🧎🏻♀️", "🧎🏼♀️", "🧎🏽♀️", "🧎🏾♀️", "🧎🏿♀️", "🧎♀️", "🧎♀", "🧑🏻🦯", "🧑🏼🦯", "🧑🏽🦯", "🧑🏾🦯", "🧑🏿🦯", "🧑🦯", "👨🏻🦯", "👨🏼🦯", "👨🏽🦯", "👨🏾🦯", "👨🏿🦯", "👨🦯", "👩🏻🦯", "👩🏼🦯", "👩🏽🦯", "👩🏾🦯", "👩🏿🦯", "👩🦯", "🧑🏻🦼", "🧑🏼🦼", "🧑🏽🦼", "🧑🏾🦼", "🧑🏿🦼", "🧑🦼", "👨🏻🦼", "👨🏼🦼", "👨🏽🦼", "👨🏾🦼", "👨🏿🦼", "👨🦼", "👩🏻🦼", "👩🏼🦼", "👩🏽🦼", "👩🏾🦼", "👩🏿🦼", "👩🦼", "🧑🏻🦽", "🧑🏼🦽", "🧑🏽🦽", "🧑🏾���", "🧑🏿🦽", "🧑🦽", "👨🏻🦽", "👨🏼🦽", "👨🏽🦽", "👨🏾🦽", "👨🏿🦽", "👨🦽", "👩🏻🦽", "👩🏼🦽", "👩🏽🦽", "👩🏾🦽", "👩🏿🦽", "👩🦽", "🏃🏻", "🏃🏼", "🏃🏽", "🏃🏾", "🏃🏿", "🏃", "🏃🏻♂️", "🏃🏼♂️", "🏃🏽♂️", "🏃🏾♂️", "🏃🏿♂️", "🏃♂️", "🏃♂", "🏃🏻♀️", "🏃🏼♀️", "🏃🏽♀️", "🏃🏾♀️", "🏃🏿♀️", "🏃♀️", "🏃♀", "💃🏻", "💃🏼", "💃🏽", "💃🏾", "💃🏿", "💃", "🕺🏻", "🕺🏼", "🕺🏽", "🕺🏾", "🕺🏿", "🕺", "🕴🏻", "🕴🏼", "🕴🏽", "🕴🏾", "🕴🏿", "🕴️", "🕴", "👯", "👯♂️", "👯♂", "👯♀️", "👯♀", "🧖🏻", "🧖🏼", "🧖🏽", "🧖🏾", "🧖🏿", "🧖", "🧖🏻♂️", "🧖🏼♂️", "🧖🏽♂️", "🧖🏾♂️", "🧖🏿♂️", "🧖♂️", "🧖♂", "🧖🏻♀️", "🧖🏼♀️", "🧖🏽♀️", "🧖🏾♀️", "🧖🏿♀️", "🧖♀️", "🧖♀", "🧗🏻", "🧗🏼", "🧗🏽", "🧗🏾", "🧗🏿", "🧗", "🧗🏻♂️", "🧗🏼♂️", "🧗🏽♂️", "🧗🏾♂️", "🧗🏿♂️", "🧗♂️", "🧗♂", "🧗🏻♀️", "🧗🏼♀️", "🧗🏽♀️", "🧗🏾♀️", "🧗🏿♀️", "🧗♀️", "🧗♀", "🤺", "🏇🏻", "🏇🏼", "🏇🏽", "🏇🏾", "🏇🏿", "🏇", "⛷️", "⛷", "🏂🏻", "🏂🏼", "🏂🏽", "🏂🏾", "🏂🏿", "🏂", "🏌🏻", "🏌🏼", "🏌🏽", "🏌🏾", "🏌🏿", "🏌️", "🏌", "🏌🏻♂️", "🏌🏼♂️", "🏌🏽♂️", "🏌🏾♂️", "🏌🏿♂️", "🏌️♂️", "🏌🏻♀️", "🏌🏼♀️", "🏌🏽♀️", "🏌🏾♀️", "🏌🏿♀️", "🏌️♀️", "🏄🏻", "🏄🏼", "🏄🏽", "🏄🏾", "🏄🏿", "🏄", "🏄🏻♂️", "🏄🏼♂️", "🏄🏽♂️", "🏄🏾♂️", "🏄🏿♂️", "🏄♂️", "🏄♂", "🏄🏻♀️", "🏄🏼♀️", "🏄🏽♀️", "🏄🏾♀️", "🏄🏿♀️", "🏄♀️", "🏄♀", "🚣🏻", "🚣🏼", "🚣🏽", "🚣🏾", "🚣🏿", "🚣", "🚣🏻♂️", "🚣🏼♂️", "🚣🏽♂️", "🚣🏾♂️", "🚣🏿♂️", "🚣♂️", "🚣♂", "🚣🏻♀️", "🚣🏼♀️", "🚣🏽♀️", "🚣🏾♀️", "🚣🏿♀️", "🚣♀️", "🚣♀", "🏊🏻", "🏊🏼", "🏊🏽", "🏊🏾", "🏊🏿", "🏊", "🏊🏻♂️", "🏊🏼♂️", "🏊🏽♂️", "🏊🏾♂️", "🏊🏿♂️", "🏊♂️", "🏊♂", "🏊🏻♀️", "🏊🏼♀️", "🏊🏽♀️", "🏊🏾♀️", "🏊🏿♀️", "🏊♀️", "🏊♀", "⛹🏻", "⛹🏼", "⛹🏽", "⛹🏾", "⛹🏿", "⛹️", "⛹", "⛹🏻♂️", "⛹🏼♂️", "⛹🏽♂️", "⛹🏾♂️", "⛹🏿♂️", "⛹️♂️", "⛹🏻♀️", "⛹🏼♀️", "⛹🏽♀️", "⛹🏾♀️", "⛹🏿♀️", "⛹️♀️", "🏋🏻", "🏋🏼", "🏋🏽", "🏋🏾", "🏋🏿", "🏋️", "🏋", "🏋🏻♂️", "🏋🏼♂️", "🏋🏽♂️", "🏋🏾♂️", "🏋🏿♂️", "🏋️♂️", "🏋🏻♀️", "🏋🏼♀️", "🏋🏽♀️", "🏋🏾♀️", "🏋🏿♀️", "🏋️♀️", "🚴🏻", "🚴🏼", "🚴🏽", "🚴🏾", "🚴🏿", "🚴", "🚴🏻♂️", "🚴🏼♂️", "🚴🏽♂️", "🚴🏾♂️", "🚴🏿♂️", "🚴♂️", "🚴♂", "🚴🏻♀️", "🚴🏼♀️", "🚴🏽♀️", "🚴🏾♀️", "🚴🏿♀️", "🚴♀️", "🚴♀", "🚵🏻", "🚵🏼", "🚵🏽", "🚵🏾", "🚵🏿", "🚵", "🚵🏻♂️", "🚵🏼♂️", "🚵🏽♂️", "🚵🏾♂️", "🚵🏿♂️", "🚵♂️", "🚵♂", "🚵🏻♀️", "🚵🏼♀️", "🚵🏽♀️", "🚵🏾♀️", "🚵🏿♀️", "🚵♀️", "🚵♀", "🤸🏻", "🤸🏼", "🤸🏽", "🤸🏾", "🤸🏿", "🤸", "🤸🏻♂️", "🤸🏼♂️", "🤸🏽♂️", "🤸🏾♂️", "🤸🏿♂️", "🤸♂️", "🤸♂", "🤸🏻♀️", "🤸🏼♀️", "🤸🏽♀️", "🤸🏾♀️", "🤸🏿♀️", "🤸♀️", "🤸♀", "🤼", "🤼♂️", "🤼♂", "🤼♀️", "🤼♀", "🤽🏻", "🤽🏼", "🤽🏽", "🤽🏾", "🤽🏿", "🤽", "🤽🏻♂️", "🤽🏼♂️", "🤽🏽♂️", "🤽🏾♂️", "🤽🏿♂️", "🤽♂️", "🤽♂", "🤽🏻♀️", "🤽🏼♀️", "🤽🏽♀️", "🤽🏾♀️", "🤽🏿♀️", "🤽♀️", "🤽♀", "🤾🏻", "🤾🏼", "🤾🏽", "🤾🏾", "🤾🏿", "🤾", "🤾🏻♂️", "🤾🏼♂️", "🤾🏽♂️", "🤾🏾♂️", "🤾🏿♂️", "🤾♂️", "🤾♂", "🤾🏻♀️", "🤾🏼♀️", "🤾🏽♀️", "🤾🏾♀️", "🤾🏿♀️", "🤾♀️", "🤾♀", "🤹🏻", "🤹🏼", "🤹🏽", "🤹🏾", "🤹🏿", "🤹", "🤹🏻♂️", "🤹🏼♂️", "🤹🏽♂️", "🤹🏾♂️", "🤹🏿♂️", "🤹♂️", "🤹♂", "🤹🏻♀️", "🤹🏼♀️", "🤹🏽♀️", "🤹🏾♀️", "🤹🏿♀️", "🤹♀️", "🤹♀", "🧘🏻", "🧘🏼", "🧘🏽", "🧘🏾", "🧘🏿", "🧘", "🧘🏻♂️", "🧘🏼♂️", "🧘🏽♂️", "🧘🏾♂️", "🧘🏿♂️", "🧘♂️", "🧘♂", "🧘🏻♀️", "🧘🏼♀️", "🧘🏽♀️", "🧘🏾♀️", "🧘🏿♀️", "🧘♀️", "🧘♀", "🛀🏻", "🛀🏼", "🛀🏽", "🛀🏾", "🛀🏿", "🛀", "🛌🏻", "🛌🏼", "🛌🏽", "🛌🏾", "🛌🏿", "🛌", "🧑🏻🤝🧑🏻", "🧑🏻🤝🧑🏼", "🧑🏻🤝🧑🏽", "🧑🏻🤝🧑🏾", "🧑🏻🤝🧑🏿", "🧑🏼🤝🧑🏻", "🧑🏼🤝🧑🏼", "🧑🏼🤝🧑🏽", "🧑🏼🤝🧑🏾", "🧑🏼🤝🧑🏿", "🧑🏽🤝🧑🏻", "🧑🏽🤝🧑🏼", "🧑🏽🤝🧑🏽", "🧑🏽🤝🧑🏾", "🧑🏽🤝🧑🏿", "🧑🏾🤝🧑🏻", "🧑🏾🤝🧑🏼", "🧑🏾🤝🧑🏽", "🧑🏾🤝🧑🏾", "🧑🏾🤝🧑🏿", "🧑🏿🤝🧑🏻", "🧑🏿🤝🧑🏼", "🧑🏿🤝🧑🏽", "🧑🏿🤝🧑🏾", "🧑🏿🤝🧑🏿", "🧑🤝🧑", "👭", "👫", "👬", "💏", "💑", "👪", "👨👩👦", "👨👩👧", "👨👩👧👦", "👨👩👦👦", "👨👩👧👧", "👨👨👦", "👨👨👧", "👨👨👧👦", "👨👨👦👦", "👨👨👧👧", "👩👩👦", "👩👩👧", "👩👩👧👦", "👩👩👦👦", "👩👩👧👧", "👨👦", "👨👦👦", "👨👧", "👨👧👦", "👨👧👧", "👩👦", "👩👦👦", "👩👧", "👩👧👦", "👩👧👧", "🗣️", "🗣", "👤", "👥", "🫂", "👣", "🐵", "🐒", "🦍", "🦧", "🐶", "🐕", "🦮", "🐕🦺", "🐩", "🐺", "🦊", "🦝", "🐱", "🐈", "🐈⬛", "🦁", "🐯", "🐅", "🐆", "🐴", "🐎", "🦄", "🦓", "🦌", "🦬", "🐮", "🐂", "🐃", "🐄", "🐷", "🐖", "🐗", "🐽", "🐏", "🐑", "🐐", "🐪", "🐫", "🦙", "🦒", "🐘", "🦣", "🦏", "🦛", "🐭", "🐁", "🐀", "🐹", "🐰", "🐇", "🐿️", "🐿", "🦫", "🦔", "🦇", "🐻", "🐻❄️", "🐻❄", "🐨", "🐼", "🦥", "🦦", "🦨", "🦘", "🦡", "🐾", "🦃", "🐔", "🐓", "🐣", "🐤", "🐥", "🐦", "🐧", "🕊️", "🕊", "🦅", "🦆", "🦢", "🦉", "🦤", "🪶", "🦩", "🦚", "🦜", "🐸", "🐊", "🐢", "🦎", "🐍", "🐲", "🐉", "🦕", "🦖", "🐳", "🐋", "🐬", "🦭", "🐟", "🐠", "🐡", "🦈", "🐙", "🐚", "🪸", "🐌", "🦋", "🐛", "🐜", "🐝", "🪲", "🐞", "🦗", "🪳", "🕷️", "🕷", "🕸️", "🕸", "🦂", "🦟", "🪰", "🪱", "🦠", "💐", "🌸", "💮", "🪷", "🏵️", "🏵", "🌹", "🥀", "🌺", "🌻", "🌼", "🌷", "🌱", "🪴", "🌲", "🌳", "🌴", "🌵", "🌾", "🌿", "☘️", "☘", "🍀", "🍁", "🍂", "🍃", "🪹", "🪺", "🍇", "🍈", "🍉", "🍊", "🍋", "🍌", "🍍", "🥭", "🍎", "🍏", "🍐", "🍑", "🍒", "🍓", "🫐", "🥝", "🍅", "🫒", "🥥", "🥑", "🍆", "🥔", "🥕", "🌽", "🌶️", "🌶", "🫑", "🥒", "🥬", "🥦", "🧄", "🧅", "🍄", "🥜", "🫘", "🌰", "🍞", "🥐", "🥖", "🫓", "🥨", "🥯", "🥞", "🧇", "🧀", "🍖", "🍗", "🥩", "🥓", "🍔", "🍟", "🍕", "🌭", "🥪", "🌮", "🌯", "🫔", "🥙", "🧆", "🥚", "🍳", "🥘", "🍲", "🫕", "🥣", "🥗", "🍿", "🧈", "🧂", "🥫", "🍱", "🍘", "🍙", "🍚", "🍛", "🍜", "🍝", "🍠", "🍢", "🍣", "🍤", "🍥", "🥮", "🍡", "🥟", "🥠", "🥡", "🦀", "🦞", "🦐", "🦑", "🦪", "🍦", "🍧", "🍨", "🍩", "🍪", "🎂", "🍰", "🧁", "🥧", "🍫", "🍬", "🍭", "🍮", "🍯", "🍼", "🥛", "☕", "🫖", "🍵", "🍶", "🍾", "🍷", "🍸", "🍹", "🍺", "🍻", "🥂", "🥃", "🫗", "🥤", "🧋", "🧃", "🧉", "🧊", "🥢", "🍽️", "🍽", "🍴", "🥄", "🔪", "🫙", "🏺", "🌍", "🌎", "🌏", "🌐", "🗺️", "🗺", "🗾", "🧭", "🏔️", "🏔", "⛰️", "⛰", "🌋", "🗻", "🏕️", "🏕", "🏖️", "🏖", "🏜️", "🏜", "🏝️", "🏝", "🏞️", "🏞", "🏟️", "🏟", "🏛️", "🏛", "🏗️", "🏗", "🧱", "🪨", "🪵", "🛖", "🏘️", "🏘", "🏚️", "🏚", "🏠", "🏡", "🏢", "🏣", "🏤", "🏥", "🏦", "🏨", "🏩", "🏪", "🏫", "🏬", "🏭", "🏯", "🏰", "💒", "🗼", "🗽", "⛪", "🕌", "🛕", "🕍", "⛩️", "⛩", "🕋", "⛲", "⛺", "🌁", "🌃", "🏙️", "🏙", "🌄", "🌅", "🌆", "🌇", "🌉", "♨️", "♨", "🎠", "🛝", "🎡", "🎢", "💈", "🎪", "🚂", "🚃", "🚄", "🚅", "🚆", "🚇", "🚈", "🚉", "🚊", "🚝", "🚞", "🚋", "🚌", "🚍", "🚎", "🚐", "🚑", "🚒", "🚓", "🚔", "🚕", "🚖", "🚗", "🚘", "🚙", "🛻", "🚚", "🚛", "🚜", "🏎️", "🏎", "🏍️", "🏍", "🛵", "🦽", "🦼", "🛺", "🚲", "🛴", "🛹", "🛼", "🚏", "🛣️", "🛣", "🛤️", "🛤", "🛢️", "🛢", "⛽", "🛞", "🚨", "🚥", "🚦", "🛑", "🚧", "⚓", "🛟", "⛵", "🛶", "🚤", "🛳️", "🛳", "⛴️", "⛴", "🛥️", "🛥", "🚢", "✈️", "✈", "🛩️", "🛩", "🛫", "🛬", "🪂", "💺", "🚁", "🚟", "🚠", "🚡", "🛰️", "🛰", "🚀", "🛸", "🛎️", "🛎", "🧳", "⌛", "⏳", "⌚", "⏰", "⏱️", "⏱", "⏲️", "⏲", "🕰️", "🕰", "🕛", "🕧", "🕐", "🕜", "🕑", "🕝", "🕒", "🕞", "🕓", "🕟", "🕔", "🕠", "🕕", "🕡", "🕖", "🕢", "🕗", "🕣", "🕘", "🕤", "🕙", "🕥", "🕚", "🕦", "🌑", "🌒", "🌓", "🌔", "🌕", "🌖", "🌗", "🌘", "🌙", "🌚", "🌛", "🌜", "🌡️", "🌡", "☀️", "☀", "🌝", "🌞", "🪐", "⭐", "🌟", "🌠", "🌌", "☁️", "☁", "⛅", "⛈️", "⛈", "🌤️", "🌤", "🌥️", "🌥", "🌦️", "🌦", "🌧️", "🌧", "🌨️", "🌨", "🌩️", "🌩", "🌪️", "🌪", "🌫️", "🌫", "🌬️", "🌬", "🌀", "🌈", "🌂", "☂️", "☂", "☔", "⛱️", "⛱", "⚡", "❄️", "❄", "☃️", "☃", "⛄", "☄️", "☄", "🔥", "💧", "🌊", "🎃", "🎄", "🎆", "🎇", "🧨", "✨", "🎈", "🎉", "🎊", "🎋", "🎍", "🎎", "🎏", "🎐", "🎑", "🧧", "🎀", "🎁", "🎗️", "🎗", "🎟️", "🎟", "🎫", "🎖️", "🎖", "🏆", "🏅", "🥇", "🥈", "🥉", "⚽", "⚾", "🥎", "🏀", "🏐", "🏈", "🏉", "🎾", "🥏", "🎳", "🏏", "🏑", "🏒", "🥍", "🏓", "🏸", "🥊", "🥋", "🥅", "⛳", "⛸️", "⛸", "🎣", "🤿", "🎽", "🎿", "🛷", "🥌", "🎯", "🪀", "🪁", "🎱", "🔮", "🪄", "🧿", "🪬", "🎮", "🕹️", "🕹", "🎰", "🎲", "🧩", "🧸", "🪅", "🪩", "🪆", "♠️", "♠", "♥️", "♥", "♦️", "♦", "♣️", "♣", "♟️", "♟", "🃏", "🀄", "🎴", "🎭", "🖼️", "🖼", "🎨", "🧵", "🪡", "🧶", "🪢", "👓", "🕶️", "🕶", "🥽", "🥼", "🦺", "👔", "👕", "👖", "🧣", "🧤", "🧥", "🧦", "👗", "👘", "🥻", "🩱", "🩲", "🩳", "👙", "👚", "👛", "👜", "👝", "🛍️", "🛍", "🎒", "🩴", "👞", "👟", "🥾", "🥿", "👠", "👡", "🩰", "👢", "👑", "👒", "🎩", "🎓", "🧢", "🪖", "⛑️", "⛑", "📿", "💄", "💍", "💎", "🔇", "🔈", "🔉", "🔊", "📢", "📣", "📯", "🔔", "🔕", "🎼", "🎵", "🎶", "🎙️", "🎙", "🎚️", "🎚", "🎛️", "🎛", "🎤", "🎧", "📻", "🎷", "🪗", "🎸", "🎹", "🎺", "🎻", "🪕", "🥁", "🪘", "📱", "📲", "☎️", "☎", "📞", "📟", "📠", "🔋", "🪫", "🔌", "💻", "🖥️", "🖥", "🖨️", "🖨", "⌨️", "⌨", "🖱️", "🖱", "🖲️", "🖲", "💽", "💾", "💿", "📀", "🧮", "🎥", "🎞️", "🎞", "📽️", "📽", "🎬", "📺", "📷", "📸", "📹", "📼", "🔍", "🔎", "🕯️", "🕯", "💡", "🔦", "🏮", "🪔", "📔", "📕", "📖", "📗", "📘", "📙", "📚", "📓", "📒", "📃", "📜", "📄", "📰", "🗞️", "🗞", "📑", "🔖", "🏷️", "🏷", "💰", "🪙", "💴", "💵", "💶", "💷", "💸", "💳", "🧾", "💹", "✉️", "✉", "📧", "📨", "📩", "📤", "📥", "📦", "📫", "📪", "📬", "📭", "📮", "🗳️", "🗳", "✏️", "✏", "✒️", "✒", "🖋️", "🖋", "🖊️", "🖊", "🖌️", "🖌", "🖍️", "🖍", "📝", "💼", "📁", "📂", "🗂️", "🗂", "📅", "📆", "🗒️", "🗒", "🗓️", "🗓", "📇", "📈", "📉", "📊", "📋", "📌", "📍", "📎", "🖇️", "🖇", "📏", "📐", "✂️", "✂", "🗃️", "🗃", "🗄️", "🗄", "🗑️", "🗑", "🔒", "🔓", "🔏", "🔐", "🔑", "🗝️", "🗝", "🔨", "🪓", "⛏️", "⛏", "⚒️", "⚒", "🛠️", "🛠", "🗡️", "🗡", "⚔️", "⚔", "🔫", "🪃", "🏹", "🛡️", "🛡", "🪚", "🔧", "🪛", "🔩", "⚙️", "⚙", "🗜️", "🗜", "⚖️", "⚖", "🦯", "🔗", "⛓️", "⛓", "🪝", "🧰", "🧲", "🪜", "⚗️", "⚗", "🧪", "🧫", "🧬", "🔬", "🔭", "📡", "💉", "🩸", "💊", "🩹", "🩼", "🩺", "����", "🚪", "🛗", "🪞", "🪟", "🛏️", "🛏", "🛋️", "🛋", "🪑", "🚽", "🪠", "🚿", "🛁", "🪤", "🪒", "🧴", "🧷", "🧹", "🧺", "🧻", "🪣", "🧼", "🫧", "🪥", "🧽", "🧯", "🛒", "🚬", "⚰️", "⚰", "🪦", "⚱️", "⚱", "🗿", "🪧", "🪪", "🏧", "🚮", "🚰", "♿", "🚹", "🚺", "🚻", "🚼", "🚾", "🛂", "🛃", "🛄", "🛅", "⚠️", "⚠", "🚸", "⛔", "🚫", "🚳", "🚭", "🚯", "🚱", "🚷", "📵", "🔞", "☢️", "☢", "☣️", "☣", "⬆️", "⬆", "↗️", "↗", "➡️", "➡", "↘️", "↘", "⬇️", "⬇", "↙️", "↙", "⬅️", "⬅", "↖️", "↖", "↕️", "↕", "↔️", "↩️", "↩", "↪️", "↪", "⤴️", "⤴", "⤵️", "⤵", "🔃", "🔄", "🔙", "🔚", "🔛", "🔜", "🔝", "🛐", "⚛️", "⚛", "🕉️", "🕉", "✡️", "✡", "☸️", "☸", "☯️", "☯", "✝️", "✝", "☦️", "☦", "☪️", "☪", "☮️", "☮", "🕎", "🔯", "♈", "♉", "♊", "♋", "♌", "♍", "♎", "♏", "♐", "♑", "♒", "♓", "⛎", "🔀", "🔁", "🔂", "▶️", "⏩", "⏭️", "⏭", "⏯️", "⏯", "◀️", "⏪", "⏮️", "⏮", "🔼", "⏫", "🔽", "⏬", "⏸️", "⏸", "⏹️", "⏹", "⏺️", "⏺", "⏏️", "⏏", "🎦", "🔅", "🔆", "📶", "📳", "📴", "♀️", "♀", "♂️", "♂", "⚧️", "⚧", "✖️", "✖", "➕", "➖", "➗", "🟰", "♾️", "♾", "‼️", "‼", "⁉️", "⁉", "❓", "❔", "❕", "❗", "〰️", "〰", "💱", "💲", "⚕️", "⚕", "♻️", "♻", "⚜️", "⚜", "🔱", "📛", "🔰", "⭕", "✅", "☑️", "☑", "✔️", "✔", "❌", "❎", "➰", "➿", "〽️", "〽", "✳️", "✳", "✴️", "✴", "❇️", "❇", "©️", "©", "®️", "®", "™️", "#️⃣", "#⃣", "*️⃣", "*⃣", "0️⃣", "0⃣", "1️⃣", "1⃣", "2️⃣", "2⃣", "3️⃣", "3⃣", "4️⃣", "4⃣", "5️⃣", "5⃣", "6️⃣", "6⃣", "7️⃣", "7⃣", "8️⃣", "8⃣", "9️⃣", "9⃣", "🔟", "🔠", "🔡", "🔢", "🔣", "🔤", "🅰️", "🅰", "🆎", "🅱️", "🅱", "🆑", "🆒", "🆓", "ℹ️", "ℹ", "🆔", "Ⓜ️", "Ⓜ", "🆕", "🆖", "🅾️", "🅾", "🆗", "🅿️", "🅿", "🆘", "🆙", "🆚", "🈁", "🈂️", "🈂", "🈷️", "🈷", "🈶", "🈯", "🉐", "🈹", "🈚", "🈲", "🉑", "🈸", "🈴", "🈳", "㊗️", "㊗", "㊙️", "㊙", "🈺", "🈵", "🔴", "🟠", "🟡", "🟢", "🔵", "🟣", "🟤", "⚫", "⚪", "🟥", "🟧", "🟨", "🟩", "🟦", "🟪", "🟫", "⬛", "⬜", "◼️", "◼", "◻️", "◻", "◾", "◽", "▪️", "▪", "▫️", "▫", "🔶", "🔷", "🔸", "🔹", "🔺", "🔻", "💠", "🔘", "🔳", "🔲", "🏁", "🚩", "🎌", "🏴", "🏳️", "🏳", "🏳️🌈", "🏳🌈", "🏳️⚧️", "🏴☠️", "🏴☠", "🇦🇨", "🇦🇩", "🇦🇪", "🇦🇫", "🇦🇬", "🇦🇮", "🇦🇱", "🇦🇲", "🇦🇴", "🇦🇶", "🇦🇷", "🇦🇸", "🇦🇹", "🇦🇺", "🇦🇼", "🇦🇽", "🇦🇿", "🇧🇦", "🇧🇧", "🇧🇩", "🇧🇪", "🇧🇫", "🇧🇬", "🇧🇭", "🇧🇮", "🇧🇯", "🇧🇱", "🇧🇲", "🇧🇳", "🇧🇴", "🇧🇶", "🇧🇷", "🇧🇸", "🇧🇹", "🇧🇻", "🇧🇼", "🇧🇾", "🇧🇿", "🇨🇦", "🇨🇨", "🇨🇩", "🇨🇫", "🇨🇬", "🇨🇭", "🇨🇮", "🇨🇰", "🇨🇱", "🇨🇲", "🇨🇳", "🇨🇴", "🇨🇵", "🇨🇷", "🇨🇺", "🇨🇻", "🇨🇼", "🇨🇽", "🇨🇾", "🇨🇿", "🇩🇪", "🇩🇬", "🇩🇯", "🇩🇰", "🇩🇲", "🇩🇴", "🇩🇿", "🇪🇦", "🇪🇨", "🇪🇪", "🇪🇬", "🇪🇭", "🇪🇷", "🇪🇸", "🇪🇹", "🇪🇺", "🇫🇮", "🇫🇯", "🇫🇰", "🇫🇲", "🇫🇴", "🇫🇷", "🇬🇦", "🇬🇧", "🇬🇩", "🇬🇪", "🇬🇫", "🇬🇬", "🇬🇭", "🇬🇮", "🇬🇱", "🇬🇲", "🇬🇳", "🇬🇵", "🇬🇶", "🇬🇷", "🇬🇸", "🇬🇹", "🇬🇺", "🇬🇼", "🇬🇾", "🇭🇰", "🇭🇲", "🇭🇳", "🇭🇷", "🇭🇹", "🇭🇺", "🇮🇨", "🇮🇩", "🇮🇪", "🇮🇱", "🇮🇲", "🇮🇳", "🇮🇴", "🇮🇶", "🇮🇷", "🇮🇸", "🇮🇹", "🇯🇪", "🇯🇲", "🇯🇴", "🇯🇵", "🇰🇪", "🇰🇬", "🇰🇭", "🇰🇮", "🇰🇲", "🇰🇳", "🇰🇵", "🇰🇷", "🇰🇼", "🇰🇾", "🇰🇿", "🇱🇦", "🇱🇧", "🇱🇨", "🇱🇮", "🇱🇰", "🇱🇷", "🇱🇸", "🇱🇹", "🇱🇺", "🇱🇻", "🇱🇾", "🇲🇦", "🇲🇨", "🇲🇩", "🇲🇪", "🇲🇫", "🇲🇬", "🇲🇭", "🇲🇰", "🇲🇱", "🇲🇲", "🇲🇳", "🇲🇴", "🇲🇵", "🇲🇶", "🇲🇷", "🇲🇸", "🇲🇹", "🇲🇺", "🇲🇻", "🇲🇼", "🇲🇽", "🇲🇾", "🇲🇿", "🇳🇦", "🇳🇨", "🇳🇪", "🇳🇫", "🇳🇬", "🇳🇮", "🇳🇱", "🇳🇴", "🇳🇵", "🇳🇷", "🇳🇺", "🇳🇿", "🇴🇲", "🇵🇦", "🇵🇪", "🇵🇫", "🇵🇬", "🇵🇭", "🇵🇰", "🇵🇱", "🇵🇲", "🇵🇳", "🇵🇷", "🇵🇸", "🇵🇹", "🇵🇼", "🇵🇾", "🇶🇦", "🇷🇪", "🇷🇴", "🇷🇸", "🇷🇺", "🇷🇼", "🇸🇦", "🇸🇧", "🇸🇨", "🇸🇩", "🇸🇪", "🇸🇬", "🇸🇭", "🇸🇮", "🇸🇯", "🇸🇰", "🇸🇱", "🇸🇲", "🇸🇳", "🇸🇴", "🇸🇷", "🇸🇸", "🇸🇹", "🇸🇻", "🇸🇽", "🇸🇾", "🇸🇿", "🇹🇦", "🇹🇨", "🇹🇩", "🇹🇫", "🇹🇬", "🇹🇭", "🇹🇯", "🇹🇰", "🇹🇱", "🇹🇲", "🇹🇳", "🇹🇴", "🇹🇷", "🇹🇹", "🇹🇻", "🇹🇼", "🇹🇿", "🇺🇦", "🇺🇬", "🇺🇲", "🇺🇳", "🇺🇸", "🇺🇾", "🇺🇿", "🇻🇦", "🇻🇨", "🇻🇪", "🇻🇬", "🇻🇮", "🇻🇳", "🇻🇺", "🇼🇫", "🇼🇸", "🇽🇰", "🇾🇪", "🇾🇹", "🇿🇦", "🇿🇲", "🇿🇼", "🏴", "🏴", "🏴"]def preprocess_llm_response(response:list):in_response = Falseaccumulated_json = ""response_buffer = ""partial_newline = Falsefor _idx, text in enumerate(response):if text is None:text = ""accumulated_json += textif partial_newline:if text.startswith("n"):response_buffer += "\n"text = text[1:]partial_newline = Falseif text.endswith("\\"):partial_newline = Truetext = text[:-1]text = text.replace("\\n", "\n")if in_response:start_index = 0if text and '\"' in text:_text = codecs.decode(text, 'unicode_escape')# print(f"{text} -> {_text}")response_buffer += _text[start_index:]else:response_buffer += text[start_index:]end_index = response_buffer.find('",')if end_index != -1:yield response_buffer[:end_index]in_response = Falseresponse_buffer = ""else:yield response_buffer[start_index:]response_buffer = ""else:response_start_index = accumulated_json[-20 - len(text):].find('"response":"')if response_start_index != -1:in_response = Truestart_index = len(accumulated_json) - (20 + len(text)) + response_start_index + len('"response":"')else:start_index = 0content = json.loads(accumulated_json)yield content
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190import syssys.path.append('/Users/work/Documents/LocalDev/productivity/gmail0')
import osimport reimport jsonimport requestsfrom notion_client import Clientfrom components.supabase.db import check_data, update_datafrom components.notion.blocks import pretty_print_blueprint
'''LOAD ENVIRONMENT VARIABLES'''from dotenv import load_dotenvload_dotenv()
'''CODE'''def get_access_token(access_code): pass def fetch_user_pages(access_token): """Fetch a list of pages accessible by the user.""" url = 'https://api.notion.com/v1/search' headers = { 'Authorization': f'Bearer {access_token}', 'Notion-Version': '2022-06-28' } response = requests.post(url, headers=headers) response = response.json() page_structure = {'active':[],'access_pages':[]} for i, page in enumerate(response['results']): active_page = {} if not page['in_trash'] and not page['archived']: # print(i) # print(page.keys()) # if i < 5: # print(page) active_page['page_type'] = page['object'] active_page['page_id'] = page['id'] active_page['page_title'] = '' if page['icon'] and page['icon'].get('emoji',None): active_page['page_title'] = (page['icon'].get('emoji','') if page['icon'] else '') + ' ' if active_page['page_type'] == 'page': title_key = next((key for key, value in page['properties'].items() if value.get('id') == 'title'), None) page_title = page['properties'][title_key]['title'] if page_title: active_page['page_title'] += page_title[0]['plain_text'] else: active_page['page_title'] += "Untitled" elif active_page['page_type'] == 'database': db_title = page['title'] if db_title: active_page['page_title'] += db_title[0]['plain_text'] else: active_page['page_title'] += "Untitled" else: pass if page['parent'].get('type') == 'workspace': active_page['parent_id'] = 'workspace' elif page['parent'].get('type') == 'page_id': active_page['parent_id'] = page['parent'].get('page_id','') elif page['parent'].get('type') == 'database_id': active_page['parent_id'] = page['parent'].get('database_id','') elif page['parent'].get('type') == 'block_id': active_page['parent_id'] = fetch_parent_page_id(page['parent'].get('block_id',None),access_token) else: active_page['parent_id'] = page['parent'] page_structure['active'].append(active_page) # print(page_structure['active'][-1]) page_structure['access_pages'] = None # page_structure['access_pages'] = response return page_structure
def fetch_parent_page_id(block_id, access_token): """Fetch the parent page ID for a given block ID using the Notion API.""" url = f"https://api.notion.com/v1/blocks/{block_id}" headers = { "Authorization": f"Bearer {access_token}", "Notion-Version": "2022-06-28", # Use the latest supported version "Content-Type": "application/json", } response = requests.get(url, headers=headers) if response.status_code == 200: block_data = response.json() parent_type = block_data.get('parent', {}).get('type') if parent_type == 'page_id': return block_data['parent']['page_id'] else: return f"Block is not directly parented by a page, but by a {parent_type}" else: return f"Failed to fetch block details: {response.text}"
def parse_user_pages(curr_user_email, user_type ="email", refresh=False, max_depth=2): token = None page_id = None page_types = None data, count = check_data(curr_user_email, column="notion_access_token", table="users", row_id_type=user_type) if data: token = data.get('access_token', None) workspace_id = data.get('workspace_id','') workspace_name = data.get('workspace_name','') workspace_icon = data.get('workspace_icon','') last_duplicated_page_id = data.get('duplicated_template_id', None) access_pages_data = None if not refresh: data, count = check_data(curr_user_email, column="notion_access_pages", table="users", row_id_type=user_type) if data: access_pages_data = data['active'] else: pages_data = fetch_user_pages(token) data, count = update_data(curr_user_email, pages_data, table="users", row_id_type=user_type, column="notion_access_pages") access_pages_data = data[0].get('notion_access_pages', None) if access_pages_data: access_pages_data = json.loads(access_pages_data)['active'] if access_pages_data: tree = {} for item in access_pages_data: tree[item['page_id']] = {**item, 'children': []}
roots = [] for item in access_pages_data: parent_id = item['parent_id'] if parent_id in tree: tree[parent_id]['children'].append(tree[item['page_id']]) else: tree[parent_id] = {'children': [tree[item['page_id']]]} roots.append(parent_id) if parent_id == "workspace": if workspace_icon: tree[parent_id]['page_title'] = workspace_icon + ' ' tree[parent_id]['page_title'] = workspace_name tree[parent_id]['page_type'] = 'root' tree[parent_id]['page_id'] = workspace_id else: tree[parent_id]['page_title'] = 'unknown' tree[parent_id]['page_type'] = 'unknown' tree[parent_id]['page_id'] = parent_id # Limit tree depth def limit_tree_depth(node, current_depth=0): if current_depth >= max_depth: node['children'] = [] # Remove children beyond max depth else: for child in node['children']: limit_tree_depth(child, current_depth + 1)
for root in roots: limit_tree_depth(tree[root]) # pretty_print_blueprint(tree) # print(roots) dropdown_options = [] page_types = [] for root in roots: formatted_options, formatted_types, _ = format_for_dropdown(tree[root]) dropdown_options.extend(formatted_options) page_types.extend(formatted_types) # print(dropdown_options) page_id = dropdown_options token = [('My Notion Access Token',token)] else: if last_duplicated_page_id: page_id = [('My Notion PageID', last_duplicated_page_id)] page_types = [('My Notion PageID', 'page')] token = [('My Notion Access Token',token)] return token, page_id, page_types
def format_for_dropdown(node, prefix='', index=0): formatted = [] page_types = [] title = f"{prefix}{node['page_title']} ({node.get('page_type', '')})" formatted.append((title, node['page_id'])) page_types.append((node['page_id'], node.get('page_type', ''))) child_index = index for child in node.get('children', []): child_formatted, child_types, child_index = format_for_dropdown(child, prefix + '•• ', child_index+1) formatted.extend(child_formatted) page_types.extend(child_types) return formatted, page_types, child_index
if __name__ == "__main__": email = 'test@test.com' # data, count = check_data(email, column="notion_access_pages", table="users", row_id_type="email") # print(data) data, count = check_data(email, column="notion_access_token", table="users", row_id_type="email") access_token = data.get('access_token', None) pages_data = fetch_user_pages(access_token) # pretty_print_blueprint(pages_data['active']) # data, count = update_data(email, pages_data, table="users", row_id_type="email", column="notion_access_pages") # print(type(data[0].get('notion_access_pages',None))) # print(data[0].get('notion_access_pages',None))123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654import osimport reimport jsonimport requestsfrom notion_client import Client
'''LOAD ENVIRONMENT VARIABLES'''from dotenv import load_dotenvload_dotenv()NOTION_KEY = os.getenv('PUBLIC_DIR_NOTION_KEY')UNSPLASH_ACCESS_KEY = os.getenv('UNSPLASH_ACCESS_KEY')
'''LOAD API CLIENTS'''notion = Client(auth=NOTION_KEY)
def pretty_print_blueprint(blueprint_json): print(json.dumps(blueprint_json, indent=4))
def get_unsplash_image_url(query, def_env_var=True): params = { "query": query, "client_id": UNSPLASH_ACCESS_KEY, "orientation": "landscape" } if not def_env_var: params["client_id"] = os.getenv('UNSPLASH_ACCESS_KEY') response = requests.get("https://api.unsplash.com/search/photos", params=params)
if response.status_code == 200: results = response.json()["results"] if results: return results[0]["urls"]["regular"] return None
def process_rich_text_content(text_blocks): rich_text_content = [] for block in text_blocks: text_content = { "type": "text", "text": { "content": block["text"], "link": None }, "annotations": { "bold": "bold" in block.get("style", []), "italic": "italic" in block.get("style", []), "strikethrough": "strikethrough" in block.get("style", []), "underline": "underline" in block.get("style", []), "code": "code" in block.get("style", []), "color": "default" } } rich_text_content.append(text_content) return rich_text_content
def is_number(s): try: float(s) return True except ValueError: return False
# FULL_TEXT_IS_URL_PATTERN = r'(?i)^(?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’])$'# FULL_TEXT_IS_URL_PATTERN = re.compile(# r'(?i)^(?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’])$')# FULL_TEXT_IS_URL_PATTERN = re.compile(# r'(?i)^'# r'(?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)' # Scheme and domain# r'(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+?' # Path# # r'(?:\?[\w%&=\.-]*)?' # r'(?:\?[\w%&=\[\]\.\-]*)?' # Optional query string# r'$')FULL_TEXT_IS_URL_PATTERN = re.compile( r'(?i)^(https?://|www\d{0,3}\.|[a-z0-9.\-]+\.[a-z]{2,4}/)([^\s()<>{}\[\]]+)(\?[\w%&=\[\]\.\-]*)?$')FULL_TEXT_IS_URL_PATTERN = re.compile( r'(?i)^(https?://|www\d{0,3}\.|[a-z0-9.\-]+\.[a-z]{2,4}/)' # Scheme and domain r'([^\s()<>{}]+)' # Path, avoiding overly complex patterns r'(\?[\w%&=\[\]\.\-]*)?$' # Query string, correctly handling square brackets and other characters)def process_table_content(rows): table_content = [] char_limit = 1000 for _idx, cell in enumerate(rows): content = str(cell) link = None content_length = len(content) if content_length > char_limit: content = f'Content is above character limit of 1000: {content_length}' if (not (' ' in content) and content.strip() != "" and not is_number(content) and content.startswith(("http:", "https:")) and content_length <= char_limit ): # print(len(rows), _idx, content_length, content) is_cell_url = None try: # is_cell_url = re.match(FULL_TEXT_IS_URL_PATTERN, content) is not None is_cell_url = FULL_TEXT_IS_URL_PATTERN.match(content) is not None except Exception as error: content = f"Regex match error: {error}" # print(content) if is_cell_url: link = {"url": content} content = 'Link' # print("URL? - ", is_cell_url) row_content = [{ "type": "text", "text": { "content": content, "link": link }, # "annotations": { # "bold": "bold" in row.get("style", []), # "italic": "italic" in row.get("style", []), # "strikethrough": "strikethrough" in row.get("style", []), # "underline": "underline" in row.get("style", []), # "code": "code" in row.get("style", []), # "color": "default" # } }] table_content.append(row_content) return table_content
def fetch_page_properties(page_id, page_type, def_env_var=True, notion_key=None): """ Fetches properties of a Notion database given its ID """ try: _notion = notion if not def_env_var: _notion = Client(auth=os.getenv('PUBLIC_DIR_NOTION_KEY')) if notion_key: _notion = Client(auth=notion_key) if page_type == 'database': page_details = _notion.databases.retrieve(database_id=page_id) if page_type == 'page': page_details = _notion.pages.retrieve(page_id=page_id) return page_details except Exception as e: print(f"Failed to fetch page properties: {e}") return None
def create_page(parent_id, title, icon, properties, cover_image=True, def_env_var=True, notion_key=None, parent_type=None): image_url = get_unsplash_image_url(title, def_env_var=def_env_var) if cover_image else None _page_properties = properties # print(_page_properties) parent_key = 'page_id' child_title_key = 'title' if parent_type == "database": parent_key = "database_id" _allowed_page_properties = {} print(f"Fetching parent '{parent_type}' details...") _parent_info = fetch_page_properties(parent_id, parent_type, def_env_var=def_env_var, notion_key=notion_key) _parent_title = None if _parent_info: print(f"Fetched parent '{parent_type}' details...") _common_keys = set() _parent_properties = _parent_info.get('properties', {}) if parent_type == "database": _parent_title = _parent_info.get('title', []) child_title_key = next((key for key, value in _parent_properties.items() if value.get('id') == 'title'), None) if parent_type == 'page': _parent_title_key = next((key for key, value in _parent_properties.items() if value.get('id') == 'title'), None) _parent_title = _parent_info["properties"].get(_parent_title_key, {}).get("title", []) _parent_properties = set(_parent_properties.keys()) _child_properties = set(_page_properties.keys()) _common_keys = _parent_properties & _child_properties _unique_to_child_properties = _child_properties - _parent_properties _unique_to_parent_properties = _parent_properties - _child_properties _filtered_child_properties = {key: _page_properties[key] for key in _common_keys} _allowed_page_properties = _filtered_child_properties print(f"""Properties status of '{parent_type}' parent: Found keys - {_common_keys}; Not Found keys - {_unique_to_child_properties}; Other present keys - {_unique_to_parent_properties}""")
if _parent_title: _parent_title = _parent_title[0].get("plain_text", "Untitled") else: _parent_title = "Untitled" else: print(f"Failed to fetch parent '{parent_type}' details...") if not child_title_key: raise ValueError(f"No title property in '{parent_type}' parent with title '{_parent_title}'.") page_properties = { child_title_key: { "title": [ {"type": "text", "text": { "content": title, }}] }} # print(_allowed_page_properties) page_properties.update(_allowed_page_properties) # print(page_properties) page_payload = { "parent": {parent_key: parent_id}, "icon": {"emoji": icon}, "properties": page_properties } if image_url: page_payload["cover"] = { "type": "external", "external": {"url": image_url}}
_notion = notion if not def_env_var: _notion = Client(auth=os.getenv('PUBLIC_DIR_NOTION_KEY')) if notion_key: _notion = Client(auth=notion_key) new_page = _notion.pages.create(**page_payload) return new_page
def create_database(parent_id, title, icon, schema, is_inline=False, cover_image=True, def_env_var=True, notion_key=None, parent_type=None): image_url = get_unsplash_image_url(title, def_env_var=def_env_var) if cover_image else None approved_types = ("checkbox", "created_by", "created_time", "date", "email", "files", "last_edited_by", "last_edited_time", "multi_select", "number", "people", "phone_number", "rich_text", "select", "title", "url")
properties = {} for name, info in schema.items(): prop_type = info["type"] if prop_type not in approved_types: raise ValueError(f"Property type '{prop_type}' is currently unsupported.")
if prop_type in ["select", "multi_select"]: properties[name] = {prop_type: {"options": info["options"]}} elif prop_type == "number": properties[name] = {prop_type: {"format": info.get("format", "number")}} else: properties[name] = {prop_type: {}}
database_payload = { "parent": { "page_id": parent_id }, "icon": { "emoji": icon }, "title": [ { "type": "text", "text": { "content": title } } ], "properties": properties, "is_inline": is_inline }
if image_url: database_payload["cover"] = { "type": "external", "external": { "url": image_url } }
_notion = notion if not def_env_var: _notion = Client(auth=os.getenv('PUBLIC_DIR_NOTION_KEY')) if notion_key: _notion = Client(auth=notion_key) new_database = _notion.databases.create(**database_payload) return new_database
def create_divider(parent_id, notion_key=None, parent_type=None): _notion = notion if notion_key: _notion = Client(auth=notion_key) divider_block = _notion.blocks.children.append(**{ "block_id": parent_id, "children": [ { "object": "block", "type": "divider", "divider": {}, } ] }) return divider_block
def create_table_of_contents(parent_id, notion_key=None, parent_type=None): _notion = notion if notion_key: _notion = Client(auth=notion_key) toc_block = _notion.blocks.children.append(**{ "block_id": parent_id, "children": [ { "object": "block", "type": "table_of_contents", "table_of_contents": {} } ] }) return toc_block
def create_heading(parent_id, text, level, notion_key=None, parent_type=None): _notion = notion if notion_key: _notion = Client(auth=notion_key) heading_block = _notion.blocks.children.append(**{ "block_id": parent_id, "children": [ { "object": "block", "type": f"heading_{level}", f"heading_{level}": { "rich_text": [ { "type": "text", "text": { "content": text } } ], }, } ] }) return heading_block
def create_paragraph(parent_id, text_blocks, notion_key=None, parent_type=None): _notion = notion if notion_key: _notion = Client(auth=notion_key) paragraph_block = _notion.blocks.children.append(**{ "block_id": parent_id, "children": [ { "object": "block", "type": "paragraph", "paragraph": { "rich_text": process_rich_text_content(text_blocks) } } ] }) return paragraph_block
def create_list(parent_id, items, bulleted=True, notion_key=None, parent_type=None): _notion = notion if notion_key: _notion = Client(auth=notion_key) list_type = "bulleted_list_item" if bulleted else "numbered_list_item" children = [{ "object": "block", "type": list_type, list_type: { "rich_text": [ { "type": "text", "text": { "content": item } } ] } } for item in items]
list_block = _notion.blocks.children.append(**{ "block_id": parent_id, "children": children }) return list_block
def create_todo_list(parent_id, items, notion_key=None, parent_type=None): _notion = notion if notion_key: _notion = Client(auth=notion_key) children = [{ "object": "block", "type": "to_do", "to_do": { "rich_text": [ { "type": "text", "text": { "content": item["text"] } } ], "checked": item.get("checked", False), }, } for item in items]
todo_block = _notion.blocks.children.append(**{ "block_id": parent_id, "children": children }) return todo_block
def create_toggle(parent_id, title, notion_key=None, parent_type=None): _notion = notion if notion_key: _notion = Client(auth=notion_key) toggle_block = _notion.blocks.children.append(**{ "block_id": parent_id, "children": [ { "object": "block", "type": "toggle", "toggle": { "rich_text": [ { "type": "text", "text": { "content": title } } ], } } ] }) return toggle_block
def create_column_list(parent_id, num_columns=2, notion_key=None, parent_type=None): _notion = notion if notion_key: _notion = Client(auth=notion_key) column_list_block = _notion.blocks.children.append(**{ "block_id": parent_id, "children": [ { "object": "block", "type": "column_list", "column_list": { "children": [ { "object": "block", "type": "column", "column": { "children": [ { "object": "block", "type": "paragraph", "paragraph": { "rich_text": [ { "type": "text", "text": { "content": "placeholder", } } ] } } ] } } for _ in range(num_columns) ] } } ] })
column_details = _notion.blocks.children.list(block_id=column_list_block["results"][0]["id"]) column_ids = []
for column in column_details["results"]: column_ids.append(column["id"]) children_details = _notion.blocks.children.list(block_id=column["id"]) for child in children_details["results"]: if "paragraph" in child and child["paragraph"]["rich_text"][0]["text"]["content"] == "placeholder": _notion.blocks.delete(child["id"])
return column_ids
def create_callout(parent_id, text_blocks, icon, color="default", notion_key=None, parent_type=None): _notion = notion if notion_key: _notion = Client(auth=notion_key) callout_block = _notion.blocks.children.append(**{ "block_id": parent_id, "children": [ { "object": "block", "type": "callout", "callout": { "rich_text": process_rich_text_content(text_blocks), "icon": { "type": "emoji", "emoji": icon }, "color": color } } ] }) return callout_block
def create_quote(parent_id, text_blocks, notion_key=None, parent_type=None): _notion = notion if notion_key: _notion = Client(auth=notion_key) quote_block = _notion.blocks.children.append(**{ "block_id": parent_id, "children": [ { "object": "block", "type": "quote", "quote": { "rich_text": process_rich_text_content(text_blocks) } } ] }) return quote_block
def create_table(parent_id, rows, notion_key=None, parent_type=None): ''' { "type": "table", "table": { "table_width": 2, "has_column_header": false, "has_row_header": false, "children": [ { "type": "table_row", "table_row": { "cells": [ [ { "type": "text", "text": { "content": "from (sender)", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, } ], [ { "type": "text", "text": { "content": "emailCount", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, } ] ] } }, ] }, "children": [ { "type": "table_row", "table_row": { "cells": [ [ { "type": "text", "text": { "content": "The Ken <info@the-ken.com>", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, } ], [ { "type": "text", "text": { "content": "22", "link": null }, "annotations": { "bold": false, "italic": false, "strikethrough": false, "underline": false, "code": false, "color": "default" }, } ] ] } }, ] } ''' _notion = notion if notion_key: _notion = Client(auth=notion_key)# table_rows_characters = [[len(cell) for cell in row] for row in rows] print(f"Total table rows: {len(rows)}") table_rows = [process_table_content(row) for row in rows] table_rows_cols = [len(row) for row in table_rows] table_blocks = sum(table_rows_cols) print(f"Total table blocks: {table_blocks}") rows_lim = 20 table_json = { "table_width": len(rows[0]), "has_column_header": False, "has_row_header": False, "children": [ {"type": "table_row", "table_row": { "cells": row }} for row in table_rows[:rows_lim]] } # pretty_print_blueprint(table_json) table_block = _notion.blocks.children.append(**{ "block_id": parent_id, "children": [ { "type": "table", "table": table_json } ] }) return table_block123456# TODO - Create a notion json from any content like:# 1. Website (HTML) (Public)# 2. Audio or Video Links (Public)# 3. LinkedIn Post (Public)# 4. Gmail or any email content (after redacting personal info - refer to emails.pi_redactor.py)# 5. Online PDF (Public)123456789101112131415161718192021222324252627import argparseimport os
from architect import process_blueprint, generate_blueprint
def main(): parser = argparse.ArgumentParser(description="Generates Notion content given a brief description") parser.add_argument("description", help="Text description of the desired content in Notion.") args = parser.parse_args()
notion_page_id = os.environ["NOTION_PAGE_ID"]
content = None for update in generate_blueprint(args.description): if isinstance(update, dict): content = update else: print(update, end="", flush=True)
blueprint = content["blueprint"] # print(blueprint) process_blueprint(notion_page_id, blueprint)
if __name__ == "__main__": main()12345678910111213141516171819202122import argparseimport json
from utils import process_page
def pretty_print_blueprint(blueprint_json): print(json.dumps(blueprint_json, indent=4))
def main(): parser = argparse.ArgumentParser(description="Process and print a Notion page as a JSON blueprint.") parser.add_argument("page_id", help="The Notion page ID to process") args = parser.parse_args()
blueprint_json = process_page(args.page_id)
pretty_print_blueprint(blueprint_json)
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164import osimport json
from notion_client import Client
'''LOAD ENVIRONMENT VARIABLES'''from dotenv import load_dotenvload_dotenv()NOTION_KEY = os.getenv('ADMIN_NOTION_KEY')notion = Client(auth=NOTION_KEY)
def pretty_print_blueprint(blueprint_json): print(json.dumps(blueprint_json, indent=4))
def process_page(page_id): page = notion.pages.retrieve(page_id) page_blueprint = { "type": "page", "title": page["properties"]["title"]["title"][0]["text"]["content"] } if page["icon"] is not None: page_blueprint["icon"] = page["icon"]["emoji"] page_blueprint["children"] = fetch_and_process_children(page_id) return page_blueprint
def process_rich_text(rich_text): content = [] for text in rich_text: style = [] if text["annotations"]["bold"]: style.append("bold") if text["annotations"]["italic"]: style.append("italic") if text["annotations"]["strikethrough"]: style.append("strikethrough") if text["annotations"]["underline"]: style.append("underline") if text["annotations"]["code"]: style.append("code") content.append({ "text": text["plain_text"], "style": style }) return content
def fetch_and_process_children(parent_id): children = [] block_children = notion.blocks.children.list(block_id=parent_id)["results"]
list_buffer = None
for child in block_children: # pretty_print_blueprint(child["type"]) if child["type"] in ["bulleted_list_item", "numbered_list_item", "to_do"]: list_type = "to_do_list" if child["type"] == "to_do" else "bulleted_list" if child["type"] == "bulleted_list_item" else "numbered_list"
if list_buffer is None or list_buffer["type"] != list_type: if list_buffer: children.append(list_buffer) list_buffer = {"type": list_type, "items": []}
if list_type == "to_do_list": todo_item_text = child["to_do"]["rich_text"][0]["text"]["content"] todo_item_checked = child["to_do"]["checked"] list_buffer["items"].append({"text": todo_item_text, "checked": todo_item_checked}) else: list_item_text = child[child["type"]]["rich_text"][0]["text"]["content"] list_buffer["items"].append(list_item_text)
else: if list_buffer: children.append(list_buffer) list_buffer = None
formatted_block = format_block(child)
if child.get("has_children", False): formatted_block[ "columns" if child["type"] == "column_list" else "children"] = fetch_and_process_children( child["id"])
children.append(formatted_block)
if list_buffer: children.append(list_buffer)
return children
def format_block(block): block_type = block["type"] block_json = {"type": block_type}
if block_type == "child_page": block_json["type"] = "page" page_details = notion.pages.retrieve(block["id"]) block_json["title"] = page_details["properties"]["title"]["title"][0]["text"]["content"] if page_details["icon"] is not None: block_json["icon"] = page_details["icon"]["emoji"]
elif block_type == "child_database": block_json["type"] = "database" database_details = notion.databases.retrieve(database_id=block["id"]) block_json["title"] = database_details["title"][0]["plain_text"] if database_details["icon"] is not None: block_json["icon"] = database_details["icon"]["emoji"] if database_details["is_inline"]: block_json["is_inline"] = database_details["is_inline"] properties = {} for prop_name, prop_details in database_details["properties"].items(): prop_type = prop_details["type"] if prop_type in ["select", "multi_select"]: options = [{"name": option["name"], "color": option.get("color", "default")} for option in prop_details[prop_type]["options"]] properties[prop_name] = {"type": prop_type, "options": options} elif prop_type == "number": properties[prop_name] = {"type": prop_type, "format": prop_details["number"].get("format", "none")} else: properties[prop_name] = {"type": prop_type} block_json["schema"] = properties
if block_type == "paragraph": block_json["content"] = process_rich_text(block["paragraph"]["rich_text"])
elif block_type.startswith("heading_"): block_json["text"] = block[block_type]["rich_text"][0]["text"]["content"]
elif block_type == "bulleted_list_item": block_json["items"] = [text["plain_text"] for text in block["bulleted_list_item"]["rich_text"]]
elif block_type == "numbered_list_item": block_json["items"] = [text["plain_text"] for text in block["numbered_list_item"]["rich_text"]]
elif block_type == "to_do": block_json["text"] = block["to_do"]["rich_text"][0]["text"]["content"] block_json["checked"] = block["to_do"]["checked"]
elif block_type == "toggle": block_json["title"] = block["toggle"]["rich_text"][0]["text"]["content"]
elif block_type == "callout": block_json["icon"] = block["callout"]["icon"]["emoji"] block_json["color"] = block["callout"]["color"] block_json["content"] = process_rich_text(block["callout"]["rich_text"])
elif block_type == "quote": block_json["content"] = process_rich_text(block["quote"]["rich_text"])
elif block_type == "table": # pretty_print_blueprint(block) # pretty_print_blueprint(block[block_type]) block_json["table"] = block[block_type]
elif block_type == "table_row": # pretty_print_blueprint(block[block_type]["cells"]) block_json["table_row"] = { "cells": block[block_type]["cells"] }
return block_json123456789101112131415161718192021222324252627282930import osimport jsonfrom supabase import create_client, Clientfrom dotenv import load_dotenvload_dotenv()
# https://supabase.com/dashboard
url: str = os.getenv("SUPABASE_URL")key: str = os.getenv("SUPABASE_KEY")
supabase: Client = create_client(url, key)
# def signup(email, password):# user = supabase.auth.sign_up({ "email": email, "password": password })# return user
# def signin(email, password):# user = supabase.auth.sign_in_with_password({ "email": email, "password": password })# return user
def get_app_keys(): data = supabase.schema('vault').table("decrypted_secrets").select("*").execute() return data
if __name__ == "__main__": # print(supabase.auth.sign_up({ "email": "test@test.com", "password": "test" })) # print(supabase.auth.sign_in_with_password({ "email": "test@test.com", "password": "password" })) data = get_app_keys() print(data)123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146import osimport jsonimport requestsfrom supabase import create_client, Clientfrom oauth2client import clientfrom dotenv import load_dotenvload_dotenv()
# https://supabase.com/dashboard
url: str = os.getenv("SUPABASE_URL")key: str = os.getenv("SUPABASE_KEY")# public_key: str = os.getenv("SUPABASE_PUBLIC_KEY")# db_host: str = os.getenv("SUPABASE_DB_HOST")# db_name: str = os.getenv("SUPABASE_DB_NAME")# db_port: str = os.getenv("SUPABASE_DB_PORT")# db_user: str = os.getenv("SUPABASE_DB_USER")# db_pwd: str = os.getenv("SUPABASE_DB_PWD")# s3_id: str = os.getenv("SUPABASE_S3_ID")# s3_endpoint: str = os.getenv("SUPABASE_S3_ENDPOINT")# s3_region: str = os.getenv("SUPABASE_S3_REGION")# s3_key: str = os.getenv("SUPABASE_S3_KEY")supabase: Client = create_client(url, key)
def check_user(email, type='google'): if type == 'google': print('Checking if User Exists for a given GmailID....') data, count = supabase.table("users").select("*").eq("email", email).execute() return data[1], count[1] if type == 'username': print('Checking if User Exists for a given Username....') data, count = supabase.table("users").select("*").eq("username", email).execute() return data[1], count[1]
def create_google_user(email, name, token_data, exist_check=True, scope='google'): print('Creating a New User....') # print(email, name) if exist_check: data, count = check_user(email) if not count and not data: print("No user found") if scope == 'google': data, count = supabase.table("users").insert({"email":email, "name":name, "auth_response": token_data}).execute() if scope == 'gmail': data, count = supabase.table("users").insert({"email":email, "name":name, "auth_response": token_data}).execute() return data[1], count[1] else: print("User already exists") return data, count else: try: if scope == 'google': data, count = supabase.table("users").insert({"email":email, "name":name, "auth_response": token_data}).execute() if scope == 'gmail': data, count = supabase.table("users").insert({"email":email, "name":name, "auth_response": token_data}).execute() return data[1], count[1] except Exception as e: print(f"🔴 Error! {e}") data, count = check_user(email) return data, count
def create_pwd_user(email, password): print('Creating a New User....') data, count = supabase.table("users").insert({"email":email, "password":password}).execute() return data[1], count[1]
def check_data(email=None, column=None, table=None, row_id_type=None, null_check=False, all=False): if email or null_check or all: print(f"Checking '{column}' for a given '{row_id_type}' in '{table}'....") try: if email: data, count = supabase.table(table).select(column).eq(row_id_type, email).execute() if null_check: data, count = supabase.table(table).select(column).is_(row_id_type, None).execute() if all: data, count = supabase.table(table).select(column).execute() if data[1]: if column == "*" or ", " in column: return data[1], count[1] if data[1][0][column]: print(f"Found a value in '{column}' for a given '{row_id_type}' in '{table}'....") if column == "auth_response" or column == "usage_limits" or column == 'gmail_token': return data[1][0][column], count[1] if column == "notion_access_token": token_data = json.loads(data[1][0][column]) return token_data, count[1] if column == "notion_access_pages": pages_data = json.loads(data[1][0][column]) return pages_data, count[1] return data[1], count[1] else: print(f"Found no value in '{column}' for a given '{row_id_type}' in '{table}'....") return None, None else: print(f"Column '{column}' not found for a given '{row_id_type}' in '{table}'....") return None, None except (IndexError, KeyError): print(f"🔴 Column '{column}' not found!") return None, None else: print(f"🔴 Invalid input email '{email}'!") return None, None
def insert_data(data, table="users"): print(f"Inserting data in '{table}'....") data, count = supabase.table(table).insert(data).execute() return data[1], count[1]
def update_data(row_id, data, table="users", row_id_type="email", column="notion_access_pages"): print(f"Updating '{column}' for a given '{row_id_type}' in '{table}'....") data, count = supabase.table(table).update({column: data}).eq(row_id_type, row_id).execute() print(f"Updated '{column}' for a given '{row_id_type}' in '{table}'....") return data[1], count[1]
def update_row(row_id, data, table="users", row_id_type="email"): cols = data.keys() print(f"Updating '{cols}' for a given '{row_id_type}' in '{table}'....") data, count = supabase.table(table).update(data).eq(row_id_type, row_id).execute() print(f"Updated '{cols}' for a given '{row_id_type}' in '{table}'....") return data[1], count[1]
def revoke_google_token(access_token): response = requests.post('https://oauth2.googleapis.com/revoke', params={'token': access_token}, headers = {'content-type': 'application/x-www-form-urlencoded'}) if response.status_code == 200: print("Token revoked successfully") else: print("Failed to revoke token: ", response.status_code, response.text)
# def delete_user(row_id_value, row_id_type='email'):# print(row_id_type, row_id_value)# if row_id_type in ('email','username') and row_id_value and row_id_value != 'f0_demo_user':# print(f'Deleting User for a given {row_id_type}....')# data, count = supabase.table("users").delete().eq(row_id_type, row_id_value).execute()# return data[1], count[1]# return None, None if __name__ == "__main__": data, count = check_user("test@gmail.com") # print(data, count) data = check_data("test@gmail.com", column="auth_response", table="users", row_id_type="email") creds = client.OAuth2Credentials.from_json(json.dumps(data)) # print(data, count, creds) # print(create_user("test@test.com", "test", {"access_token": "test"}, exist_check=False)) # print(update_user("test@test.com", {"access_token": "test2"})) # print(create_user("test@test.com", "test", {"access_token": "test"}, exist_check=False)) 1# https://supabase.com/dashboard12345678910111213
#### Example Test Code:# from fastapi.testclient import TestClientfrom fastapi import testclientimport app # Import your FastAPI app
client = testclient.TestClient(app.app)
def test_user_details_endpoint(): response = client.post("/get-user-details") assert response.status_code == 200 # Add more assertions based on expected response structure print(response.json())123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217'''Reading GMAIL using Python - Abhishek Chhibber'''
'''This script does the following:- Go to Gmal inbox- Find and read all the unread messages- Extract details (Date, Sender, Subject, Snippet, Body) and export them to a .csv file / DB- Mark the messages as Read - so that they are not read again '''
'''Before running this script, the user should get the authentication by following the link: https://developers.google.com/gmail/api/quickstart/pythonAlso, client_secret.json should be saved in the same directory as this file'''
''' Resources: 1. https://github.com/abhishekchhibber/Gmail-Api-through-Python 2. https://github.com/Charlkie/PyMail/blob/master/authentication.py 3. https://developers.google.com/gmail/api/reference/rest/v1/users.messages/list 4. https://console.cloud.google.com/apis/credentials/consent?project=third-node-425006-g7 5. https://github.com/aksappy/unsubscriber '''
# Importing required librariesimport apiclientfrom apiclient import discoveryfrom apiclient import errorsfrom httplib2 import Httpfrom oauth2client import file, client, toolsimport base64from bs4 import BeautifulSoupimport reimport timeimport dateutil.parser as parserfrom datetime import datetimeimport osimport datetimeimport csvimport pandas as pd
""" A gradio-powered web interface which does the following: 1. TAB 1 - STEP1: CONNECT GMAIL -> FETCH OVERALL + LABEL-WISE messagesTotal & messagesUnread -> SHOW LABEL-WISE INFO OR ERROR MESSAGE 2. TAB 1 - STEP2: FETCH N UNREAD EMAILS FOR A SELECTED LABEL FROM THE FETCHED LABELS OF STEP1 -> SHOW THE SUCCESS OR ERROR MESSAGE 3. TAB 1 - STEP3: SAVE THE FETCHED EMAILS OF STEP2 AS A CSV FILE IN FOLDER 'data/emails_data' 4. TAB 2 - STEP1: FETCH ALL THE CSV FILES FROM FOLDER 'data/emails_data' -> SHOW THE SUMMARY OF EMAILS AS SENDER X EMAIL_COUNT IN DESCENDING ORDER"""
''' GRADIO TAB 1: STEP 1 - INTERFACE 1 - CONNECT GMAIL & SHOW OVERALL & LABEL INFO'''# Creating a storage.JSON file with authentication detailsSCOPES = 'https://www.googleapis.com/auth/gmail.readonly' # we are using modify and not readonly, as we will be marking the messages Readstore = file.Storage('storage.json') creds = store.get()if not creds or creds.invalid: flow = client.flow_from_clientsecrets('client_secret.json', SCOPES) creds = tools.run_flow(flow, store)GMAIL = discovery.build('gmail', 'v1', http=creds.authorize(Http()))
# Get profile infouser_id = 'me'my_profile = GMAIL.users().getProfile(userId='me').execute()print(my_profile['emailAddress'], my_profile['messagesTotal'], my_profile['threadsTotal'])
# List LABELS & info regarding themmy_labels = GMAIL.users().labels().list(userId='me').execute()my_labels_db = pd.DataFrame(my_labels['labels'])# print(my_labels_db)# get info of system labelssystem_labels = my_labels_db[my_labels_db['type'] == 'system']excluded_labels = ['DRAFT','SENT','STARRED','IMPORTANT','CHAT','UNREAD','TRASH']system_labels = system_labels[~system_labels['name'].isin(excluded_labels)]for index, row in system_labels.iterrows(): label_id = row['id'] label_info = GMAIL.users().labels().get(userId='me', id=label_id).execute() # Update the messagesTotal and messagesUnread columns using row indexing system_labels.at[index, 'messagesTotal'] = label_info['messagesTotal'] system_labels.at[index, 'messagesUnread'] = label_info['messagesUnread']system_labels = system_labels.sort_values(by='messagesUnread')print(system_labels)
''' GRADIO TAB: STEP 2 - INTERFACE 1 - FETCH N UNREAD EMAILS FOR A SELECTED LABEL'''# Getting a specific number of unread mails from Inbox# labelIds can be changed accordinglylabel_id_one = 'CATEGORY_SOCIAL'label_id_two = 'UNREAD'maxResults = system_labels.loc[system_labels['name'] == label_id_one, 'messagesUnread'].iloc[0]print(maxResults)maxResults = 200inbox_msgs = GMAIL.users().messages().list( userId='me', labelIds=[label_id_one, label_id_two], maxResults=maxResults ).execute()
# We get a dictonary. Now reading values for the key 'messages'mssg_list = inbox_msgs.get('messages', [])print ("Total unread messages in inbox: ", str(len(mssg_list)))# print(mssg_list)
''' GRADIO TAB: STEP 2 - INTERFACE 2'''# Fetching details of each message in 'messages'final_list = [ ]for i, mssg in enumerate(mssg_list[:2]): temp_dict = { } m_id = mssg['id'] # get id of individual message message = GMAIL.users().messages().get(userId=user_id, id=m_id).execute() # fetch the message using API payld = message['payload'] # get payload of the message headr = payld['headers'] # get header of the payload # print(headr)
for one in headr: # getting the Subject if one['name'] == 'Subject': msg_subject = one['value'] temp_dict['Subject'] = msg_subject else: pass
for two in headr: # getting the date if two['name'] == 'Date': msg_date = two['value'] date_parse = (parser.parse(msg_date)) m_date = (date_parse) temp_dict['Date'] = str(m_date) else: pass
for three in headr: # getting the Sender if three['name'] == 'From': msg_from = three['value'] temp_dict['Sender'] = msg_from else: pass
# temp_dict['Snippet'] = message['snippet'] # fetching message snippet
# try: # # Fetching message body # mssg_parts = payld['parts'] # fetching the message parts # part_one = mssg_parts[0] # fetching first element of the part # part_body = part_one['body'] # fetching body of the message # part_data = part_body['data'] # fetching data from the body # clean_one = part_data.replace("-","+") # decoding from Base64 to UTF-8 # clean_one = clean_one.replace("_","/") # decoding from Base64 to UTF-8 # clean_two = base64.b64decode (bytes(clean_one, 'UTF-8')) # decoding from Base64 to UTF-8 # soup = BeautifulSoup(clean_two , "lxml" ) # mssg_body = soup.body() # # mssg_body is a readible form of message body # # depending on the end user's requirements, it can be further cleaned # # using regex, beautiful soup, or any other method # temp_dict['Message_body'] = mssg_body # except : # pass
# print (temp_dict) print(i, temp_dict['Date'], temp_dict['Sender'], temp_dict['Subject']) final_list.append(temp_dict) # This will create a dictonary item in the final list
# This will mark the messages as read # GMAIL.users().messages().modify(userId=user_id, id=m_id,body={ 'removeLabelIds': ['UNREAD']}).execute() print ("Total messaged retrived: ", str(len(final_list)))
''' GRADIO TAB: STEP 2 - INTERFACE 2 - SAVE THE FETCHED EMAILS FOR THE SELECTED LABEL'''# Exporting final_list as .csv'''The final_list will have dictionary in the following format:{ 'Sender': '"email.com" <name@email.com>', 'Subject': 'Lorem ipsum dolor sit ametLorem ipsum dolor sit amet', 'Date': 'yyyy-mm-dd', 'Snippet': 'Lorem ipsum dolor sit amet' 'Message_body': 'Lorem ipsum dolor sit amet'}The dictionary can be exported as a .csv or into a databse'''# create the folder 'data/emails_data' if it doesn't existfolder_path = "data/emails_data"os.makedirs(folder_path, exist_ok=True) # exist_ok=True avoids permission errors if folder exists# get current date and time in a specific formatnow = datetime.datetime.now().strftime("%Y-%m-%d_%H-%M-%S") # Adjust format as needed (YYYY-MM-DD_HH-MM-SS)filename = f"senders_report_{now}.csv"senders_df = pd.DataFrame(final_list)senders_df.to_csv(folder_path+"/"+filename, index=False)# sender_counts = senders_df.groupby('Sender')['Subject'].count().reset_index(name='emailCount')# sender_counts = sender_counts.sort_values(by='emailCount', ascending=False)# print(sender_counts)
''' GRADIO TAB '''# Fetch all the existing csv files & analyze the selected one to show emailCount for each Sender# get list of files in the foldercsv_files = []# get list of CSV filenames in sorted orderfolder_files = sorted(os.listdir(folder_path), reverse=True) # Sort filenames alphabeticallyfor filename in folder_files: # check if file extension is '.csv' (case-insensitive) if filename.lower().endswith('.csv'): csv_files.append(filename)print(csv_files)# check if there are any CSV filesif not csv_files: print("No CSV files found in the 'data/emails_data' folder.")else: # read the first CSV file first_file = csv_files[0] first_file_path = os.path.join(folder_path, first_file) df = pd.read_csv(first_file_path) # print information about the dataframe print(f"First CSV file: {first_file}") print(df.head()) # Display the first few rows sender_counts = df.groupby('Sender')['Subject'].count().reset_index(name='emailCount') sender_counts = sender_counts.sort_values(by='emailCount', ascending=False) print(sender_counts)
# Using AI to categorize emails into critical vs non-critical, opportunity vs promotion, social vs product or eisenhower framework1{"web":{"client_id":"","project_id":"","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"","redirect_uris":["https://myapp.com/auth","http://127.0.0.1:8000/auth","http://localhost"]}}1{"installed":{"client_id":"","project_id":"","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"","redirect_uris":["http://localhost"]}}1{"access_token": "", "client_id": "", "client_secret": "", "refresh_token": "", "token_expiry": "2222-12-22T21:22:22Z", "token_uri": "https://oauth2.googleapis.com/token", "user_agent": null, "revoke_uri": "https://oauth2.googleapis.com/revoke", "id_token": null, "id_token_jwt": null, "token_response": {"access_token": "", "expires_in": 3599, "scope": "https://www.googleapis.com/auth/gmail.readonly", "token_type": "Bearer"}, "scopes": ["https://www.googleapis.com/auth/gmail.readonly"], "token_info_uri": "https://oauth2.googleapis.com/tokeninfo", "invalid": false, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}1234567891011121314151617181920212223242526272829303132333435import pandas as pd
LABEL_COLS = ['label_id','label_name','messagesTotal','messagesUnread','label_type']LABEL_SAMPLES = [['CATEGORY_PROMOTIONS','CATEGORY_PROMOTIONS',100000,99999,'system']]LABEL_DB = pd.DataFrame(LABEL_SAMPLES, columns=LABEL_COLS)EMAIL_COLS = ['id','label','date','from','email','domain','subject','unsub_links']EMAIL_SAMPLES = [['iAmAAlphaNumericID','CATEGORY_PROMOTIONS','2009-04-01T00:00:00+00:00','SomeBank','creditcardoffer@somebank.com','somebank.com','Go on vacation. Enjoy & come back with debt 😉.','https://somebank.com/weWillHideTheUnsubscribeButtonToTheVeryEndBecauseWeThinkYouHaveShortAttentionSpan&WouldForgetToUnsubscribe']]EMAIL_DB = pd.DataFrame(EMAIL_SAMPLES, columns=EMAIL_COLS)PROCESSING_ERRORS_COLS = ['error']+EMAIL_COLSPROCESSING_ERRORS_SAMPLES = [['Unknown string format: Sun, 1 Apr 2009 00:00:00 +0000 (GMT+00:00)']+EMAIL_SAMPLES[0]]PROCESSING_ERRORS_DB = pd.DataFrame(PROCESSING_ERRORS_SAMPLES, columns=PROCESSING_ERRORS_COLS)EMAIL_SUMMARY_COLS = ['label','from','emailCount']DOMAIN_SUMMARY_SAMPLES = [['CATEGORY_PROMOTIONS','somebank.com',10000]]EMAIL_SUMMARY_DB = pd.DataFrame(DOMAIN_SUMMARY_SAMPLES, columns=EMAIL_SUMMARY_COLS)SENDER_SUMMARY_SAMPLES = [['CATEGORY_PROMOTIONS','creditcardoffer@somebank.com',9999]]SENDER_SUMMARY_DB = pd.DataFrame(SENDER_SUMMARY_SAMPLES, columns=EMAIL_SUMMARY_COLS)UNSUB_COLS = ['label','domain', 'email', 'from', 'emailCount', 'unsub_link']UNSUB_SAMPLES = [['CATEGORY_PROMOTIONS','somebank.com','creditcardoffer@somebank.com','SomeBank',9999,'https://somebank.com/unsubscribeButDontWorryWeWillFindYou']]UNSUB_DB = pd.DataFrame(UNSUB_SAMPLES, columns=UNSUB_COLS)
# Analyses Email0 generates:ANALYSIS_TYPES = [ 'Sender-wise Unread Emails Analysis', 'Domain-wise Unread Emails Analysis', 'Unread Emails', 'Unsubscribe Links for Unread Emails', 'Email Processing Errors', 'Overall']FILE_PATHS = [ 'data/emails_data/[Gmail0_SAMPLE]_CATEGORY_PROMOTIONS_Sender-wise Unread Emails Analysis.csv', 'data/emails_data/[Gmail0_SAMPLE]_CATEGORY_PROMOTIONS_Domain-wise Unread Emails Analysis.csv', 'data/emails_data/[Gmail0_SAMPLE]_CATEGORY_PROMOTIONS_Unread Emails.csv', 'data/emails_data/[Gmail0_SAMPLE]_CATEGORY_PROMOTIONS_Unsubscribe Links for Unread Emails.csv', 'data/emails_data/[Gmail0_SAMPLE]_CATEGORY_PROMOTIONS_Email Processing Errors.csv', 'data/emails_data/[Gmail0_SAMPLE]_CATEGORY_PROMOTIONS_Overall.xlsx']123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638"""The main Client class for the Python client."""
from __future__ import annotations
import concurrent.futuresimport hashlibimport jsonimport mathimport osimport reimport secretsimport shutilimport tempfileimport threadingimport timeimport urllib.parseimport uuidimport warningsfrom concurrent.futures import Futurefrom dataclasses import dataclassfrom datetime import datetimefrom functools import partialfrom pathlib import Pathfrom threading import Lockfrom typing import Any, Callable, Literal
import httpximport huggingface_hubfrom huggingface_hub import CommitOperationAdd, SpaceHardware, SpaceStagefrom huggingface_hub.utils import ( RepositoryNotFoundError, build_hf_headers, send_telemetry,)from packaging import version
from gradio_client import utilsfrom gradio_client.compatibility import EndpointV3Compatibilityfrom gradio_client.data_classes import ParameterInfofrom gradio_client.documentation import documentfrom gradio_client.exceptions import AppError, AuthenticationErrorfrom gradio_client.utils import ( Communicator, JobStatus, Message, QueueError, ServerMessage, Status, StatusUpdate,)
DEFAULT_TEMP_DIR = os.environ.get("GRADIO_TEMP_DIR") or str( Path(tempfile.gettempdir()) / "gradio")
@document("predict", "submit", "view_api", "duplicate", "deploy_discord")class Client: """ The main Client class for the Python client. This class is used to connect to a remote Gradio app and call its API endpoints.
Example: from gradio_client import Client
client = Client("abidlabs/whisper-large-v2") # connecting to a Hugging Face Space client.predict("test.mp4", api_name="/predict") >> What a nice recording! # returns the result of the remote API call
client = Client("https://bec81a83-5b5c-471e.gradio.live") # connecting to a temporary Gradio share URL job = client.submit("hello", api_name="/predict") # runs the prediction in a background thread job.result() >> 49 # returns the result of the remote API call (blocking call) """
def __init__( self, src: str, hf_token: str | None = None, max_workers: int = 40, verbose: bool = True, auth: tuple[str, str] | None = None, *, headers: dict[str, str] | None = None, download_files: str | Path | Literal[False] = DEFAULT_TEMP_DIR, ssl_verify: bool = True, _skip_components: bool = True, # internal parameter to skip values certain components (e.g. State) that do not need to be displayed to users. ): """ Parameters: src: Either the name of the Hugging Face Space to load, (e.g. "abidlabs/whisper-large-v2") or the full URL (including "http" or "https") of the hosted Gradio app to load (e.g. "http://mydomain.com/app" or "https://bec81a83-5b5c-471e.gradio.live/"). hf_token: The Hugging Face token to use to access private Spaces. Automatically fetched if you are logged in via the Hugging Face Hub CLI. Obtain from: https://huggingface.co/settings/token max_workers: The maximum number of thread workers that can be used to make requests to the remote Gradio app simultaneously. verbose: Whether the client should print statements to the console. headers: Additional headers to send to the remote Gradio app on every request. By default only the HF authorization and user-agent headers are sent. This parameter will override the default headers if they have the same keys. download_files: Directory where the client should download output files on the local machine from the remote API. By default, uses the value of the GRADIO_TEMP_DIR environment variable which, if not set by the user, is a temporary directory on your machine. If False, the client does not download files and returns a FileData dataclass object with the filepath on the remote machine instead. ssl_verify: If False, skips certificate validation which allows the client to connect to Gradio apps that are using self-signed certificates. """ self.verbose = verbose self.hf_token = hf_token self.download_files = download_files self._skip_components = _skip_components self.headers = build_hf_headers( token=hf_token, library_name="gradio_client", library_version=utils.__version__, ) if headers: self.headers.update(headers) self.ssl_verify = ssl_verify self.space_id = None self.cookies: dict[str, str] = {} if isinstance(self.download_files, (str, Path)): if not os.path.exists(self.download_files): os.makedirs(self.download_files, exist_ok=True) if not os.path.isdir(self.download_files): raise ValueError(f"Path: {self.download_files} is not a directory.") self.output_dir = str(self.download_files) else: self.output_dir = DEFAULT_TEMP_DIR
if src.startswith("http://") or src.startswith("https://"): _src = src if src.endswith("/") else src + "/" if "huggingface.co/spaces/" in src: parts = urllib.parse.urlparse(src).path.split('/') try: # Find the index of 'spaces' and extract namespace and space_id spaces_index = parts.index('spaces') namespace = parts[spaces_index + 1] space_id = parts[spaces_index + 2] self.space_id = namespace + '/' + space_id except (ValueError, IndexError): raise ValueError("Invalid Hugging Face Space URL format") if ".hf.space" in src: subdomain = urllib.parse.urlparse(src).hostname.split('.')[0] namespace, space_id = subdomain.split('-', 1) self.space_id = namespace + '/' + space_id else: _src = self._space_name_to_src(src) if _src is None: raise ValueError( f"Could not find Space: {src}. If it is a private Space, please provide an hf_token." ) self.space_id = src self.src = _src self.is_private_space = None if self.space_id: self.is_private_space = huggingface_hub.space_info(self.space_id, token=self.hf_token).private state = self._get_space_state() if state == SpaceStage.BUILDING: if self.verbose: print("Space is still building. Please wait...") while self._get_space_state() == SpaceStage.BUILDING: time.sleep(2) # so we don't get rate limited by the API pass if state in utils.INVALID_RUNTIME: raise ValueError( f"The current space is in the invalid state: {state}. " "Please contact the owner to fix this." ) if self.verbose: print(f"Loaded as API: {self.src} ✔")
if auth is not None: self._login(auth)
self.config = self._get_config() self.protocol: Literal["ws", "sse", "sse_v1", "sse_v2", "sse_v2.1"] = ( self.config.get("protocol", "ws") ) self.api_url = urllib.parse.urljoin(self.src, utils.API_URL) self.sse_url = urllib.parse.urljoin( self.src, utils.SSE_URL_V0 if self.protocol == "sse" else utils.SSE_URL ) self.heartbeat_url = urllib.parse.urljoin(self.src, utils.HEARTBEAT_URL) self.sse_data_url = urllib.parse.urljoin( self.src, utils.SSE_DATA_URL_V0 if self.protocol == "sse" else utils.SSE_DATA_URL, ) self.ws_url = urllib.parse.urljoin( self.src.replace("http", "ws", 1), utils.WS_URL ) self.upload_url = urllib.parse.urljoin(self.src, utils.UPLOAD_URL) self.reset_url = urllib.parse.urljoin(self.src, utils.RESET_URL) self.app_version = version.parse(self.config.get("version", "2.0")) self._info = self._get_api_info() self.session_hash = str(uuid.uuid4())
endpoint_class = ( Endpoint if self.protocol.startswith("sse") else EndpointV3Compatibility ) self.endpoints = { dependency.get("id", fn_index): endpoint_class( self, dependency.get("id", fn_index), dependency, self.protocol ) for fn_index, dependency in enumerate(self.config["dependencies"]) }
# Create a pool of threads to handle the requests self.executor = concurrent.futures.ThreadPoolExecutor(max_workers=max_workers)
# Disable telemetry by setting the env variable HF_HUB_DISABLE_TELEMETRY=1 threading.Thread(target=self._telemetry_thread, daemon=True).start() self._refresh_heartbeat = threading.Event() self._kill_heartbeat = threading.Event()
self.heartbeat = threading.Thread(target=self._stream_heartbeat, daemon=True) self.heartbeat.start()
self.stream_open = False self.streaming_future: Future | None = None self.pending_messages_per_event: dict[str, list[Message | None]] = {} self.pending_event_ids: set[str] = set()
def close(self): self._kill_heartbeat.set() self.heartbeat.join(timeout=1)
def _stream_heartbeat(self): while True: url = self.heartbeat_url.format(session_hash=self.session_hash) try: with httpx.stream( "GET", url, headers=self.headers, cookies=self.cookies, verify=self.ssl_verify, timeout=20, ) as response: for _ in response.iter_lines(): if self._refresh_heartbeat.is_set(): self._refresh_heartbeat.clear() break if self._kill_heartbeat.is_set(): return except httpx.TransportError: return
def stream_messages( self, protocol: Literal["sse_v1", "sse_v2", "sse_v2.1", "sse_v3"] ) -> None: try: with httpx.Client( timeout=httpx.Timeout(timeout=None), verify=self.ssl_verify ) as client: with client.stream( "GET", self.sse_url, params={"session_hash": self.session_hash}, headers=self.headers, cookies=self.cookies, ) as response: for line in response.iter_lines(): line = line.rstrip("\n") if not len(line): continue if line.startswith("data:"): resp = json.loads(line[5:]) if resp["msg"] == ServerMessage.heartbeat: continue elif ( resp.get("message", "") == ServerMessage.server_stopped ): for ( pending_messages ) in self.pending_messages_per_event.values(): pending_messages.append(resp) return elif resp["msg"] == ServerMessage.close_stream: self.stream_open = False return event_id = resp["event_id"] if event_id not in self.pending_messages_per_event: self.pending_messages_per_event[event_id] = [] self.pending_messages_per_event[event_id].append(resp) if resp["msg"] == ServerMessage.process_completed: self.pending_event_ids.remove(event_id) if ( len(self.pending_event_ids) == 0 and protocol != "sse_v3" ): self.stream_open = False return else: raise ValueError(f"Unexpected SSE line: '{line}'") except BaseException as e: # If the job is cancelled the stream will close so we # should not raise this httpx exception that comes from the # stream abruply closing if isinstance(e, httpx.RemoteProtocolError): return import traceback
traceback.print_exc() raise e
def send_data(self, data, hash_data, protocol): req = httpx.post( self.sse_data_url, json={**data, **hash_data}, headers=self.headers, cookies=self.cookies, verify=self.ssl_verify, ) if req.status_code == 503: raise QueueError("Queue is full! Please try again.") req.raise_for_status() resp = req.json() event_id = resp["event_id"]
if not self.stream_open: self.stream_open = True
def open_stream(): return self.stream_messages(protocol)
def close_stream(_): self.stream_open = False for _, pending_messages in self.pending_messages_per_event.items(): pending_messages.append(None)
if self.streaming_future is None or self.streaming_future.done(): self.streaming_future = self.executor.submit(open_stream) self.streaming_future.add_done_callback(close_stream)
return event_id
@classmethod def duplicate( cls, from_id: str, to_id: str | None = None, hf_token: str | None = None, private: bool = True, hardware: Literal[ "cpu-basic", "cpu-upgrade", "t4-small", "t4-medium", "a10g-small", "a10g-large", "a100-large", ] | SpaceHardware | None = None, secrets: dict[str, str] | None = None, sleep_timeout: int = 5, max_workers: int = 40, verbose: bool = True, ): """ Duplicates a Hugging Face Space under your account and returns a Client object for the new Space. No duplication is created if the Space already exists in your account (to override this, provide a new name for the new Space using `to_id`). To use this method, you must provide an `hf_token` or be logged in via the Hugging Face Hub CLI.
The new Space will be private by default and use the same hardware as the original Space. This can be changed by using the `private` and `hardware` parameters. For hardware upgrades (beyond the basic CPU tier), you may be required to provide billing information on Hugging Face: https://huggingface.co/settings/billing
Parameters: from_id: The name of the Hugging Face Space to duplicate in the format "{username}/{space_id}", e.g. "gradio/whisper". to_id: The name of the new Hugging Face Space to create, e.g. "abidlabs/whisper-duplicate". If not provided, the new Space will be named "{your_HF_username}/{space_id}". hf_token: The Hugging Face token to use to access private Spaces. Automatically fetched if you are logged in via the Hugging Face Hub CLI. Obtain from: https://huggingface.co/settings/token private: Whether the new Space should be private (True) or public (False). Defaults to True. hardware: The hardware tier to use for the new Space. Defaults to the same hardware tier as the original Space. Options include "cpu-basic", "cpu-upgrade", "t4-small", "t4-medium", "a10g-small", "a10g-large", "a100-large", subject to availability. secrets: A dictionary of (secret key, secret value) to pass to the new Space. Defaults to None. Secrets are only used when the Space is duplicated for the first time, and are not updated if the duplicated Space already exists. sleep_timeout: The number of minutes after which the duplicate Space will be puased if no requests are made to it (to minimize billing charges). Defaults to 5 minutes. max_workers: The maximum number of thread workers that can be used to make requests to the remote Gradio app simultaneously. verbose: Whether the client should print statements to the console. Example: import os from gradio_client import Client HF_TOKEN = os.environ.get("HF_TOKEN") client = Client.duplicate("abidlabs/whisper", hf_token=HF_TOKEN) client.predict("audio_sample.wav") >> "This is a test of the whisper speech recognition model." """ try: original_info = huggingface_hub.get_space_runtime(from_id, token=hf_token) except RepositoryNotFoundError as rnfe: raise ValueError( f"Could not find Space: {from_id}. If it is a private Space, please provide an `hf_token`." ) from rnfe if to_id: if "/" in to_id: to_id = to_id.split("/")[1] space_id = huggingface_hub.get_full_repo_name(to_id, token=hf_token) else: space_id = huggingface_hub.get_full_repo_name( from_id.split("/")[1], token=hf_token ) try: huggingface_hub.get_space_runtime(space_id, token=hf_token) if verbose: print( f"Using your existing Space: {utils.SPACE_URL.format(space_id)} 🤗" ) if secrets is not None: warnings.warn( "Secrets are only used when the Space is duplicated for the first time, and are not updated if the duplicated Space already exists." ) except RepositoryNotFoundError: if verbose: print(f"Creating a duplicate of {from_id} for your own use... 🤗") huggingface_hub.duplicate_space( from_id=from_id, to_id=space_id, token=hf_token, exist_ok=True, private=private, ) if secrets is not None: for key, value in secrets.items(): huggingface_hub.add_space_secret( space_id, key, value, token=hf_token ) if verbose: print(f"Created new Space: {utils.SPACE_URL.format(space_id)}") current_info = huggingface_hub.get_space_runtime(space_id, token=hf_token) current_hardware = ( current_info.hardware or huggingface_hub.SpaceHardware.CPU_BASIC ) hardware = hardware or original_info.hardware if current_hardware != hardware: huggingface_hub.request_space_hardware(space_id, hardware, token=hf_token) # type: ignore print( f"-------\nNOTE: this Space uses upgraded hardware: {hardware}... see billing info at https://huggingface.co/settings/billing\n-------" ) # Setting a timeout only works if the hardware is not basic # so set it here after the hardware has been requested if hardware != huggingface_hub.SpaceHardware.CPU_BASIC: utils.set_space_timeout( space_id, hf_token=hf_token, timeout_in_seconds=sleep_timeout * 60 ) if verbose: print("") client = cls( space_id, hf_token=hf_token, max_workers=max_workers, verbose=verbose ) return client
def _get_space_state(self): if not self.space_id: return None info = huggingface_hub.get_space_runtime(self.space_id, token=self.hf_token) return info.stage
def predict( self, *args, api_name: str | None = None, fn_index: int | None = None, **kwargs, ) -> Any: """ Calls the Gradio API and returns the result (this is a blocking call).
Parameters: args: The arguments to pass to the remote API. The order of the arguments must match the order of the inputs in the Gradio app. api_name: The name of the API endpoint to call starting with a leading slash, e.g. "/predict". Does not need to be provided if the Gradio app has only one named API endpoint. fn_index: As an alternative to api_name, this parameter takes the index of the API endpoint to call, e.g. 0. Both api_name and fn_index can be provided, but if they conflict, api_name will take precedence. Returns: The result of the API call. Will be a Tuple if the API has multiple outputs. Example: from gradio_client import Client client = Client(src="gradio/calculator") client.predict(5, "add", 4, api_name="/predict") >> 9.0 """ inferred_fn_index = self._infer_fn_index(api_name, fn_index) if self.endpoints[inferred_fn_index].is_continuous: raise ValueError( "Cannot call predict on this function as it may run forever. Use submit instead." ) return self.submit( *args, api_name=api_name, fn_index=fn_index, **kwargs ).result()
def new_helper(self, fn_index: int) -> Communicator: return Communicator( Lock(), JobStatus(), self.endpoints[fn_index].process_predictions, self.reset_url, )
def submit( self, *args, api_name: str | None = None, fn_index: int | None = None, result_callbacks: Callable | list[Callable] | None = None, **kwargs, ) -> Job: """ Creates and returns a Job object which calls the Gradio API in a background thread. The job can be used to retrieve the status and result of the remote API call.
Parameters: args: The arguments to pass to the remote API. The order of the arguments must match the order of the inputs in the Gradio app. api_name: The name of the API endpoint to call starting with a leading slash, e.g. "/predict". Does not need to be provided if the Gradio app has only one named API endpoint. fn_index: As an alternative to api_name, this parameter takes the index of the API endpoint to call, e.g. 0. Both api_name and fn_index can be provided, but if they conflict, api_name will take precedence. result_callbacks: A callback function, or list of callback functions, to be called when the result is ready. If a list of functions is provided, they will be called in order. The return values from the remote API are provided as separate parameters into the callback. If None, no callback will be called. Returns: A Job object that can be used to retrieve the status and result of the remote API call. Example: from gradio_client import Client client = Client(src="gradio/calculator") job = client.submit(5, "add", 4, api_name="/predict") job.status() >> <Status.STARTING: 'STARTING'> job.result() # blocking call >> 9.0 """ inferred_fn_index = self._infer_fn_index(api_name, fn_index)
endpoint = self.endpoints[inferred_fn_index]
if isinstance(endpoint, Endpoint): args = utils.construct_args(endpoint.parameters_info, args, kwargs)
helper = None if endpoint.protocol in ( "ws", "sse", "sse_v1", "sse_v2", "sse_v2.1", "sse_v3", ): helper = self.new_helper(inferred_fn_index) end_to_end_fn = endpoint.make_end_to_end_fn(helper) future = self.executor.submit(end_to_end_fn, *args)
cancel_fn = endpoint.make_cancel(helper)
job = Job( future, communicator=helper, verbose=self.verbose, space_id=self.space_id, _cancel_fn=cancel_fn, )
if result_callbacks: if isinstance(result_callbacks, Callable): result_callbacks = [result_callbacks]
def create_fn(callback) -> Callable: def fn(future): if isinstance(future.result(), tuple): callback(*future.result()) else: callback(future.result())
return fn
for callback in result_callbacks: job.add_done_callback(create_fn(callback))
return job
def _get_api_info(self): api_info_url = urllib.parse.urljoin(self.src, utils.RAW_API_INFO_URL) if self.app_version > version.Version("3.36.1"): r = httpx.get( api_info_url, headers=self.headers, cookies=self.cookies, verify=self.ssl_verify, ) if r.is_success: info = r.json() else: raise ValueError(f"Could not fetch api info for {self.src}: {r.text}") else: fetch = httpx.post( utils.SPACE_FETCHER_URL, json={ "config": json.dumps(self.config), "serialize": False, }, ) if fetch.is_success: info = fetch.json()["api"] else: raise ValueError( f"Could not fetch api info for {self.src}: {fetch.text}" ) info["named_endpoints"] = { a: e for a, e in info["named_endpoints"].items() if e.pop("show_api", True) } info["unnamed_endpoints"] = { a: e for a, e in info["unnamed_endpoints"].items() if e.pop("show_api", True) } return info
def view_api( self, all_endpoints: bool | None = None, print_info: bool = True, return_format: Literal["dict", "str"] | None = None, ) -> dict | str | None: """ Prints the usage info for the API. If the Gradio app has multiple API endpoints, the usage info for each endpoint will be printed separately. If return_format="dict" the info is returned in dictionary format, as shown in the example below.
Parameters: all_endpoints: If True, prints information for both named and unnamed endpoints in the Gradio app. If False, will only print info about named endpoints. If None (default), will print info about named endpoints, unless there aren't any -- in which it will print info about unnamed endpoints. print_info: If True, prints the usage info to the console. If False, does not print the usage info. return_format: If None, nothing is returned. If "str", returns the same string that would be printed to the console. If "dict", returns the usage info as a dictionary that can be programmatically parsed, and *all endpoints are returned in the dictionary* regardless of the value of `all_endpoints`. The format of the dictionary is in the docstring of this method. Example: from gradio_client import Client client = Client(src="gradio/calculator") client.view_api(return_format="dict") >> { 'named_endpoints': { '/predict': { 'parameters': [ { 'label': 'num1', 'python_type': 'int | float', 'type_description': 'numeric value', 'component': 'Number', 'example_input': '5' }, { 'label': 'operation', 'python_type': 'str', 'type_description': 'string value', 'component': 'Radio', 'example_input': 'add' }, { 'label': 'num2', 'python_type': 'int | float', 'type_description': 'numeric value', 'component': 'Number', 'example_input': '5' }, ], 'returns': [ { 'label': 'output', 'python_type': 'int | float', 'type_description': 'numeric value', 'component': 'Number', }, ] }, '/flag': { 'parameters': [ ... ], 'returns': [ ... ] } } 'unnamed_endpoints': { 2: { 'parameters': [ ... ], 'returns': [ ... ] } } } }
""" num_named_endpoints = len(self._info["named_endpoints"]) num_unnamed_endpoints = len(self._info["unnamed_endpoints"]) if num_named_endpoints == 0 and all_endpoints is None: all_endpoints = True
human_info = "Client.predict() Usage Info\n---------------------------\n" human_info += f"Named API endpoints: {num_named_endpoints}\n"
for api_name, endpoint_info in self._info["named_endpoints"].items(): human_info += self._render_endpoints_info(api_name, endpoint_info)
if all_endpoints: human_info += f"\nUnnamed API endpoints: {num_unnamed_endpoints}\n" for fn_index, endpoint_info in self._info["unnamed_endpoints"].items(): # When loading from json, the fn_indices are read as strings # because json keys can only be strings human_info += self._render_endpoints_info(int(fn_index), endpoint_info) elif num_unnamed_endpoints > 0: human_info += f"\nUnnamed API endpoints: {num_unnamed_endpoints}, to view, run Client.view_api(all_endpoints=True)\n"
if print_info: print(human_info) if return_format == "str": return human_info elif return_format == "dict": return self._info
def reset_session(self) -> None: self.session_hash = str(uuid.uuid4()) self._refresh_heartbeat.set()
def _render_endpoints_info( self, name_or_index: str | int, endpoints_info: dict[str, list[ParameterInfo]], ) -> str: parameter_info = endpoints_info["parameters"] parameter_names = [ p.get("parameter_name") or p["label"] for p in parameter_info ] parameter_names = [utils.sanitize_parameter_names(p) for p in parameter_names] rendered_parameters = ", ".join(parameter_names) if rendered_parameters: rendered_parameters = rendered_parameters + ", " return_values = [p["label"] for p in endpoints_info["returns"]] return_values = [utils.sanitize_parameter_names(r) for r in return_values] rendered_return_values = ", ".join(return_values) if len(return_values) > 1: rendered_return_values = f"({rendered_return_values})"
if isinstance(name_or_index, str): final_param = f'api_name="{name_or_index}"' elif isinstance(name_or_index, int): final_param = f"fn_index={name_or_index}" else: raise ValueError("name_or_index must be a string or integer")
human_info = f"\n - predict({rendered_parameters}{final_param}) -> {rendered_return_values}\n" human_info += " Parameters:\n" if parameter_info: for info in parameter_info: desc = ( f" ({info['python_type']['description']})" if info["python_type"].get("description") else "" ) default_value = info.get("parameter_default") default_value = utils.traverse( default_value, lambda x: f"handle_file(\"{x['url']}\")", utils.is_file_obj_with_meta, ) default_info = ( "(required)" if not info.get("parameter_has_default", False) else f"(not required, defaults to: {default_value})" ) type_ = info["python_type"]["type"] if info.get("parameter_has_default", False) and default_value is None: type_ += " | None" human_info += f" - [{info['component']}] {utils.sanitize_parameter_names(info.get('parameter_name') or info['label'])}: {type_} {default_info} {desc} \n" else: human_info += " - None\n" human_info += " Returns:\n" if endpoints_info["returns"]: for info in endpoints_info["returns"]: desc = ( f" ({info['python_type']['description']})" if info["python_type"].get("description") else "" ) type_ = info["python_type"]["type"] human_info += f" - [{info['component']}] {utils.sanitize_parameter_names(info['label'])}: {type_}{desc} \n" else: human_info += " - None\n"
return human_info
def __repr__(self): return self.view_api(print_info=False, return_format="str")
def __str__(self): return self.view_api(print_info=False, return_format="str")
def _telemetry_thread(self) -> None: # Disable telemetry by setting the env variable HF_HUB_DISABLE_TELEMETRY=1 data = { "src": self.src, } try: send_telemetry( topic="py_client/initiated", library_name="gradio_client", library_version=utils.__version__, user_agent=data, ) except Exception: pass
def _infer_fn_index(self, api_name: str | None, fn_index: int | None) -> int: inferred_fn_index = None if api_name is not None: for i, d in enumerate(self.config["dependencies"]): config_api_name = d.get("api_name") if config_api_name is None or config_api_name is False: continue if "/" + config_api_name == api_name: inferred_fn_index = d.get("id", i) break else: error_message = f"Cannot find a function with `api_name`: {api_name}." if not api_name.startswith("/"): error_message += " Did you mean to use a leading slash?" raise ValueError(error_message) elif fn_index is not None: inferred_fn_index = fn_index if ( inferred_fn_index not in self.endpoints or not self.endpoints[inferred_fn_index].is_valid ): raise ValueError(f"Invalid function index: {fn_index}.") else: valid_endpoints = [ e for e in self.endpoints.values() if e.is_valid and e.api_name is not None and e.backend_fn is not None and e.show_api ] if len(valid_endpoints) == 1: inferred_fn_index = valid_endpoints[0].fn_index else: raise ValueError( "This Gradio app might have multiple endpoints. Please specify an `api_name` or `fn_index`" ) return inferred_fn_index
def __del__(self): if hasattr(self, "executor"): self.executor.shutdown(wait=True)
def _space_name_to_src(self, space) -> str | None: return huggingface_hub.space_info(space, token=self.hf_token).host # type: ignore
def _login(self, auth: tuple[str, str]): if self.is_private_space: resp = httpx.post( urllib.parse.urljoin(self.src, utils.LOGIN_URL), headers=self.headers, # This missing line is stopping usage of private gradio spaces with authentication as api data={"username": auth[0], "password": auth[1]}, verify=self.ssl_verify, ) else: resp = httpx.post( urllib.parse.urljoin(self.src, utils.LOGIN_URL), data={"username": auth[0], "password": auth[1]}, verify=self.ssl_verify, ) if not resp.is_success: if resp.status_code == 401: raise AuthenticationError( f"Could not login to {self.src}. Invalid credentials." ) else: raise ValueError(f"Could not login to {self.src}.") self.cookies = { name: value for name, value in resp.cookies.items() if value is not None }
def _get_config(self) -> dict: r = httpx.get( urllib.parse.urljoin(self.src, utils.CONFIG_URL), headers=self.headers, cookies=self.cookies, verify=self.ssl_verify, ) if r.is_success: return r.json() elif r.status_code == 401: raise AuthenticationError( f"Could not load {self.src} as credentials were not provided. Please login." ) else: # to support older versions of Gradio r = httpx.get( self.src, headers=self.headers, cookies=self.cookies, verify=self.ssl_verify, ) if not r.is_success: raise ValueError(f"Could not fetch config for {self.src}") # some basic regex to extract the config result = re.search(r"window.gradio_config = (.*?);[\s]*</script>", r.text) try: config = json.loads(result.group(1)) # type: ignore except AttributeError as ae: raise ValueError( f"Could not get Gradio config from: {self.src}" ) from ae if "allow_flagging" in config: raise ValueError( "Gradio 2.x is not supported by this client. Please upgrade your Gradio app to Gradio 3.x or higher." ) return config
def deploy_discord( self, discord_bot_token: str | None = None, api_names: list[str | tuple[str, str]] | None = None, to_id: str | None = None, hf_token: str | None = None, private: bool = False, ): """ Deploy the upstream app as a discord bot. Currently only supports gr.ChatInterface. Parameters: discord_bot_token: This is the "password" needed to be able to launch the bot. Users can get a token by creating a bot app on the discord website. If run the method without specifying a token, the space will explain how to get one. See here: https://huggingface.co/spaces/freddyaboulton/test-discord-bot-v1. api_names: The api_names of the app to turn into bot commands. This parameter currently has no effect as ChatInterface only has one api_name ('/chat'). to_id: The name of the space hosting the discord bot. If None, the name will be gradio-discord-bot-{random-substring} hf_token: HF api token with write priviledges in order to upload the files to HF space. Can be ommitted if logged in via the HuggingFace CLI, unless the upstream space is private. Obtain from: https://huggingface.co/settings/token private: Whether the space hosting the discord bot is private. The visibility of the discord bot itself is set via the discord website. See https://huggingface.co/spaces/freddyaboulton/test-discord-bot-v1 """
if self.config["mode"] == "chat_interface" and not api_names: api_names = [("chat", "chat")]
valid_list = isinstance(api_names, list) and ( isinstance(n, str) or ( isinstance(n, tuple) and isinstance(n[0], str) and isinstance(n[1], str) ) for n in api_names ) if api_names is None or not valid_list: raise ValueError( f"Each entry in api_names must be either a string or a tuple of strings. Received {api_names}" ) if len(api_names) != 1: raise ValueError("Currently only one api_name can be deployed to discord.")
for i, name in enumerate(api_names): if isinstance(name, str): api_names[i] = (name, name)
fn = next( ( ep for ep in self.endpoints.values() if ep.api_name == f"/{api_names[0][0]}" ), None, ) if not fn: raise ValueError( f"api_name {api_names[0][0]} not present in {self.space_id or self.src}" ) inputs = [inp for inp in fn.input_component_types if not inp.skip] outputs = [inp for inp in fn.input_component_types if not inp.skip] if not inputs == ["textbox"] and outputs == ["textbox"]: raise ValueError( "Currently only api_names with a single textbox as input and output are supported. " f"Received {inputs} and {outputs}" )
is_private = False if self.space_id: is_private = huggingface_hub.space_info(self.space_id).private if is_private and not hf_token: raise ValueError( f"Since {self.space_id} is private, you must explicitly pass in hf_token " "so that it can be added as a secret in the discord bot space." )
if to_id: if "/" in to_id: to_id = to_id.split("/")[1] space_id = huggingface_hub.get_full_repo_name(to_id, token=hf_token) else: if self.space_id: space_id = f'{self.space_id.split("/")[1]}-gradio-discord-bot' else: space_id = f"gradio-discord-bot-{secrets.token_hex(4)}" space_id = huggingface_hub.get_full_repo_name(space_id, token=hf_token)
api = huggingface_hub.HfApi()
try: huggingface_hub.space_info(space_id) first_upload = False except huggingface_hub.utils.RepositoryNotFoundError: first_upload = True
huggingface_hub.create_repo( space_id, repo_type="space", space_sdk="gradio", token=hf_token, exist_ok=True, private=private, ) if first_upload: huggingface_hub.metadata_update( repo_id=space_id, repo_type="space", metadata={"tags": ["gradio-discord-bot"]}, )
with open( str(Path(__file__).parent / "templates" / "discord_chat.py"), encoding="utf-8", ) as f: app = f.read() app = app.replace("<<app-src>>", self.src) app = app.replace("<<api-name>>", api_names[0][0]) app = app.replace("<<command-name>>", api_names[0][1])
with tempfile.NamedTemporaryFile( mode="w", delete=False, encoding="utf-8" ) as app_file: with tempfile.NamedTemporaryFile(mode="w", delete=False) as requirements: app_file.write(app) requirements.write("\n".join(["discord.py==2.3.1"]))
operations = [ CommitOperationAdd(path_in_repo="app.py", path_or_fileobj=app_file.name), CommitOperationAdd( path_in_repo="requirements.txt", path_or_fileobj=requirements.name ), ]
api.create_commit( repo_id=space_id, commit_message="Deploy Discord Bot", repo_type="space", operations=operations, token=hf_token, )
if discord_bot_token: huggingface_hub.add_space_secret( space_id, "DISCORD_TOKEN", discord_bot_token, token=hf_token ) if is_private: huggingface_hub.add_space_secret( space_id, "HF_TOKEN", hf_token, # type: ignore token=hf_token, )
url = f"https://huggingface.co/spaces/{space_id}" print(f"See your discord bot here! {url}") return url
@dataclassclass ComponentApiType: skip: bool value_is_file: bool is_state: bool
@dataclassclass ReplaceMe: index: int
class Endpoint: """Helper class for storing all the information about a single API endpoint."""
def __init__( self, client: Client, fn_index: int, dependency: dict, protocol: str = "sse_v1" ): self.client: Client = client self.fn_index = fn_index self.dependency = dependency api_name = dependency.get("api_name") self.api_name: str | Literal[False] | None = ( "/" + api_name if isinstance(api_name, str) else api_name ) self._info = self.client._info self.protocol = protocol self.input_component_types = [ self._get_component_type(id_) for id_ in dependency["inputs"] ] self.output_component_types = [ self._get_component_type(id_) for id_ in dependency["outputs"] ] self.parameters_info = self._get_parameters_info()
self.root_url = client.src + "/" if not client.src.endswith("/") else client.src self.is_continuous = dependency.get("types", {}).get("continuous", False)
# Disallow hitting endpoints that the Gradio app has disabled self.is_valid = self.api_name is not False self.backend_fn = dependency.get("backend_fn") self.show_api = dependency.get("show_api")
def _get_component_type(self, component_id: int): component = next( i for i in self.client.config["components"] if i["id"] == component_id ) skip_api = component.get("skip_api", component["type"] in utils.SKIP_COMPONENTS) return ComponentApiType( skip_api, self.value_is_file(component), component["type"] == "state", )
def _get_parameters_info(self) -> list[ParameterInfo] | None: if self.api_name in self._info["named_endpoints"]: return self._info["named_endpoints"][self.api_name]["parameters"] return None
@staticmethod def value_is_file(component: dict) -> bool: # This is still hacky as it does not tell us which part of the payload is a file. # If a component has a complex payload, part of which is a file, this will simply # return True, which means that all parts of the payload will be uploaded as files # if they are valid file paths. We will deprecate this 1.0. if "api_info" not in component: return False return utils.value_is_file(component["api_info"])
def __repr__(self): return f"Endpoint src: {self.client.src}, api_name: {self.api_name}, fn_index: {self.fn_index}"
def __str__(self): return self.__repr__()
def make_end_to_end_fn(self, helper: Communicator | None = None): _predict = self.make_predict(helper)
def _inner(*data): if not self.is_valid: raise utils.InvalidAPIEndpointError()
data = self.insert_empty_state(*data) data = self.process_input_files(*data) predictions = _predict(*data) predictions = self.process_predictions(*predictions)
# Append final output only if not already present # for consistency between generators and not generators if helper: with helper.lock: if not helper.job.outputs: helper.job.outputs.append(predictions) return predictions
return _inner
def make_cancel( self, helper: Communicator | None, ): if helper is None: return if self.client.app_version > version.Version("4.29.0"): url = urllib.parse.urljoin(self.client.src, utils.CANCEL_URL)
# The event_id won't be set on the helper until later # so need to create the data in a function that's run at cancel time def post_data(): return { "fn_index": self.fn_index, "session_hash": self.client.session_hash, "event_id": helper.event_id, }
cancel_msg = None cancellable = True else: candidates: list[tuple[int, list[int]]] = [] for i, dep in enumerate(self.client.config["dependencies"]): if self.fn_index in dep["cancels"]: candidates.append( (i, [d for d in dep["cancels"] if d != self.fn_index]) )
fn_index, other_cancelled = ( min(candidates, key=lambda x: len(x[1])) if candidates else (None, None) ) cancellable = fn_index is not None cancel_msg = None if cancellable and other_cancelled: other_api_names = [ "/" + self.client.config["dependencies"][i].get("api_name") for i in other_cancelled ] cancel_msg = ( f"Cancelled this job will also cancel any jobs for {', '.join(other_api_names)} " "that are currently running." ) elif not cancellable: cancel_msg = ( "Cancelling this job will not stop the server from running. " "To fix this, an event must be added to the upstream app that explicitly cancels this one or " "the upstream app must be running Gradio 4.29.0 and greater." )
def post_data(): return { "data": [], "fn_index": fn_index, "session_hash": self.client.session_hash, }
url = self.client.api_url
def _cancel(): if cancel_msg: warnings.warn(cancel_msg) if cancellable: httpx.post( url, json=post_data(), headers=self.client.headers, cookies=self.client.cookies, verify=self.client.ssl_verify, )
return _cancel
def make_predict(self, helper: Communicator | None = None): def _predict(*data) -> tuple: data = { "data": data, "fn_index": self.fn_index, "session_hash": self.client.session_hash, }
hash_data = { "fn_index": self.fn_index, "session_hash": self.client.session_hash, }
if self.protocol == "sse": result = self._sse_fn_v0(data, hash_data, helper) # type: ignore elif self.protocol in ("sse_v1", "sse_v2", "sse_v2.1", "sse_v3"): event_id = self.client.send_data(data, hash_data, self.protocol) self.client.pending_event_ids.add(event_id) self.client.pending_messages_per_event[event_id] = [] helper.event_id = event_id result = self._sse_fn_v1plus(helper, event_id, self.protocol) else: raise ValueError(f"Unsupported protocol: {self.protocol}")
if "error" in result: if result["error"] is None: raise AppError( "The upstream Gradio app has raised an exception but has not enabled " "verbose error reporting. To enable, set show_error=True in launch()." ) else: raise AppError( "The upstream Gradio app has raised an exception: " + result["error"] )
try: output = result["data"] except KeyError as ke: is_public_space = ( self.client.space_id and not huggingface_hub.space_info(self.client.space_id).private ) if "error" in result and "429" in result["error"] and is_public_space: raise utils.TooManyRequestsError( f"Too many requests to the API, please try again later. To avoid being rate-limited, " f"please duplicate the Space using Client.duplicate({self.client.space_id}) " f"and pass in your Hugging Face token." ) from None elif "error" in result: raise ValueError(result["error"]) from None raise KeyError( f"Could not find 'data' key in response. Response received: {result}" ) from ke return tuple(output)
return _predict
def insert_empty_state(self, *data) -> tuple: data = list(data) for i, input_component_type in enumerate(self.input_component_types): if input_component_type.is_state: data.insert(i, None) return tuple(data)
def process_input_files(self, *data) -> tuple: data_ = [] for i, d in enumerate(data): d = utils.traverse( d, partial(self._upload_file, data_index=i), utils.is_file_obj_with_meta, ) data_.append(d) return tuple(data_)
def process_predictions(self, *predictions): # If self.download_file is True, we assume that that the user is using the Client directly (as opposed # within gr.load) and therefore, download any files generated by the server and skip values for # components that the user likely does not want to see (e.g. gr.State, gr.Tab). if self.client.download_files: predictions = self.download_files(*predictions) if self.client._skip_components: predictions = self.remove_skipped_components(*predictions) predictions = self.reduce_singleton_output(*predictions) return predictions
def download_files(self, *data) -> tuple: data_ = list(data) if self.client.protocol == "sse_v2.1": data_ = utils.traverse( data_, self._download_file, utils.is_file_obj_with_meta ) else: data_ = utils.traverse(data_, self._download_file, utils.is_file_obj) return tuple(data_)
def remove_skipped_components(self, *data) -> tuple: """""" data = [d for d, oct in zip(data, self.output_component_types) if not oct.skip] return tuple(data)
def reduce_singleton_output(self, *data) -> Any: if self.client._skip_components: effective_output_components = [ o for o in self.output_component_types if not o.skip ] else: effective_output_components = self.output_component_types if len(effective_output_components) == 1: return data[0] else: return data
def _upload_file(self, f: dict, data_index: int) -> dict[str, str]: file_path = f["path"] orig_name = Path(file_path) if not utils.is_http_url_like(file_path): component_id = self.dependency["inputs"][data_index] component_config = next( ( c for c in self.client.config["components"] if c["id"] == component_id ), {}, ) max_file_size = self.client.config.get("max_file_size", None) max_file_size = math.inf if max_file_size is None else max_file_size if os.path.getsize(file_path) > max_file_size: raise ValueError( f"File {file_path} exceeds the maximum file size of {max_file_size} bytes " f"set in {component_config.get('label', '') + ''} component." ) with open(file_path, "rb") as f: files = [("files", (orig_name.name, f))] r = httpx.post( self.client.upload_url, headers=self.client.headers, cookies=self.client.cookies, verify=self.client.ssl_verify, files=files, ) r.raise_for_status() result = r.json() file_path = result[0] # Only return orig_name if has a suffix because components # use the suffix of the original name to determine format to save it to in cache. return { "path": file_path, "orig_name": utils.strip_invalid_filename_characters(orig_name.name) if orig_name.suffix else None, }
def _download_file(self, x: dict) -> str: url_path = self.root_url + "file=" + x["path"] if self.client.output_dir is not None: os.makedirs(self.client.output_dir, exist_ok=True)
sha1 = hashlib.sha1() temp_dir = Path(tempfile.gettempdir()) / secrets.token_hex(20) temp_dir.mkdir(exist_ok=True, parents=True)
with httpx.stream( "GET", url_path, headers=self.client.headers, cookies=self.client.cookies, verify=self.client.ssl_verify, follow_redirects=True, ) as response: response.raise_for_status() with open(temp_dir / Path(url_path).name, "wb") as f: for chunk in response.iter_bytes(chunk_size=128 * sha1.block_size): sha1.update(chunk) f.write(chunk)
directory = Path(self.client.output_dir) / sha1.hexdigest() directory.mkdir(exist_ok=True, parents=True) dest = directory / Path(url_path).name shutil.move(temp_dir / Path(url_path).name, dest) return str(dest.resolve())
def _sse_fn_v0(self, data: dict, hash_data: dict, helper: Communicator): with httpx.Client( timeout=httpx.Timeout(timeout=None), verify=self.client.ssl_verify ) as client: return utils.get_pred_from_sse_v0( client, data, hash_data, helper, self.client.sse_url, self.client.sse_data_url, self.client.headers, self.client.cookies, self.client.ssl_verify, self.client.executor, )
def _sse_fn_v1plus( self, helper: Communicator, event_id: str, protocol: Literal["sse_v1", "sse_v2", "sse_v2.1", "sse_v3"], ): return utils.get_pred_from_sse_v1plus( helper, self.client.headers, self.client.cookies, self.client.pending_messages_per_event, event_id, protocol, self.client.ssl_verify, self.client.executor, )
@document("result", "outputs", "status")class Job(Future): """ A Job is a wrapper over the Future class that represents a prediction call that has been submitted by the Gradio client. This class is not meant to be instantiated directly, but rather is created by the Client.submit() method.
A Job object includes methods to get the status of the prediction call, as well to get the outputs of the prediction call. Job objects are also iterable, and can be used in a loop to get the outputs of prediction calls as they become available for generator endpoints. """
def __init__( self, future: Future, communicator: Communicator | None = None, verbose: bool = True, space_id: str | None = None, _cancel_fn: Callable[[], None] | None = None, ): """ Parameters: future: The future object that represents the prediction call, created by the Client.submit() method communicator: The communicator object that is used to communicate between the client and the background thread running the job verbose: Whether to print any status-related messages to the console space_id: The space ID corresponding to the Client object that created this Job object """ self.future = future self.communicator = communicator self._counter = 0 self.verbose = verbose self.space_id = space_id self.cancel_fn = _cancel_fn
def __iter__(self) -> Job: return self
def __next__(self) -> tuple | Any: if not self.communicator: raise StopIteration()
while True: with self.communicator.lock: if len(self.communicator.job.outputs) >= self._counter + 1: o = self.communicator.job.outputs[self._counter] self._counter += 1 return o if ( self.communicator.job.latest_status.code == Status.FINISHED and self._counter >= len(self.communicator.job.outputs) ): raise StopIteration() time.sleep(0.001)
def result(self, timeout: float | None = None) -> Any: """ Return the result of the call that the future represents. Raises CancelledError: If the future was cancelled, TimeoutError: If the future didn't finish executing before the given timeout, and Exception: If the call raised then that exception will be raised.
Parameters: timeout: The number of seconds to wait for the result if the future isn't done. If None, then there is no limit on the wait time. Returns: The result of the call that the future represents. For generator functions, it will return the final iteration. Example: from gradio_client import Client calculator = Client(src="gradio/calculator") job = calculator.submit("foo", "add", 4, fn_index=0) job.result(timeout=5) >> 9 """ return super().result(timeout=timeout)
def outputs(self) -> list[tuple | Any]: """ Returns a list containing the latest outputs from the Job.
If the endpoint has multiple output components, the list will contain a tuple of results. Otherwise, it will contain the results without storing them in tuples.
For endpoints that are queued, this list will contain the final job output even if that endpoint does not use a generator function.
Example: from gradio_client import Client client = Client(src="gradio/count_generator") job = client.submit(3, api_name="/count") while not job.done(): time.sleep(0.1) job.outputs() >> ['0', '1', '2'] """ if not self.communicator: return [] else: with self.communicator.lock: return self.communicator.job.outputs
def status(self) -> StatusUpdate: """ Returns the latest status update from the Job in the form of a StatusUpdate object, which contains the following fields: code, rank, queue_size, success, time, eta, and progress_data.
progress_data is a list of updates emitted by the gr.Progress() tracker of the event handler. Each element of the list has the following fields: index, length, unit, progress, desc. If the event handler does not have a gr.Progress() tracker, the progress_data field will be None.
Example: from gradio_client import Client client = Client(src="gradio/calculator") job = client.submit(5, "add", 4, api_name="/predict") job.status() >> <Status.STARTING: 'STARTING'> job.status().eta >> 43.241 # seconds """ time = datetime.now() cancelled = False if self.communicator: with self.communicator.lock: cancelled = self.communicator.should_cancel if cancelled: return StatusUpdate( code=Status.CANCELLED, rank=0, queue_size=None, success=False, time=time, eta=None, progress_data=None, ) if self.done(): if not self.future._exception: # type: ignore return StatusUpdate( code=Status.FINISHED, rank=0, queue_size=None, success=True, time=time, eta=None, progress_data=None, ) else: return StatusUpdate( code=Status.FINISHED, rank=0, queue_size=None, success=False, time=time, eta=None, progress_data=None, ) elif not self.communicator: return StatusUpdate( code=Status.PROCESSING, rank=0, queue_size=None, success=None, time=time, eta=None, progress_data=None, ) else: with self.communicator.lock: eta = self.communicator.job.latest_status.eta if self.verbose and self.space_id and eta and eta > 30: print( f"Due to heavy traffic on this app, the prediction will take approximately {int(eta)} seconds." f"For faster predictions without waiting in queue, you may duplicate the space using: Client.duplicate({self.space_id})" ) return self.communicator.job.latest_status
def cancel(self) -> bool: """Cancels the job as best as possible.
If the app you are connecting to has the gradio queue enabled, the job will be cancelled locally as soon as possible. For apps that do not use the queue, the job cannot be cancelled if it's been sent to the local executor (for the time being).
Note: In general, this DOES not stop the process from running in the upstream server except for the following situations:
1. If the job is queued upstream, it will be removed from the queue and the server will not run the job 2. If the job has iterative outputs, the job will finish as soon as the current iteration finishes running 3. If the job has not been picked up by the queue yet, the queue will not pick up the job """ if self.communicator: with self.communicator.lock: self.communicator.should_cancel = True if self.cancel_fn: self.cancel_fn() return True return self.future.cancel()
def __getattr__(self, name): """Forwards any properties to the Future class.""" return getattr(self.future, name).DS_Store
README.md+5-5
app.py
components/__init__.pyDeleted
components/emails/pi_redactor.pyDeleted-1
components/emails/emails.py → components/fetch_emails.pyRenamed+36-126
components/gen_ai/linkedin_bio.pyDeleted-1
components/gen_ai/notion_gen.pyDeleted-153
components/gradio/api.pyAdded+183
components/gradio/guides/get_started_guide.mdDeleted-15
components/notion/architect.py → components/llm_response.pyRenamed+48-143
components/notion/__init__.pyDeleted
components/notion/auth.pyDeleted-190
components/notion/blocks.pyDeleted-654
components/notion/notion_json.pyDeleted-6
components/notion/test_scripts/generate_content.pyDeleted-27
components/notion/test_scripts/process_page.pyDeleted-22
components/notion/test_scripts/utils.pyDeleted-164
components/supabase/__init__.pyDeleted
components/supabase/auth.pyDeleted-30
components/supabase/db.pyDeleted-146
components/supabase/storage.pyDeleted-1
components/test_scripts/fastapi.pyDeleted-13
components/test_scripts/gmail.pyDeleted-217
data/google_auth/client_secret.jsonDeleted-1
data/google_auth/client_secret_desktop.jsonDeleted-1
data/google_auth/storage.jsonDeleted-1
data/images/logo.pngDeleted
data/sample.pyAdded+35
components/storage/tables.py → data/tables.pyRenamed
gradio_client_updated.pyAdded+1638