{"text": "from taipy.core.config import Config, Scope, Frequency import taipy as tp import datetime as dt import pandas as pd import time Config.load('config_09.toml') Config.configure_job_executions(mode=\"standalone\", max_nb_of_workers=2) def filter_by_month(df, month): df['Date'] = pd.to_datetime(df['Date']) df = df[df['Date'].dt.month == month] return df def count_values(df): print(\"Wait 10 seconds\") time.sleep(10) return len(df) def callback_scenario_state(scenario, job): \"\"\"All the scenarios are subscribed to the callback_scenario_state function. It means whenever a job is done, it is called. Depending on the job and the status, it will update the message stored in a json that is then displayed on the GUI. Args: scenario (Scenario): the scenario of the job changed job (_type_): the job that has its status changed \"\"\" print(scenario.name) if job.status.value == 7: for data_node in job.task.output.values(): print(data_node.read()) if __name__==\"__main__\": # my_scenario is the id of the scenario configured scenario_cfg = Config.scenarios['my_scenario'] tp.Core().run() scenario_1 = tp.create_scenario(scenario_cfg, creation_date=dt.datetime(2022,10,7), name=\"Scenario 2022/10/7\") scenario_1.subscribe(callback_scenario_state) scenario_1.submit(wait=True) scenario_1.submit(wait=True, timeout=5)"} {"text": "from taipy import Config import taipy as tp def double(nb): return nb * 2 Config.load('config_02.toml') if __name__ == '__main__': # my_scenario is the id of the scenario configured scenario_cfg = Config.scenarios['my_scenario'] scenario = tp.create_scenario(scenario_cfg, name=\"Scenario\") tp.submit(scenario) print(\"Output of First submit:\", scenario.output.read()) print(\"Before write\", scenario.input.read()) scenario.input.write(54) print(\"After write\",scenario.input.read()) tp.submit(scenario) print(\"Second submit\",scenario.output.read()) # Basic functions of Taipy Core print([s.name for s in tp.get_scenarios()]) scenario = tp.get(scenario.id) tp.delete(scenario.id) scenario = None data_node = None tp.Gui(\"\"\"<|{scenario}|scenario_selector|> <|{scenario}|scenario|> <|{scenario}|scenario_dag|> <|{data_node}|data_node_selector|>\"\"\").run() "} {"text": "from taipy.core.config import Config import taipy as tp import datetime as dt import pandas as pd def filter_current(df): current_month = dt.datetime.now().month df['Date'] = pd.to_datetime(df['Date']) df = df[df['Date'].dt.month == current_month] return df def count_values(df): return len(df) Config.load('config_03.toml') if __name__ == '__main__': # my_scenario is the id of the scenario configured scenario_cfg = Config.scenarios['my_scenario'] tp.Core().run() scenario = tp.create_scenario(scenario_cfg, creation_date=dt.datetime(2022,10,7), name=\"Scenario 2022/10/7\") scenario.submit() print(\"Nb of values of scenario:\", scenario.nb_of_values.read()) data_node = None tp.Gui(\"\"\"<|{scenario}|scenario_selector|> <|{scenario}|scenario|> <|{scenario}|scenario_dag|> <|{data_node}|data_node_selector|>\"\"\").run() "} {"text": "from importlib import util, import_module from pathlib import Path import sys import inspect import os import json if len(sys.argv) < 3: print(\"Packages should be passed as arguments after the name of the searched file.\", file=sys.stderr) exit(1) else: errors = 0 file_name = sys.argv[1] result = dict() exit_code = 1 for package in sys.argv[2:]: parts = package.split(\".\") package_found = True for idx in range(len(parts)): if not util.find_spec(\".\".join(parts[0: idx+1])): package_found = False break if not package_found: print(f\"Package {package} not found.\", file=sys.stderr) errors += 1 else: module = import_module(package) found = False try: module_file = inspect.getfile(module) for root, dirs, files in os.walk(Path(module_file).parent.resolve()): root_path = Path(root) if file_name in files: result[package] = str((root_path / file_name).resolve()) found = True except Exception as e: print(f\"Error accessing {package}: {e}.\", file=sys.stderr) exit_code += 1 if not found: print(f\"File {file_name} not found in Package {package}.\", file=sys.stderr) errors += 1 if len(result): json.dump(result, sys.stdout) elif errors: exit(exit_code) "} {"text": "from taipy import Gui import cv2 face_cascade = cv2.CascadeClassifier(\"haarcascade_frontalface_default.xml\") number_of_faces_detected = 0 selected_file = None image = None def process_image(state): img = cv2.imread(state.selected_file, cv2.IMREAD_UNCHANGED) gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray) state.number_of_faces_detected = len(faces) # Draw a rectangle around faces for (x, y, w, h) in faces: cv2.rectangle(img, (x, y), (x + w, y + h), (255, 255, 0), 2) state.image = cv2.imencode(\".jpg\", img)[1].tobytes() content = \"\"\" <|{selected_file}|file_selector|label=Upload File|on_action=process_image|extensions=.jpg,.gif,.png|drop_message=Drop Message|> <|{image}|image|width=300px|height=300px|> <|{number_of_faces_detected} face(s) detected|> \"\"\" if __name__ == \"__main__\": Gui(page=content).run(dark_mode=False, port=8080) "} {"text": "from setuptools import find_packages, setup setup( author=\"You Name\", author_email=\"your@email.domain\", python_requires=\">=3.8\", classifiers=[ \"Intended Audience :: Developers\", # \"License :: OSI Approved :: Apache Software License\", \"Natural Language :: English\", \"Programming Language :: Python :: 3\", \"Programming Language :: Python :: 3.8\", \"Programming Language :: Python :: 3.9\", \"Programming Language :: Python :: 3.10\", ], # license=\"Apache License 2.0\", install_requires=[\"taipy-gui>=2.0\"], include_package_data=True, name=\"guiext-library\", description=\"My taipy-gui extension demo\", long_description=\"This package contains a demonstration of using the Taipy GUI Extension API.\", keywords=\"taipy\", packages=find_packages(include=[\"demo_lib\", \"demo_lib.*\"]), version=\"1.0.0\", zip_safe=False ) "} {"text": "from taipy.gui import Gui from library import Library page = \"\"\" # Extension library <|library.element|> \"\"\" gui = Gui(page=page) gui.add_library(Library()) if __name__ == \"__main__\": # Run main app gui.run() "} {"text": "from pathlib import Path from taipy.gui.extension import ElementLibrary, Element, ElementProperty, PropertyType class Library(ElementLibrary): elts = { # Declare the elements of the library here, as key/value pairs of # a dictionary. # - The key is used as the element name. # - The value must be an instance of taipy.gui.extension.Element # # Ex: # \"element_name\": Element( # \"default_property_name\" # { # \"property_name\": ElementProperty(...) # }, # react_component=\"ElementComponent\" # ), } def get_name(self) -> str: return \"library\" def get_elements(self) -> dict: return Library.elts def get_scripts(self) -> list[str]: # Only one JavaScript bundle for this library. return [\"library/frontend/dist/library.js\"] def get_resource(self, name: str) -> Path: return super().get_resource(name) "} {"text": "# Export the library class for easier access by developers using it from .library import Library "} {"text": "#Import modules import taipy as tp from taipy import Config, Scope, Gui import pandas as pd import numpy as np #Back-End Code #Filter function for best/worst colleges within 1 stat def filtering_college(initial_dataset: pd.DataFrame, selected_stat, ): completed_graph_dataset = initial_dataset[selected_stat] completed_graph_data = completed_graph_dataset.nlargest(10, selected_stat, keep = \"all\") return completed_graph_data #Data Node Creation initial_dataset_cfg = Config.configure_data_node(id=\"initial_dataset\",storage_type=\"csv\",path=\"College_Data.csv\",scope=Scope.GLOBAL) selected_stat_cfg = Config.configure_data_node(id = \"selected_stat\", default_data = \"Name\", slope = Scope.GLOBAL) completed_graph_data_cfg = Config.configure_data_node(id=\"completed_graph_data\", scope=Scope.GLOBAL) #Task Creation filtered_college_cfg = Config.configure_task(id = \"filtered_college\", function=filtering_college, input = [initial_dataset_cfg, selected_stat_cfg], output = [completed_graph_data_cfg]) #Pipeline Creation pipeline_cfg = Config.configure_scenario(id=\"pipeline\",task_configs=[filtered_college_cfg]) #Scenario Creation scenario_cfg = Config.configure_scenario(id = \"scenario\", pipeline_configs = [pipeline_cfg]) #scenario = tp.create_scenario(scenario_cfg) #Core creation if __name__ == \"__main__\": tp.Core().run() #Start of Front-End Code #Callback Function def modify_df(state): scenario.selected_node.write(state.selected_stat) tp.submit(scenario) state.df = scenario.completed_graph_data_cfg.read() list_stats = [\"Name\",\"Private\",\"Apps\",\"Accept\",\"Enroll\",\"Top10perc\",\"Top25perc\",\"F.Undergrad\",\"P.Undergrad\",\"Outstate\",\"Room.Board\",\"Books\",\"Personal\",\"PhD\",\"Terminal\",\"S.F.Ratio\",\"perc.alumni\",\"Expend\",\"Grad.Rate\"] selected_stat = \"Top10perc\" df = pd.DataFrame(columns = [\"Name\", selected_stat], copy = True) #Variable Instantiation #App Creation college_stat_app = \"\"\"<|{selected_stat}|selector|lov={list_stats}|on_change=modify_df|dropdown|> <|{df}|chart|x=Name|y=selected_stat|type=bar|title=College Stats|>\"\"\" #Runs the app (finally) print(selected_stat) Gui(page = college_stat_app).run() "} {"text": "import json def add_line(source, line, step): line = line.replace('Getting Started with Taipy GUI', 'Getting Started with Taipy GUI on Notebooks') line = line.replace('(../src/', '(https://docs.taipy.io/en/latest/getting_started/src/') if line.startswith('[1].split(')')[0] width = line.split('](')[1].split(')')[1].split(' ')[1] source.append('
Click here to return to home page
{table}