|
import requests |
|
import streamlit as st |
|
|
|
|
|
def fetch_readme_content(): |
|
url = "https://raw.githubusercontent.com/SAILResearch/awesome-foundation-model-leaderboards/main/README.md" |
|
response = requests.get(url) |
|
if response.status_code == 200: |
|
return response.text |
|
else: |
|
st.error("Failed to fetch README.md content from GitHub.") |
|
return "" |
|
|
|
|
|
class SearchApplication: |
|
def __init__(self): |
|
self.title = "Awesome Foundation Model Leaderboard Search" |
|
self.set_page_config() |
|
|
|
st.header(self.title) |
|
col1, col2 = st.columns(2) |
|
with col1: |
|
self.query = st.text_input("Search English words", value="") |
|
|
|
with col2: |
|
st.write("#") |
|
self.search_button = st.button("π") |
|
|
|
st.caption( |
|
"You can search for open-source software from [200+ " |
|
"repositories](https://github.com/SAILResearch/awesome-foundation-model-leaderboards)." |
|
) |
|
st.write("#") |
|
|
|
self.show_search_results() |
|
|
|
def set_page_config(self): |
|
st.set_page_config( |
|
page_title=self.title, |
|
page_icon="π", |
|
layout="centered", |
|
) |
|
|
|
|
|
def show_search_results(self): |
|
if self.query or self.search_button: |
|
st.write("#") |
|
|
|
readme_content = fetch_readme_content() |
|
|
|
if readme_content: |
|
search_results = [] |
|
lines = readme_content.split("\n") |
|
for line in lines: |
|
if self.query.lower() in line.lower(): |
|
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.") |
|
|
|
|
|
if __name__ == "__main__": |
|
SearchApplication() |
|
|