Replaces placeholders such as {image_processor_class} in the docstring with the actual values, deducted from the model name and the auto modules.
(docstring: str, model_name: str)
| 2832 | |
| 2833 | |
| 2834 | def format_args_docstring(docstring: str, model_name: str) -> str: |
| 2835 | """ |
| 2836 | Replaces placeholders such as {image_processor_class} in the docstring with the actual values, |
| 2837 | deducted from the model name and the auto modules. |
| 2838 | """ |
| 2839 | # first check if there are any placeholders in the docstring, if not return it as is |
| 2840 | placeholders = set(_re_placeholders.findall(docstring)) |
| 2841 | if not placeholders: |
| 2842 | return docstring |
| 2843 | |
| 2844 | # get the placeholders dictionary for the given model name |
| 2845 | placeholders_dict = get_placeholders_dict(placeholders, model_name) |
| 2846 | # replace the placeholders in the docstring with the values from the placeholders_dict |
| 2847 | for placeholder, value in placeholders_dict.items(): |
| 2848 | if isinstance(value, dict) and placeholder == "image_processor_class": |
| 2849 | value = value.get("torchvision", value.get("pil", None)) |
| 2850 | if placeholder is not None: |
| 2851 | docstring = docstring.replace(f"{{{placeholder}}}", value) |
| 2852 | return docstring |
| 2853 | |
| 2854 | |
| 2855 | def get_args_doc_from_source(args_classes: object | list[object]) -> dict: |
no test coverage detected