darisdzakwanhoesien commited on
Commit
3b422ad
·
verified ·
1 Parent(s): 7fec0e0

Update models/qa.py

Browse files
Files changed (1) hide show
  1. models/qa.py +19 -0
models/qa.py CHANGED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # models/qa.py
2
+
3
+ from typing import Dict, Any
4
+ from models.utils import create_pipeline
5
+
6
+ AVAILABLE_MODELS = {
7
+ "indobert-qa": "indobenchmark/indobert-base-p1",
8
+ }
9
+
10
+
11
+ def predict(context: str, question: str, model_key: str) -> Dict[str, Any]:
12
+ model_id = AVAILABLE_MODELS.get(model_key)
13
+ if model_id is None:
14
+ raise ValueError(f"Unknown QA model key: {model_key}")
15
+ p, err = create_pipeline("question-answering", model_id)
16
+ if err:
17
+ raise RuntimeError(err)
18
+ out = p(question=question, context=context)
19
+ return out