Spaces:
Runtime error
Runtime error
| # pylint: disable=no-name-in-module | |
| # pylint: disable=no-member | |
| """ | |
| Author : Bastien GUILLAUME | |
| Version : 0.0.1 | |
| Date : 2023-03-16 | |
| Title : Inference With Gradio running an onnxruntime backend | |
| """ | |
| import json | |
| import logging | |
| import os | |
| from functools import reduce | |
| from jsonschema import validate | |
| logging.basicConfig( | |
| format="%(asctime)s.%(msecs)03d %(levelname)-8s [%(filename)s:%(lineno)s - %(funcName)20s() ] - %(message)s", | |
| level=logging.INFO, | |
| datefmt="%Y%m%d-%H%M%S", | |
| ) | |
| schema = { | |
| "definitions": {}, | |
| "type": "string", | |
| "properties": { | |
| "title": {"type": "string"}, | |
| "description": {"type": "string"}, | |
| "tasks": { | |
| "type": "object", | |
| "properties": { | |
| "tasks": {"type": "object"}, | |
| "properties": { | |
| "shortname": {"type": "string"}, | |
| "name": {"type": "object"}, | |
| # "description": {"type": "string"}, | |
| "products": {"type": "array"}, | |
| "models": {"type": "object"}, | |
| }, | |
| "additionalProperties": True, | |
| }, | |
| }, | |
| }, | |
| "additionalProperties": True, | |
| } | |
| with open("config_file/demo_yvesrocher.json") as config_file: | |
| config = json.load(config_file) | |
| print(type(config["tasks"]["task1"]["description"])) | |
| validate(json.dumps(config), schema) | |
| logging.log(level=logging.DEBUG, msg=f"Loaded config file : {json.dumps(config)}") | |
| def deep_get(dictionary, keys, default=None): | |
| return reduce( | |
| lambda d, key: d.get(key, default) if isinstance(d, dict) else default, | |
| keys.split("."), | |
| dictionary, | |
| ) | |
| def get_tasks(): | |
| tasks = [] | |
| for task in config["tasks"].keys(): | |
| tasks.append(config["tasks"][task]["name"]["fr"]) | |
| return tasks | |
| def get_tasks_name(): | |
| tasks_name = [] | |
| for task in config["tasks"].keys(): | |
| tasks_name.append(config["tasks"][task]["shortname"]) | |
| return tasks_name | |
| def get_tasks_description(): | |
| tasks_descripion = [] | |
| for task in config["tasks"].keys(): | |
| tasks_descripion.append(config["tasks"][task]["description"]["fr"]) | |
| return tasks_descripion | |
| def get_tasks_products(): | |
| tasks_products = [] | |
| for task in config["tasks"].keys(): | |
| tasks_products.append(config["tasks"][task]["products"]) | |
| return tasks_products | |
| title = ( | |
| os.getenv("GRADIO_TITLE") | |
| if "GRADIO_TITLE" in os.environ | |
| else config.get("title", "TITLE neither set in config file nor in ENV") | |
| ) | |
| description = ( | |
| os.getenv("GRADIO_DESCRIPTION") | |
| if "GRADIO_DESCRIPTION" in os.environ | |
| else config.get("description", "DESCRIPTION neither set in config file nor in ENV") | |
| ) | |
| tasks = get_tasks() | |
| tasks_name = get_tasks_name() | |
| tasks_description = get_tasks_description() | |
| tasks_products = get_tasks_products() | |
| logging.log(level=logging.INFO, msg=f"Parsed Data :") | |
| logging.log(level=logging.INFO, msg=f"Title : {title}") | |
| logging.log(level=logging.INFO, msg=f"Description : {description}") | |
| logging.log(level=logging.INFO, msg=f"Tasks : {tasks}") | |
| logging.log(level=logging.INFO, msg=f"Tasks name : {tasks_name}") | |
| logging.log(level=logging.INFO, msg=f"Tasks descrption : {tasks_description}") | |
| logging.log(level=logging.INFO, msg=f"Tasks products : {tasks_products}") | |
| logging.log(level=logging.INFO, msg=f"End of Parsed Data\n") |