import os import re import json import datetime import itertools import requests from PIL import Image import base64 import streamlit as st from huggingface_hub import ModelSearchArguments import webbrowser from numerize.numerize import numerize def paginator(label, articles, articles_per_page=10, on_sidebar=True): # https://gist.github.com/treuille/2ce0acb6697f205e44e3e0f576e810b7 """Lets the user paginate a set of article. Parameters ---------- label : str The label to display over the pagination widget. article : Iterator[Any] The articles to display in the paginator. articles_per_page: int The number of articles to display per page. on_sidebar: bool Whether to display the paginator widget on the sidebar. Returns ------- Iterator[Tuple[int, Any]] An iterator over *only the article on that page*, including the item's index. """ # Figure out where to display the paginator if on_sidebar: location = st.sidebar.empty() else: location = st.empty() # Display a pagination selectbox in the specified location. articles = list(articles) n_pages = (len(articles) - 1) // articles_per_page + 1 page_format_func = lambda i: f"Results {i*10} to {i*10 +10 -1}" page_number = location.selectbox(label, range(n_pages), format_func=page_format_func) # Iterate over the articles in the page to let the user display them. min_index = page_number * articles_per_page max_index = min_index + articles_per_page return itertools.islice(enumerate(articles), min_index, max_index) def page(): st.set_page_config( page_title="HF Search Engine", page_icon="š", layout="wide", initial_sidebar_state="auto", # menu_items={ # "Get Help": "https://www.extremelycoolapp.com/help", # "Report a bug": "https://www.extremelycoolapp.com/bug", # "About": "# This is a header. This is an *extremely* cool app!", # }, ) ### SIDEBAR search_backend = st.sidebar.selectbox( "Search Engine", ["hfapi", "custom"], format_func=lambda x: {"hfapi": "Huggingface API", "custom": "Sentence Bert"}[x], ) limit_results = st.sidebar.number_input("Limit results", min_value=0, value=10) st.sidebar.markdown("# Filters") args = ModelSearchArguments() library = st.sidebar.multiselect( "Library", args.library.values(), format_func=lambda x: {v: k for k, v in args.library.items()}[x] ) task = st.sidebar.multiselect( "Task", args.pipeline_tag.values(), format_func=lambda x: {v: k for k, v in args.pipeline_tag.items()}[x] ) ### MAIN PAGE st.markdown( "