Spaces:
Sleeping
Sleeping
Download utils/interfaces.py from skodan/multimodal-caption-retrieval: direct link, hf CLI and curl.
- Browser
- Download file 979 Bytes
-
https://huggingface.co/spaces/skodan/multimodal-caption-retrieval/resolve/main/utils/interfaces.py
- Command line
-
hf download hf://spaces/skodan/multimodal-caption-retrieval/utils/interfaces.py
-
curl -L -o interfaces.py https://huggingface.co/spaces/skodan/multimodal-caption-retrieval/resolve/main/utils/interfaces.py
979 Bytes
| from abc import ABC, abstractmethod | |
| from typing import List, Dict, Any | |
| from PIL import Image | |
| class UnifiedModelInterface(ABC): | |
| def load(self) -> None: | |
| """Lazy load all required components (models, indices, vocab, etc.)""" | |
| pass | |
| def generate_caption(self, image: Image.Image) -> str: | |
| pass | |
| def text_to_image(self, text: str, top_k: int = 5) -> List[Dict[str, Any]]: | |
| """Returns [{'image_path': str, 'score': float}, ...]""" | |
| pass | |
| def image_to_text(self, image: Image.Image, top_k: int = 5) -> List[str]: | |
| """Returns list of caption strings""" | |
| pass | |
| 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") |