Spaces:
Running
Running
Adding actual fields for models.
Browse files
app.py
CHANGED
|
@@ -2,20 +2,166 @@ import gradio as gr
|
|
| 2 |
from huggingface_hub import HfApi
|
| 3 |
import os
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
TOKEN = os.environ.get("DEBUG")
|
| 6 |
API = HfApi(token=TOKEN)
|
| 7 |
|
|
|
|
| 8 |
def update(name):
|
| 9 |
-
API.restart_space(
|
| 10 |
-
return f"Okay!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
with gr.Blocks() as demo:
|
| 13 |
gr.Markdown("This is a super basic example 'frontend'. Start typing below and then click **Run** to launch the job.")
|
| 14 |
gr.Markdown("The job will be launched at [EnergyStarAI/launch-computation-example](https://huggingface.co/spaces/EnergyStarAI/launch-computation-example)")
|
| 15 |
with gr.Row():
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
demo.launch()
|
|
|
|
| 2 |
from huggingface_hub import HfApi
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
import datetime
|
| 6 |
+
|
| 7 |
+
OWNER = "EnergyStarAI"
|
| 8 |
+
COMPUTE_SPACE = f"{OWNER}/launch-computation-example"
|
| 9 |
+
REQUESTS_DATASET_PATH = f"{OWNER}/requests_debug"
|
| 10 |
+
|
| 11 |
TOKEN = os.environ.get("DEBUG")
|
| 12 |
API = HfApi(token=TOKEN)
|
| 13 |
|
| 14 |
+
|
| 15 |
def update(name):
|
| 16 |
+
API.restart_space(COMPUTE_SPACE)
|
| 17 |
+
return f"Okay! {COMPUTE_SPACE} should be running now!"
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def get_model_size(model_info: ModelInfo, precision: str):
|
| 21 |
+
"""Gets the model size from the configuration, or the model name if the configuration does not contain the information."""
|
| 22 |
+
try:
|
| 23 |
+
model_size = round(model_info.safetensors["total"] / 1e9, 3)
|
| 24 |
+
except (AttributeError, TypeError):
|
| 25 |
+
return 0 # Unknown model sizes are indicated as 0, see NUMERIC_INTERVALS in app.py
|
| 26 |
+
|
| 27 |
+
size_factor = 8 if (precision == "GPTQ" or "gptq" in model_info.modelId.lower()) else 1
|
| 28 |
+
model_size = size_factor * model_size
|
| 29 |
+
return model_size
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def add_new_eval(
|
| 33 |
+
repo_id: str,
|
| 34 |
+
base_model: str,
|
| 35 |
+
revision: str,
|
| 36 |
+
precision: str,
|
| 37 |
+
weight_type: str,
|
| 38 |
+
model_type: str,
|
| 39 |
+
):
|
| 40 |
+
model_owner = repo_id.split("/")[0]
|
| 41 |
+
model_name = repo_id.split("/")[1]
|
| 42 |
+
precision = precision.split(" ")[0]
|
| 43 |
+
|
| 44 |
+
out_dir = f"{EVAL_REQUESTS_PATH}/{model_owner}"
|
| 45 |
+
print("Making Dataset directory to output results at %s" % out_dir)
|
| 46 |
+
os.makedirs(out_dir, exist_ok=True)
|
| 47 |
+
out_path = f"{EVAL_REQUESTS_PATH}/{model_owner}/{model_name}_eval_request_{precision}_{weight_type}.json"
|
| 48 |
+
|
| 49 |
+
current_time = datetime.now(datetime.timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 50 |
+
|
| 51 |
+
#if model_type is None or model_type == "":
|
| 52 |
+
# return styled_error("Please select a model type.")
|
| 53 |
+
|
| 54 |
+
# Does the model actually exist?
|
| 55 |
+
#if revision == "":
|
| 56 |
+
revision = "main"
|
| 57 |
+
|
| 58 |
+
# Is the model on the hub?
|
| 59 |
+
#if weight_type in ["Delta", "Adapter"]:
|
| 60 |
+
# base_model_on_hub, error, _ = is_model_on_hub(model_name=base_model, revision=revision, token=TOKEN, test_tokenizer=True)
|
| 61 |
+
# if not base_model_on_hub:
|
| 62 |
+
# return styled_error(f'Base model "{base_model}" {error}')
|
| 63 |
+
|
| 64 |
+
#if not weight_type == "Adapter":
|
| 65 |
+
# model_on_hub, error, _ = is_model_on_hub(model_name=model, revision=revision, token=TOKEN, test_tokenizer=True)
|
| 66 |
+
# if not model_on_hub:
|
| 67 |
+
# return styled_error(f'Model "{model}" {error}')
|
| 68 |
+
|
| 69 |
+
# Is the model info correctly filled?
|
| 70 |
+
try:
|
| 71 |
+
model_info = API.model_info(repo_id=repo_id, revision=revision)
|
| 72 |
+
except Exception:
|
| 73 |
+
print("Could not find information for model %s at revision %s" % (model, revision))
|
| 74 |
+
return
|
| 75 |
+
# return styled_error("Could not get your model information. Please fill it up properly.")
|
| 76 |
+
|
| 77 |
+
model_size = get_model_size(model_info=model_info, precision=precision)
|
| 78 |
+
|
| 79 |
+
# Were the model card and license filled?
|
| 80 |
+
#try:
|
| 81 |
+
# license = model_info.cardData["license"]
|
| 82 |
+
#except Exception:
|
| 83 |
+
# return styled_error("Please select a license for your model")
|
| 84 |
+
|
| 85 |
+
#modelcard_OK, error_msg = check_model_card(model)
|
| 86 |
+
#if not modelcard_OK:
|
| 87 |
+
# return styled_error(error_msg)
|
| 88 |
+
|
| 89 |
+
# Seems good, creating the eval
|
| 90 |
+
print("Adding request")
|
| 91 |
+
|
| 92 |
+
request_entry = {
|
| 93 |
+
"model": repo_id,
|
| 94 |
+
"base_model": base_model,
|
| 95 |
+
"revision": revision,
|
| 96 |
+
"precision": precision,
|
| 97 |
+
"weight_type": weight_type,
|
| 98 |
+
"status": "PENDING",
|
| 99 |
+
"submitted_time": current_time,
|
| 100 |
+
"model_type": model_type,
|
| 101 |
+
"likes": model_info.likes,
|
| 102 |
+
"params": model_size}
|
| 103 |
+
#"license": license,
|
| 104 |
+
#"private": False,
|
| 105 |
+
#}
|
| 106 |
+
|
| 107 |
+
# Check for duplicate submission
|
| 108 |
+
#if f"{model}_{revision}_{precision}" in REQUESTED_MODELS:
|
| 109 |
+
# return styled_warning("This model has been already submitted.")
|
| 110 |
+
|
| 111 |
+
print("Writing out request file to %s" % out_path)
|
| 112 |
+
with open(out_path, "w") as f:
|
| 113 |
+
f.write(json.dumps(eval_entry))
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
|
| 117 |
|
| 118 |
with gr.Blocks() as demo:
|
| 119 |
gr.Markdown("This is a super basic example 'frontend'. Start typing below and then click **Run** to launch the job.")
|
| 120 |
gr.Markdown("The job will be launched at [EnergyStarAI/launch-computation-example](https://huggingface.co/spaces/EnergyStarAI/launch-computation-example)")
|
| 121 |
with gr.Row():
|
| 122 |
+
gr.Markdown("# ✉️✨ Submit your model here!", elem_classes="markdown-text")
|
| 123 |
+
with gr.Row():
|
| 124 |
+
with gr.Column():
|
| 125 |
+
model_name_textbox = gr.Textbox(label="Model name")
|
| 126 |
+
revision_name_textbox = gr.Textbox(label="Revision commit", placeholder="main")
|
| 127 |
+
model_type = gr.Dropdown(
|
| 128 |
+
choices=[t.to_str(" : ") for t in ModelType if t != ModelType.Unknown],
|
| 129 |
+
label="Model type",
|
| 130 |
+
multiselect=False,
|
| 131 |
+
value=None,
|
| 132 |
+
interactive=True,
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
with gr.Column():
|
| 136 |
+
precision = gr.Dropdown(
|
| 137 |
+
choices=[i.value.name for i in Precision if i != Precision.Unknown],
|
| 138 |
+
label="Precision",
|
| 139 |
+
multiselect=False,
|
| 140 |
+
value="float16",
|
| 141 |
+
interactive=True,
|
| 142 |
+
)
|
| 143 |
+
weight_type = gr.Dropdown(
|
| 144 |
+
choices=[i.value.name for i in WeightType],
|
| 145 |
+
label="Weights type",
|
| 146 |
+
multiselect=False,
|
| 147 |
+
value="Original",
|
| 148 |
+
interactive=True,
|
| 149 |
+
)
|
| 150 |
+
base_model_name_textbox = gr.Textbox(label="Base model (for delta or adapter weights)")
|
| 151 |
|
| 152 |
+
submit_button = gr.Button("Run Analysis")
|
| 153 |
+
submission_result = gr.Markdown()
|
| 154 |
+
submit_button.click(
|
| 155 |
+
fn=add_new_eval,
|
| 156 |
+
inputs=[
|
| 157 |
+
model_name_textbox,
|
| 158 |
+
base_model_name_textbox,
|
| 159 |
+
revision_name_textbox,
|
| 160 |
+
precision,
|
| 161 |
+
weight_type,
|
| 162 |
+
model_type,
|
| 163 |
+
],
|
| 164 |
+
outputs=submission_result,
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
demo.launch()
|