Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,42 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
from PIL import Image, ImageDraw, ImageFont
|
| 4 |
import io
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def main():
|
| 7 |
# Inject custom CSS to change the color of selected tasks
|
|
@@ -63,6 +99,7 @@ def main():
|
|
| 63 |
# Define the ordered list of tasks.
|
| 64 |
task_order = [
|
| 65 |
"Text Generation",
|
|
|
|
| 66 |
"Image Generation",
|
| 67 |
"Text Classification",
|
| 68 |
"Image Classification",
|
|
@@ -77,17 +114,18 @@ def main():
|
|
| 77 |
st.sidebar.write("#### 1. Select task(s) to view models")
|
| 78 |
selected_tasks = st.sidebar.multiselect("", options=task_order, default=["Text Generation"])
|
| 79 |
# Mapping from task to CSV file name.
|
| 80 |
-
|
| 81 |
-
"Text Generation": "
|
| 82 |
-
"
|
| 83 |
-
"
|
| 84 |
-
"
|
| 85 |
-
"Image
|
| 86 |
-
"
|
| 87 |
-
"
|
| 88 |
-
"
|
| 89 |
-
"
|
| 90 |
-
"
|
|
|
|
| 91 |
}
|
| 92 |
st.sidebar.write("#### 2. Select a model to generate label")
|
| 93 |
default_model_data = {
|
|
@@ -107,7 +145,7 @@ def main():
|
|
| 107 |
for task in selected_tasks:
|
| 108 |
file_name = task_to_file[task]
|
| 109 |
try:
|
| 110 |
-
df =
|
| 111 |
except FileNotFoundError:
|
| 112 |
st.sidebar.error(f"Could not find '{file_name}' for task {task}!")
|
| 113 |
continue
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
from PIL import Image, ImageDraw, ImageFont
|
| 4 |
import io
|
| 5 |
+
import os, socket
|
| 6 |
+
from huggingface_hub import hf_hub_download
|
| 7 |
+
|
| 8 |
+
HF_REPO_ID = "AIEnergyScore/Leaderboard" # this is a Space
|
| 9 |
+
HF_REPO_TYPE = "space"
|
| 10 |
+
HF_DATA_PREFIX = "data/energy" # where the CSVs live in the Space
|
| 11 |
+
|
| 12 |
+
def read_csv_from_hub(file_name: str) -> pd.DataFrame:
|
| 13 |
+
"""
|
| 14 |
+
Download a CSV from the HF Space path data/energy/<file_name>
|
| 15 |
+
and return it as a pandas DataFrame.
|
| 16 |
+
Falls back to local file if Hub is unavailable.
|
| 17 |
+
"""
|
| 18 |
+
hub_path = f"{HF_DATA_PREFIX}/{file_name}"
|
| 19 |
+
try:
|
| 20 |
+
# fast DNS sanity check to give a useful error if DNS is down
|
| 21 |
+
socket.gethostbyname("huggingface.co")
|
| 22 |
+
|
| 23 |
+
local_path = hf_hub_download(
|
| 24 |
+
repo_id=HF_REPO_ID,
|
| 25 |
+
repo_type=HF_REPO_TYPE,
|
| 26 |
+
filename=hub_path,
|
| 27 |
+
revision="main", # adjust if you use a branch/tag
|
| 28 |
+
resume_download=True
|
| 29 |
+
)
|
| 30 |
+
return pd.read_csv(local_path)
|
| 31 |
+
except Exception as e:
|
| 32 |
+
# Fallback to local file if present
|
| 33 |
+
try:
|
| 34 |
+
return pd.read_csv(file_name)
|
| 35 |
+
except Exception:
|
| 36 |
+
# re-raise with context so it surfaces nicely in Streamlit
|
| 37 |
+
raise RuntimeError(
|
| 38 |
+
f"Unable to load '{file_name}' from Hub path '{hub_path}' or locally. "
|
| 39 |
+
f"Original error: {e}"
|
| 40 |
+
)
|
| 41 |
|
| 42 |
def main():
|
| 43 |
# Inject custom CSS to change the color of selected tasks
|
|
|
|
| 99 |
# Define the ordered list of tasks.
|
| 100 |
task_order = [
|
| 101 |
"Text Generation",
|
| 102 |
+
"Reasoning",
|
| 103 |
"Image Generation",
|
| 104 |
"Text Classification",
|
| 105 |
"Image Classification",
|
|
|
|
| 114 |
st.sidebar.write("#### 1. Select task(s) to view models")
|
| 115 |
selected_tasks = st.sidebar.multiselect("", options=task_order, default=["Text Generation"])
|
| 116 |
# Mapping from task to CSV file name.
|
| 117 |
+
TASK_TO_CSV = {
|
| 118 |
+
"Text Generation": "text_generation.csv",
|
| 119 |
+
"Reasoning": "reasoning.csv",
|
| 120 |
+
"Image Generation": "image_generation.csv",
|
| 121 |
+
"Text Classification": "text_classification.csv",
|
| 122 |
+
"Image Classification": "image_classification.csv",
|
| 123 |
+
"Image Captioning": "image_captioning.csv",
|
| 124 |
+
"Summarization": "summarization.csv",
|
| 125 |
+
"Speech-to-Text (ASR)": "asr.csv",
|
| 126 |
+
"Object Detection": "object_detection.csv",
|
| 127 |
+
"Question Answering": "question_answering.csv",
|
| 128 |
+
"Sentence Similarity": "sentence_similarity.csv"
|
| 129 |
}
|
| 130 |
st.sidebar.write("#### 2. Select a model to generate label")
|
| 131 |
default_model_data = {
|
|
|
|
| 145 |
for task in selected_tasks:
|
| 146 |
file_name = task_to_file[task]
|
| 147 |
try:
|
| 148 |
+
df = read_csv_from_hub(file_name)
|
| 149 |
except FileNotFoundError:
|
| 150 |
st.sidebar.error(f"Could not find '{file_name}' for task {task}!")
|
| 151 |
continue
|