elg
Advanced tools
| Metadata-Version: 2.1 | ||
| Name: elg | ||
| Version: 0.4.21 | ||
| Version: 0.4.22 | ||
| Summary: Use the European Language Grid in your Python projects | ||
@@ -5,0 +5,0 @@ Home-page: https://gitlab.com/european-language-grid/platform/python-client |
+1
-1
@@ -1,2 +0,2 @@ | ||
| __version__ = "0.4.21" | ||
| __version__ = "0.4.22" | ||
@@ -3,0 +3,0 @@ import importlib.util |
@@ -360,2 +360,5 @@ import inspect | ||
| ), | ||
| caching=f"""RUN ["venv/bin/python", "-c", "from {service_script} import app"] | ||
| ENV TRANSFORMERS_OFFLINE=1 | ||
| """, | ||
| ) | ||
@@ -362,0 +365,0 @@ ) |
@@ -19,3 +19,3 @@ from .StatusMessage import StatusMessage | ||
| """Generate StatusMessage for code: elg.request.invalid""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -31,3 +31,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.request.missing""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -43,3 +43,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.request.type.unsupported""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -55,3 +55,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.request.property.unsupported""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -67,3 +67,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.request.too.large""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -77,5 +77,27 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| @classmethod | ||
| def generate_elg_request_parameter_missing(cls, params=[], detail={}, **kwargs): | ||
| """Generate StatusMessage for code: elg.request.parameter.missing""" | ||
| if "lang" in kwargs: | ||
| print( | ||
| "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| ) | ||
| code = "elg.request.parameter.missing" | ||
| text = "Required parameter {0} missing from request" | ||
| return StatusMessage(code=code, text=text, params=params, detail=detail) | ||
| @classmethod | ||
| def generate_elg_request_parameter_invalid(cls, params=[], detail={}, **kwargs): | ||
| """Generate StatusMessage for code: elg.request.parameter.invalid""" | ||
| if "lang" in kwargs: | ||
| print( | ||
| "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| ) | ||
| code = "elg.request.parameter.invalid" | ||
| text = 'Value "{1}" is not valid for parameter {0}' | ||
| return StatusMessage(code=code, text=text, params=params, detail=detail) | ||
| @classmethod | ||
| def generate_elg_request_text_mimetype_unsupported(cls, params=[], detail={}, **kwargs): | ||
| """Generate StatusMessage for code: elg.request.text.mimeType.unsupported""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -91,3 +113,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.request.audio.format.unsupported""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -103,3 +125,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.request.audio.sampleRate.unsupported""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -115,3 +137,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.request.image.format.unsupported""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -127,3 +149,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.request.structuredText.property.unsupported""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -139,3 +161,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.response.invalid""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -151,3 +173,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.response.type.unsupported""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -163,3 +185,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.response.property.unsupported""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -175,3 +197,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.response.texts.property.unsupported""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -187,3 +209,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.response.classification.property.unsupported""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -199,3 +221,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.service.not.found""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -211,3 +233,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.async.call.not.found""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -223,3 +245,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.permissions.quotaExceeded""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -235,3 +257,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.permissions.accessDenied""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -247,3 +269,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.permissions.accessManagerError""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -259,3 +281,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.file.not.found""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -271,3 +293,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.file.expired""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -283,3 +305,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.upload.too.large""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -295,3 +317,3 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." | ||
| """Generate StatusMessage for code: elg.service.internalError""" | ||
| if "lang" in kwargs.keys(): | ||
| if "lang" in kwargs: | ||
| print( | ||
@@ -298,0 +320,0 @@ "Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language." |
@@ -104,2 +104,9 @@ from collections.abc import AsyncIterable, Iterable | ||
| @classmethod | ||
| def from_auto_content(cls, content: Any): | ||
| if isinstance(content, dict): | ||
| return cls(**content) | ||
| else: | ||
| raise ValueError(f"The AudioRequest message cannot be initialize from {content}") | ||
| def __str__(self): | ||
@@ -106,0 +113,0 @@ return " - ".join( |
@@ -82,1 +82,10 @@ from typing import Any, Dict, List | ||
| """*(required)* the actual text object with the text content""" | ||
| @classmethod | ||
| def from_auto_content(cls, content: Any): | ||
| if isinstance(content, list): | ||
| return cls(texts=content) | ||
| elif isinstance(content, dict): | ||
| return cls(texts=[Text(**content)]) | ||
| else: | ||
| raise ValueError(f"The StructuredTextRequest message cannot be initialize from {content}") |
| from pathlib import Path | ||
| from typing import Dict, List | ||
| from typing import Any, Dict, List | ||
@@ -46,1 +46,10 @@ from .. import Annotation, Request | ||
| return cls(content=content, features=features, annotations=annotations, params=params) | ||
| @classmethod | ||
| def from_auto_content(cls, content: Any): | ||
| if isinstance(content, str): | ||
| return cls(content=content) | ||
| elif isinstance(content, dict): | ||
| return cls(**content) | ||
| else: | ||
| raise ValueError(f"The TextRequest message cannot be initialize from {content}") |
@@ -78,3 +78,3 @@ from numbers import Number | ||
| if len(self.texts) == 1: | ||
| return self.texts[0] | ||
| return self.texts[0].auto_content() | ||
| return self.texts | ||
@@ -81,0 +81,0 @@ |
+16
-3
@@ -5,3 +5,3 @@ from typing import Callable, List, Union | ||
| from .entity import Entity | ||
| from .model import Request | ||
| from .model import AudioRequest, Request, StructuredTextRequest, TextRequest | ||
| from .service import Service | ||
@@ -179,7 +179,20 @@ | ||
| assert len(self.services) == len(request_types) | ||
| assert len(self.services) == len(output_funcs) | ||
| result = request_input | ||
| results = [] | ||
| for service, request_type, output_func in zip(self.services, request_types, output_funcs): | ||
| for idx, (service, request_type, output_func) in enumerate(zip(self.services, request_types, output_funcs)): | ||
| if request_type == "text": | ||
| request_input = TextRequest.from_auto_content(result) | ||
| elif request_type == "structuredText": | ||
| request_input = StructuredTextRequest.from_auto_content(result) | ||
| elif request_type == "audio": | ||
| request_input = AudioRequest.from_auto_content(result) | ||
| else: | ||
| raise ValueError("request type does not support by the Pipeline class.") | ||
| if idx == len(self.services) - 1: | ||
| output_func = lambda response: response | ||
| result = service( | ||
| request_input=result, | ||
| request_input=request_input, | ||
| request_type=request_type, | ||
@@ -186,0 +199,0 @@ sync_mode=sync_mode, |
+16
-1
@@ -588,3 +588,3 @@ import inspect | ||
| path = Path(path) | ||
| required_files = [path.name] + required_files | ||
| required_files = [path.name] + ["prepare.py"] + required_files | ||
| required_folders = "\n".join( | ||
@@ -600,2 +600,14 @@ [COPY_FOLDER.format(folder_name=str(Path(folder))) for folder in required_folders] | ||
| f.write(ENTRYPOINT_QUART.format(service_script=service_script).encode("utf-8")) | ||
| with open(path.parent / "prepare.py", "w") as f: | ||
| f.write( | ||
| f"""import asyncio | ||
| async def prepare(): | ||
| from {service_script} import app | ||
| await app.startup() | ||
| await app.shutdown() | ||
| asyncio.run(prepare()) | ||
| """ | ||
| ) | ||
| with open(path.parent / "Dockerfile", "w") as f: | ||
@@ -609,2 +621,5 @@ f.write( | ||
| env=ENV_QUART.format(log_level=log_level), | ||
| caching=f"""RUN ["venv/bin/python", "prepare.py"] | ||
| ENV TRANSFORMERS_OFFLINE=1 | ||
| """, | ||
| ) | ||
@@ -611,0 +626,0 @@ ) |
+2
-26
@@ -380,3 +380,3 @@ import hashlib | ||
| a list of texts, or directly a Request object. | ||
| request_type (str, optional): precise the type of the request. Can be "text", "structuredText", "audio", or "audioStream". | ||
| request_type (str, optional): precise the type of the request. Can be "text", "structuredText", "audio", "audioStream", "image", or "imageStream". | ||
| It is only used if request_input is not a Request object. Defaults to "text". | ||
@@ -456,27 +456,3 @@ sync_mode (bool, optional): True to use the sync_mode. Defaults to False. | ||
| post_kwargs = {} | ||
| # self.id == 0 corresponds to a service initialized from a docker image | ||
| if isinstance(request, AudioRequest) and self.id == 0: | ||
| files = { | ||
| "request": ( | ||
| None, | ||
| json.dumps( | ||
| { | ||
| "type": "audio", | ||
| "format": request.format, | ||
| "sampleRate": request.sample_rate, | ||
| "features": request.features, | ||
| "annotations": request.annotations, | ||
| } | ||
| ), | ||
| "application/json", | ||
| ), | ||
| "content": ( | ||
| None, | ||
| request.content, | ||
| "audio/x-wav" if request.format == "LINEAR16" else "audio/mpeg", | ||
| ), | ||
| } | ||
| data = None | ||
| post_kwargs = {"files": files} | ||
| elif isinstance(request, AudioRequest): | ||
| if isinstance(request, AudioRequest): | ||
| data = request.content if request.content else request.generator | ||
@@ -483,0 +459,0 @@ post_kwargs["params"] = request.params |
@@ -23,2 +23,11 @@ import json | ||
| def stringliteral(v): | ||
| """Prefer double quoted string (json style) unless the string contains any double quotes.""" | ||
| if '"' in str(v): | ||
| return repr(v) | ||
| else: | ||
| return json.dumps(v) | ||
| with open("elg/model/base/StandardMessages.py", "w+") as file: | ||
@@ -29,7 +38,7 @@ file.write("from .StatusMessage import StatusMessage\n\n") | ||
| '\n """\n' | ||
| + " This class provides easy access to the standard set of ELG status messages that are provided by default by \n" | ||
| + " the platform and should be fully translated in the ELG user interface. If you use codes other than these \n" | ||
| + " standard ones in your services then you should also try to contribute translations of your messages into as \n" | ||
| + " This class provides easy access to the standard set of ELG status messages that are provided by default by\n" | ||
| + " the platform and should be fully translated in the ELG user interface. If you use codes other than these\n" | ||
| + " standard ones in your services then you should also try to contribute translations of your messages into as\n" | ||
| + " many languages as possible for the benefit of other ELG users.\n\n" | ||
| " Implementation note: This class is auto-generated from elg-messages.properties - to add new message codes you \n" | ||
| + " Implementation note: This class is auto-generated from elg-messages.properties - to add new message codes you\n" | ||
| + " should edit the property files, then run /utils/generate_standard_messages.py. Do not edit this class directly.\n" | ||
@@ -42,9 +51,11 @@ + ' """\n' | ||
| file.write('\n """Generate StatusMessage for code: ' + key + '"""') | ||
| file.write('\n if "lang" in kwargs.keys():') | ||
| file.write('\n if "lang" in kwargs:') | ||
| file.write("\n print(") | ||
| file.write( | ||
| """\n print("Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language.")""" | ||
| "\n \"Warning: lang is deprecated and will be ignored. The standard message 'text' will be in English, pass it to the i18n resolver to obtain it in another language.\"" | ||
| ) | ||
| file.write("\n code=" + repr(key)) | ||
| file.write("\n text=" + repr(details[key])) | ||
| file.write("\n return StatusMessage(code=code,text=text,params=params,detail=detail)") | ||
| file.write("\n )") | ||
| file.write("\n code = " + stringliteral(key)) | ||
| file.write("\n text = " + stringliteral(details[key])) | ||
| file.write("\n return StatusMessage(code=code, text=text, params=params, detail=detail)") | ||
| file.write("\n") |
@@ -47,2 +47,4 @@ ENTRYPOINT_FLASK = """\ | ||
| {caching} | ||
| RUN chmod +x ./docker-entrypoint.sh | ||
@@ -49,0 +51,0 @@ ENTRYPOINT ["./docker-entrypoint.sh"]\ |
+1
-1
| Metadata-Version: 2.1 | ||
| Name: elg | ||
| Version: 0.4.21 | ||
| Version: 0.4.22 | ||
| Summary: Use the European Language Grid in your Python projects | ||
@@ -5,0 +5,0 @@ Home-page: https://gitlab.com/european-language-grid/platform/python-client |
+1
-1
@@ -5,3 +5,3 @@ from setuptools import find_packages, setup | ||
| name="elg", | ||
| version="0.4.21", | ||
| version="0.4.22", | ||
| author="ELG Technical Team", | ||
@@ -8,0 +8,0 @@ url="https://gitlab.com/european-language-grid/platform/python-client", |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
322717
0.82%7339
0.76%