File size: 687 Bytes
1f399b4
 
 
 
 
 
062350e
 
22e7347
 
 
1f399b4
 
 
 
 
 
 
 
 
 
bce1ca2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from typing import List, Dict
from flair.models.language_model import LanguageModel


class PreTrainedPipeline:
    def __init__(self, path=""):
        from huggingface_hub import hf_hub_download

        self.model = LanguageModel.load_language_model(
            hf_hub_download(repo_id="dchaplinsky/flair-uk-forward", filename="best-lm.pt")
        )

    def __call__(self, inputs: str) -> List[Dict]:
        """
        Args:
            inputs (:obj:`str`):
                a string containing some text
        Return:
            A :obj:`str`
        """
        inputs = inputs.strip()
        return [{"generated_text": self.model.generate_text(inputs, temperature=0.5)[0]}]