merve's picture
merve HF staff
Update app.py
07f6ad9
raw
history blame
No virus
3.67 kB
import requests
import json
import pandas as pd
from tqdm.auto import tqdm
import streamlit as st
from huggingface_hub import HfApi, hf_hub_download
from huggingface_hub.repocard import metadata_load
import streamlit.components.v1 as components
def make_clickable_model(model_name):
link = "https://huggingface.co/" + model_name
return f'<a target="_blank" href="{link}">{model_name}</a>'
# Make user clickable link
def make_clickable_user(user_id):
link = "https://huggingface.co/" + user_id
return f'<a target="_blank" href="{link}">{user_id}</a>'
def get_model_ids():
api = HfApi()
models = api.list_models(filter="deprem-clf-v1")
model_ids = [x.modelId for x in models]
return model_ids
def get_metadata(model_id):
try:
readme_path = hf_hub_download(model_id, filename="README.md")
return metadata_load(readme_path)
except requests.exceptions.HTTPError:
# 404 README.md not found
return None
def parse_metrics_accuracy(meta):
if "model-index" not in meta:
return None
result = meta["model-index"][0]["results"]
metrics = result[0]["metrics"]
accuracy = metrics[2]["value"]
print("Accuracy", accuracy)
return accuracy
def parse_metrics_recall(meta):
if "model-index" not in meta:
return None
result = meta["model-index"][0]["results"]
metrics = result[0]["metrics"]
recall = metrics[0]["value"]
print("Recall", recall)
return recall
def parse_metrics_f1(meta):
if "model-index" not in meta:
return None
result = meta["model-index"][0]["results"]
metrics = result[0]["metrics"]
f1 = metrics[1]["value"]
print("F1-score", f1)
return f1
#@st.cache(ttl=600)
def get_data():
data = []
model_ids = get_model_ids()
for model_id in tqdm(model_ids):
meta = get_metadata(model_id)
if meta is None:
continue
user_id = model_id.split('/')[0]
row = {}
row["User"] = user_id
row["Model"] = model_id
recall = parse_metrics_recall(meta)
row["Recall"] = recall
f1 = parse_metrics_f1(meta)
row["F1-Score"] = f1
data.append(row)
return pd.DataFrame.from_records(data)
dataframe = get_data()
dataframe = dataframe.fillna("")
st.markdown("# Deprem Niyet Analizi için Lider Tablosu")
st.markdown("Bu lider tablosu modellerimizi versiyonladıktan sonra hangi modeli üretime çıkarmamız gerektiğinin takibini yapmak için kullanılır.")
st.markdown(
"Model card'da metadata'da tags kısmına deprem-clf-v1 yazarsanız modeliniz buraya otomatik eklenir."
)
st.markdown(
"Burada recall, f1-score ve accuracy'nin macro average'ına bakıyoruz. Model card'ın metadata kısmında bu üç veriyi log'lamanız yeterli. Burada classification report çıkarırken **probability'lerin** confidence threshold'u baz alınır."
)
st.markdown("Örnek metadata için [bu model card'ın metadata kısmını](https://huggingface.co/deprem-ml/deprem-roberta-intent/blob/main/README.md) kopyalayıp yapıştırarak kendi metriklerinize göre ayarlayabilirsiniz.")
st.markdown(
"Modelin üstüne tıklayıp model card'a gidebilirsiniz."
)
# turn the model ids into clickable links
dataframe["User"] = dataframe["User"].apply(make_clickable_user)
dataframe["Model"] = dataframe["Model"].apply(make_clickable_model)
dataframe = dataframe.sort_values(by=['F1-Score'], ascending=False)
table_html = dataframe.to_html(escape=False, index=False)
table_html = table_html.replace("<th>", '<th align="left">') # left-align the headers
st.write(table_html, unsafe_allow_html=True)