Spaces:
Build error
Build error
Download twNLP-app/src/utils/text/textsubscript.py from lowannann/assignment_1: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/spaces/lowannann/assignment_1/resolve/main/twNLP-app/src/utils/text/textsubscript.py
- Command line
-
hf download hf://spaces/lowannann/assignment_1/twNLP-app/src/utils/text/textsubscript.py
-
curl -L -o textsubscript.py https://huggingface.co/spaces/lowannann/assignment_1/resolve/main/twNLP-app/src/utils/text/textsubscript.py
1.24 kB
| import asyncio | |
| from itertools import chain | |
| from typing import List, Union | |
| from .text_color import create_pos_color | |
| async def add_pos_textsubscript(data_list: List[str]) -> str: | |
| create = ( | |
| lambda value: f"""<span>{value[0]}<sub style='margin-right: 0.7rem; color: {create_pos_color(value[1])};'>({value[1]})</sub></span>""" | |
| ) | |
| return "".join(list(map(create, data_list))) | |
| async def add_ws_textsubscript(data_list: List[str]) -> str: | |
| create = lambda value: f"<span style='margin-right: 1rem'>{value}</span>" | |
| return "".join(list(map(create, data_list))) | |
| async def add_cwn_textsubscript(segmented_list) -> str: | |
| create = ( | |
| lambda value: f"<span>{value[0]}<sub style='margin-right: 1rem; color: {create_pos_color(value[1])};'>{value[1]}</sub></span>" | |
| ) | |
| return "".join(list(map(create, chain(*segmented_list)))) | |
| async def add_multiple_textsubscripts( | |
| target: str, list_of_lists: List[List[Union[str, tuple]]] | |
| ) -> List[str]: | |
| textsubscript_factories = { | |
| "ws": add_ws_textsubscript, | |
| "pos": add_pos_textsubscript, | |
| "cwn": add_cwn_textsubscript, | |
| } | |
| return await asyncio.gather( | |
| *list(map(textsubscript_factories[target], list_of_lists)) | |
| ) | |