File size: 3,500 Bytes
6414ec4
 
09c7026
6414ec4
a208802
 
a04589c
 
24a3e12
eb4651f
 
 
 
a208802
 
6414ec4
b5241cb
6414ec4
b5241cb
 
13c8543
b5241cb
6414ec4
b5241cb
 
6414ec4
 
 
 
59ef901
6414ec4
 
 
eb4651f
 
6414ec4
b4d30ed
6414ec4
 
 
 
09c7026
6414ec4
 
 
 
 
 
 
 
09c7026
 
 
 
6414ec4
eb4651f
6414ec4
 
 
 
 
 
 
09c7026
 
6414ec4
09c7026
 
6414ec4
 
 
 
 
 
 
 
 
 
 
a208802
 
a04589c
17424df
a04589c
17424df
a208802
6414ec4
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import requests
import streamlit as st
import re  # For string normalization

# Constants for citation information
CITATION_BUTTON_LABEL = "πŸ“™ Citation"
CITATION_NOTE_TEXT = "If you use this resource, please cite it as:"
CITATION_BIB_TEXT = """
@article{zhao2024workflows,
  title={On the Workflows and Smells of Leaderboard Operations (LBOps): An Exploratory Study of Foundation Model Leaderboards},
  author={Zhao, Zhimin and Bangash, Abdul Ali and C{\^o}go, Filipe Roseiro and Adams, Bram and Hassan, Ahmed E},
  journal={arXiv preprint arXiv:2407.04065},
  year={2024}
}
"""

@st.cache_data(ttl=3600)  # Cache the data for 1 hour
def fetch_readme_content():
    try:
        url = "https://raw.githubusercontent.com/SAILResearch/awesome-foundation-model-leaderboards/main/README.md"
        response = requests.get(url, timeout=30)
        response.raise_for_status()  # Raises HTTPError for bad responses
        return response.text
    except requests.exceptions.RequestException as e:
        st.error(f"Failed to fetch README.md content: {e}")
        return ""

class SearchApplication:
    def __init__(self):
        self.title = "Foundation Model Leaderboard Search"
        self.set_page_config()

        st.header(self.title)
        self.query = st.text_input("Search", value="")
        
        st.caption(
            "This search toolkit is a user-friendly platform that enables efficient exploration and filtering of the comprehensive [Awesome Foundation Model Leaderboard](https://github.com/SAILResearch/awesome-foundation-model-leaderboards) list, which includes over 400 foundation model leaderboards, along with various development tools and evaluation organizations, making it an indispensable resource for researchers, developers, and enthusiasts in the field."
        )
        st.write("#")

        self.show_search_results()
        self.show_citation_panel()

    def set_page_config(self):
        st.set_page_config(
            page_title=self.title,
            page_icon="😎",
            layout="centered",
        )

    def normalize_string(self, input_string):
        """Normalize a string by removing spaces, converting to lowercase, and stripping special characters."""
        return re.sub(r'\s+', '', input_string.lower())

    def show_search_results(self):
        if self.query:
            st.write("#")

            readme_content = fetch_readme_content()

            if readme_content:
                search_results = []
                lines = readme_content.split("\n")
                normalized_query = self.normalize_string(self.query)  # Normalize user query

                for line in lines:
                    normalized_line = self.normalize_string(line)  # Normalize each line
                    if normalized_query in normalized_line:
                        search_results.append(line)

                num_search_results = len(search_results)
                st.write(f"A total of {num_search_results} matches found.")

                if num_search_results > 0:
                    for result in search_results:
                        st.write(result)
                else:
                    st.write("No matches found.")

    def show_citation_panel(self):
        with st.expander(CITATION_BUTTON_LABEL, expanded=True):
            st.markdown(CITATION_NOTE_TEXT)
            st.code(
                CITATION_BIB_TEXT,
                language="",
            )

if __name__ == "__main__":
    SearchApplication()