Download run.py from aiflows/HumanStandardInputFlowModule: direct link, hf CLI and curl.
- Browser
- Download file 3.02 kB
-
https://huggingface.co/aiflows/HumanStandardInputFlowModule/resolve/43c0f718b92d9b8d2be8193dfd64d150211344a9/run.py
- Command line
-
hf download hf://aiflows/HumanStandardInputFlowModule@43c0f718b92d9b8d2be8193dfd64d150211344a9/run.py
-
curl -L -o run.py https://huggingface.co/aiflows/HumanStandardInputFlowModule/resolve/43c0f718b92d9b8d2be8193dfd64d150211344a9/run.py
3.02 kB
| import os | |
| import hydra | |
| import aiflows | |
| from aiflows.flow_launchers import FlowLauncher | |
| from aiflows.backends.api_info import ApiInfo | |
| from aiflows.utils.general_helpers import read_yaml_file | |
| from aiflows import logging | |
| from aiflows.flow_cache import CACHING_PARAMETERS, clear_cache | |
| from aiflows.utils import serve_utils | |
| from aiflows.workers import run_dispatch_worker_thread | |
| from aiflows.messages import FlowMessage | |
| from aiflows.interfaces import KeyInterface | |
| from aiflows.utils.colink_utils import start_colink_server | |
| from aiflows.workers import run_dispatch_worker_thread | |
| CACHING_PARAMETERS.do_caching = False # Set to True in order to disable caching | |
| # clear_cache() # Uncomment this line to clear the cache | |
| logging.set_verbosity_debug() | |
| dependencies = [ | |
| {"url": "aiflows/HumanStandardInputFlowModule", "revision": os.getcwd()}, | |
| ] | |
| from aiflows import flow_verse | |
| flow_verse.sync_dependencies(dependencies) | |
| if __name__ == "__main__": | |
| #1. ~~~~~ Set up a colink server ~~~~ | |
| FLOW_MODULES_PATH = "./" | |
| cl = start_colink_server() | |
| #2. ~~~~~Load flow config~~~~~~ | |
| root_dir = "." | |
| cfg_path = os.path.join(root_dir, "demo.yaml") | |
| cfg = read_yaml_file(cfg_path) | |
| #3. ~~~~ Serve The Flow ~~~~ | |
| serve_utils.serve_flow( | |
| cl = cl, | |
| flow_type="HumanStandardInputFlowModule", | |
| default_config=cfg, | |
| default_state=None, | |
| default_dispatch_point="coflows_dispatch" | |
| ) | |
| #4. ~~~~~Start A Worker Thread~~~~~ | |
| run_dispatch_worker_thread(cl, dispatch_point="coflows_dispatch", flow_modules_base_path=FLOW_MODULES_PATH) | |
| #5. ~~~~~Mount the flow and get its proxy~~~~~~ | |
| proxy_flow = serve_utils.recursive_mount( | |
| cl=cl, | |
| client_id="local", | |
| flow_type="HumanStandardInputFlowModule", | |
| config_overrides=None, | |
| initial_state=None, | |
| dispatch_point_override=None, | |
| ) | |
| #6. ~~~ Get the data ~~~ | |
| data = {"id": 0, "statement": "This flow works well"} # This can be a list of samples | |
| # data = {"id": 0, "question": "Who was the NBA champion in 2023?"} # This can be a list of samples | |
| #option1: use the FlowMessage class | |
| input_message = FlowMessage( | |
| data=data, | |
| ) | |
| #option2: use the proxy_flow | |
| #input_message = proxy_flow._package_input_message(data = data) | |
| #7. ~~~ Run inference ~~~ | |
| future = proxy_flow.send_message_blocking(input_message) | |
| #uncomment this line if you would like to get the full message back | |
| #reply_message = future.get_message() | |
| reply_data = future.get_data() | |
| # ~~~ Print the output ~~~ | |
| print("~~~~~~Reply~~~~~~") | |
| print(reply_data) | |
| #8. ~~~~ (Optional) apply output interface on reply ~~~~ | |
| # output_interface = KeyInterface( | |
| # keys_to_rename={"api_output": "answer"}, | |
| # ) | |
| # print("Output: ", output_interface(reply_data)) | |
| #9. ~~~~~Optional: Unserve Flow~~~~~~ | |
| # serve_utils.delete_served_flow(cl, "ReverseNumberAtomicFlow_served") |