Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| import wandb | |
| import datetime | |
| def get_all_competition_summary(api, projects): | |
| number_of_competitions = 0 | |
| number_of_runs = 0 | |
| for project in projects: | |
| entity = projects[project]["entity"] | |
| project_name = projects[project]["project"] | |
| runs = api.runs(f"{entity}/{project_name}") | |
| number_of_competitions += 1 | |
| number_of_runs += len(runs) | |
| return number_of_competitions,number_of_runs | |
| def fetch_competition_summary(api, projects, selected_project): | |
| data = [] | |
| entity = projects[selected_project]["entity"] | |
| project = projects[selected_project]["project"] | |
| runs = api.runs(f"{entity}/{project}") | |
| for run in runs: | |
| try: | |
| summary = run.summary | |
| if summary.get("validator_hotkey") and summary.get("winning_hotkey"): | |
| data.append({ | |
| "ID": run.id, | |
| "Validator Hotkey": summary.get("validator_hotkey"), | |
| "Winning Hotkey": summary.get("winning_hotkey"), | |
| "Run Time (s)": summary.get("run_time_s"), | |
| "Created At": run.created_at, | |
| }) | |
| except Exception as e: | |
| st.write(f"Error processing run {run.id}: {str(e)}") | |
| df = pd.DataFrame(data) | |
| if not df.empty: | |
| df['Created At'] = pd.to_datetime(df['Created At']) | |
| df = df.sort_values(by="Created At", ascending=False) | |
| return df | |
| def fetch_models_evaluation(api, projects, selected_project): | |
| data = [] | |
| entity = projects[selected_project]["entity"] | |
| project = projects[selected_project]["project"] | |
| runs = api.runs(f"{entity}/{project}") | |
| for run in runs: | |
| try: | |
| summary = run.summary | |
| if summary.get("score") is not None: # Assuming runs with score are model evaluations | |
| data.append({ | |
| "ID": run.id, | |
| "Username": run.user.username, | |
| "Hotkey": summary.get("miner_hotkey", "N/A"), | |
| "Score": summary.get("score"), | |
| "F1-beta": summary.get("fbeta"), | |
| "Accuracy": summary.get("accuracy"), | |
| "Recall": summary.get("recall"), | |
| "Precision": summary.get("precision"), | |
| "Tested entries": summary.get("tested_entries"), | |
| # "Run Time (s)": summary.get("run_time_s"), | |
| "ROC AUC": summary.get("roc_auc"), | |
| "Confusion Matrix": summary.get("confusion_matrix"), | |
| "Created At": run.created_at, | |
| #TODO link to huggingface model | |
| }) | |
| except Exception as e: | |
| st.write(f"Error processing run {run.id}: {str(e)}") | |
| df = pd.DataFrame(data) | |
| if not df.empty: | |
| df['Created At'] = pd.to_datetime(df['Created At']) | |
| df = df.sort_values(by="Created At", ascending=False) | |
| return df | |
| def update_leader_info(leader_info, competition, best_model): | |
| current_date = datetime.now().strftime("%Y-%m-%d") | |
| if leader_info.get(competition) is None: | |
| leader_info[competition] = { | |
| "Username": best_model["Username"], | |
| "Hotkey": best_model["Hotkey"], | |
| "Date": current_date, | |
| "Days on Top": 1 | |
| } | |
| else: | |
| if leader_info[competition]["UID"] == best_model["ID"]: | |
| leader_info[competition]["Days on Top"] += 1 | |
| else: | |
| leader_info[competition] = { | |
| "Username": best_model["Username"], | |
| "Hotkey": best_model["Hotkey"], | |
| "Date": current_date, | |
| "Days on Top": 1 | |
| } | |
| return leader_info[competition] | |
| def highlight_score_column(s): | |
| """ | |
| Highlight the 'Score' column with a custom background color. | |
| """ | |
| return ['background-color: yellow' if s.name == 'Score' else '' for _ in s] | |
| def set_custom_table_style(): | |
| st.markdown(""" | |
| <style> | |
| .dataframe, .summary-table { | |
| width: 100%; | |
| border-collapse: collapse; | |
| margin: 20px 0; | |
| font-size: 16px; | |
| min-width: 400px; | |
| } | |
| .dataframe th, | |
| .dataframe td, | |
| .summary-table th, | |
| .summary-table td { | |
| padding: 12px 15px; | |
| border: 1px solid #CCCCCC; | |
| text-align: left; | |
| } | |
| .dataframe thead th, | |
| .summary-table th { | |
| background-color: #333333; | |
| color: #FFFFFF; | |
| } | |
| .dataframe tbody tr:nth-child(even), | |
| .summary-table tr:nth-child(even) { | |
| background-color: #F0F0F0; | |
| } | |
| .dataframe tbody tr:nth-child(odd), | |
| .summary-table tr:nth-child(odd) { | |
| background-color: #E0E0E0; | |
| } | |
| .dataframe tbody td, | |
| .summary-table td { | |
| color: #333333; | |
| } | |
| .dataframe tbody tr:hover, | |
| .summary-table tr:hover { | |
| background-color: #D1D1D1; | |
| } | |
| .table-container { | |
| overflow-x: auto; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |