import sys root_dir = __file__.rsplit("/", 2)[0] if root_dir not in sys.path: sys.path.append(root_dir) import gradio as gr from utils import set_text_bg_color from loop_retrieve_cards import get_models, get_datasets, get_readme_dict def match_card(input: str, card_id: str, card_type: str) -> str: """ Search the input in a card. If the input string is contained in the card_id or its README, display this card. Args: input: Input string card_id: HuggingFace card id card_type: Type of card, either "model" or "dataset" """ display_str = "" readme_dict = get_readme_dict() if input.lower() in card_id.lower() or input.lower() in readme_dict[card_id].lower(): # Add card id if card_type == "model": display_str += f"## [{set_text_bg_color(input, card_id)}](https://huggingface.co/{card_id})\n\n" else: display_str += f"## [{set_text_bg_color(input, card_id)}](https://huggingface.co/datasets/{card_id})\n\n" # Highlight lines that contain the input string show_lines = [] for line in readme_dict[card_id].split("\n"): if input.lower() in line.lower() and "