import gradio as gr import re from pathlib import Path from api import load_annoy_index, analyze_image annoy_index, mappings = load_annoy_index() def get_article_text(): article = Path("README.md").read_text() # Remove the HuggingFace Space app information from the README article = re.sub(r"^---.+---\s+", "", article, flags=re.MULTILINE + re.DOTALL) return article STYLE = """ """ def find_matching_images(input_img, n_matches: int = 10): results = analyze_image(input_img, annoy_index, n_matches=n_matches) indexes = results[0] scores = results[1] images = [] HTML = "" for i in range(len(indexes)): index = str(indexes[i]) mapping = mappings[index] url = mapping["url"] if url != "": images.append(url) score = round((1 - scores[i]) * 100, 1) HTML += f"""