Upload api.py with huggingface_hub
Browse files
api.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from typing import Any, Dict, List, Union
|
2 |
|
3 |
from datasets import DatasetDict
|
@@ -28,3 +29,18 @@ def load_dataset(dataset_query: str) -> DatasetDict:
|
|
28 |
|
29 |
def evaluate(predictions, data) -> List[Dict[str, Any]]:
|
30 |
return _compute(predictions=predictions, references=data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from functools import lru_cache
|
2 |
from typing import Any, Dict, List, Union
|
3 |
|
4 |
from datasets import DatasetDict
|
|
|
29 |
|
30 |
def evaluate(predictions, data) -> List[Dict[str, Any]]:
|
31 |
return _compute(predictions=predictions, references=data)
|
32 |
+
|
33 |
+
|
34 |
+
@lru_cache
|
35 |
+
def _get_produce_with_cache(recipe_query):
|
36 |
+
return get_dataset_artifact(recipe_query).produce
|
37 |
+
|
38 |
+
|
39 |
+
def produce(instance_or_instances, recipe_query):
|
40 |
+
is_list = isinstance(instance_or_instances, list)
|
41 |
+
if not is_list:
|
42 |
+
instance_or_instances = [instance_or_instances]
|
43 |
+
result = _get_produce_with_cache(recipe_query)(instance_or_instances)
|
44 |
+
if not is_list:
|
45 |
+
result = result[0]
|
46 |
+
return result
|