Spaces:
Sleeping
Sleeping
File size: 964 Bytes
1182571 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
from abc import ABC, abstractmethod
from typing import List
class ParaphrasingModel(ABC):
"""
Abstract base class for paraphrasing models (e.g., T5, GPT).
"""
@abstractmethod
def paraphrase(self, text: str) -> str:
"""Paraphrase the given text."""
pass
def paraphrase_batch(self, texts: List[str]) -> List[str]:
"""
Paraphrase a list of texts.
Default implementation loops, but subclasses should override for GPU batching.
"""
return [self.paraphrase(text) for text in texts]
class TextProcessingMode(ABC):
"""
Abstract base class for text processing modes (Strategy Pattern).
Defines HOW the text is broken down and processed (e.g., by paragraph, random sentences).
"""
@abstractmethod
def process(self, text: str, paraphraser: ParaphrasingModel) -> str:
"""
Process a block of text using the provided paraphraser.
"""
pass
|