Spaces:
Sleeping
Sleeping
| #modules/summarizer_module.py | |
| from typing import Dict, List | |
| from core.base_module import AIModule | |
| from langchain import OpenAI | |
| class SummarizerModule(AIModule): | |
| def __init__(self, model_name: str = "gpt-3.5-turbo"): | |
| self.model = OpenAI(model_name=model_name) | |
| async def process(self, input_data: Dict) -> Dict: | |
| text = input_data.get("text", "") | |
| prompt = f"Please summarize the following text:\n\n{text}\n\nSummary:" | |
| summary = self.model.predict(prompt) | |
| return { | |
| "summary": summary, | |
| "original_length": len(text), | |
| "summary_length": len(summary) | |
| } | |
| async def get_status(self) -> Dict: | |
| return {"status": "operational"} | |
| def capabilities(self) -> List[str]: | |
| return ["text-summarization", "length-reduction"] | |