Spaces:
Sleeping
Sleeping
Download src/summarizer.py from build-small-hackathon/ryugaku-app: direct link, hf CLI and curl.
- Browser
- Download file 1.25 kB
-
https://huggingface.co/spaces/build-small-hackathon/ryugaku-app/resolve/main/src/summarizer.py
- Command line
-
hf download hf://spaces/build-small-hackathon/ryugaku-app/src/summarizer.py
-
curl -L -o summarizer.py https://huggingface.co/spaces/build-small-hackathon/ryugaku-app/resolve/main/src/summarizer.py
1.25 kB
| """Summarization and easy English services.""" | |
| from __future__ import annotations | |
| from typing import Tuple | |
| from src.config import SUMMARY_SYSTEM_PROMPT, EASY_ENGLISH_SYSTEM_PROMPT | |
| from src.model_loader import get_model_and_tokenizer | |
| from src.generation import chat_generate | |
| def summarize(text: str) -> Tuple[str, str]: | |
| """Summarize Japanese text in English. Returns (summary, status).""" | |
| if not text or not text.strip(): | |
| return "", "" | |
| model, tokenizer = get_model_and_tokenizer() | |
| messages = [ | |
| {"role": "system", "content": SUMMARY_SYSTEM_PROMPT}, | |
| {"role": "user", "content": text.strip()}, | |
| ] | |
| summary = chat_generate(model, tokenizer, messages, max_new_tokens=512, do_sample=False) | |
| return summary, "" | |
| def easy_english(text: str) -> Tuple[str, str]: | |
| """Rewrite English text into simple English. Returns (easy_text, status).""" | |
| if not text or not text.strip(): | |
| return "", "" | |
| model, tokenizer = get_model_and_tokenizer() | |
| messages = [ | |
| {"role": "system", "content": EASY_ENGLISH_SYSTEM_PROMPT}, | |
| {"role": "user", "content": text.strip()}, | |
| ] | |
| easy = chat_generate(model, tokenizer, messages, max_new_tokens=512, do_sample=False) | |
| return easy, "" | |