Spaces:
Sleeping
Sleeping
Update models/summarization.py
Browse files- models/summarization.py +21 -0
models/summarization.py
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# models/summarization.py
|
| 2 |
+
from typing import Any
|
| 3 |
+
from models.utils import create_pipeline
|
| 4 |
+
|
| 5 |
+
AVAILABLE_MODELS = {
|
| 6 |
+
# small/medium indonesian summarization model (placeholder)
|
| 7 |
+
"indobart": "cahya/indobart-large",
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def predict(text: str, model_key: str) -> str:
|
| 12 |
+
model_id = AVAILABLE_MODELS.get(model_key)
|
| 13 |
+
if model_id is None:
|
| 14 |
+
raise ValueError(f"Unknown summarization model key: {model_key}")
|
| 15 |
+
p, err = create_pipeline("summarization", model_id)
|
| 16 |
+
if err:
|
| 17 |
+
raise RuntimeError(err)
|
| 18 |
+
out = p(text, max_length=200, min_length=30)
|
| 19 |
+
if isinstance(out, list) and out:
|
| 20 |
+
return out[0].get('summary_text', str(out[0]))
|
| 21 |
+
return str(out)
|