File size: 979 Bytes
c33d894
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from abc import ABC, abstractmethod
from typing import List, Dict, Any
from PIL import Image

class UnifiedModelInterface(ABC):
    @abstractmethod
    def load(self) -> None:
        """Lazy load all required components (models, indices, vocab, etc.)"""
        pass

    @abstractmethod
    def generate_caption(self, image: Image.Image) -> str:
        pass

    @abstractmethod
    def text_to_image(self, text: str, top_k: int = 5) -> List[Dict[str, Any]]:
        """Returns [{'image_path': str, 'score': float}, ...]"""
        pass

    @abstractmethod
    def image_to_text(self, image: Image.Image, top_k: int = 5) -> List[str]:
        """Returns list of caption strings"""
        pass

    @abstractmethod
    def image_to_image(self, image: Image.Image, top_k: int = 5) -> List[Dict[str, Any]]:
        pass

    def text_to_text(self, text: str, top_k: int = 5) -> List[Dict[str, Any]]:
        raise NotImplementedError("Text-to-text not supported by this model")