Download utils.py from coffeebeans-ai/multimodal_rag_chatbot: direct link, hf CLI and curl.
- Browser
- Download file 748 Bytes
-
https://huggingface.co/spaces/coffeebeans-ai/multimodal_rag_chatbot/resolve/main/utils.py
- Command line
-
hf download hf://spaces/coffeebeans-ai/multimodal_rag_chatbot/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/coffeebeans-ai/multimodal_rag_chatbot/resolve/main/utils.py
748 Bytes
| from logging_config import setup_logger | |
| logger = setup_logger(__name__) | |
| def extract_text_from_content(content): | |
| """Extract text from various message content formats.""" | |
| if isinstance(content, str): | |
| return content | |
| elif isinstance(content, list): | |
| # Handle list of text items or dictionaries | |
| text_parts = [] | |
| for item in content: | |
| if isinstance(item, dict): | |
| # Extract text from dictionary format | |
| if 'text' in item: | |
| text_parts.append(item['text']) | |
| elif isinstance(item, str): | |
| text_parts.append(item) | |
| return ''.join(text_parts) | |
| else: | |
| # Fallback for any other format | |
| return str(content) | |