Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import subprocess
|
|
| 8 |
from io import StringIO
|
| 9 |
|
| 10 |
import runpod
|
|
|
|
| 11 |
import requests
|
| 12 |
import gradio as gr
|
| 13 |
import pandas as pd
|
|
@@ -192,6 +193,7 @@ tags:
|
|
| 192 |
- merge
|
| 193 |
- mergekit
|
| 194 |
- lazymergekit
|
|
|
|
| 195 |
---
|
| 196 |
|
| 197 |
# {{ model_name }}
|
|
@@ -263,6 +265,9 @@ print(outputs[0]["generated_text"])
|
|
| 263 |
|
| 264 |
|
| 265 |
def upload_model(api: HfApi, username: str, model_name: str) -> None:
|
|
|
|
|
|
|
|
|
|
| 266 |
api.create_repo(
|
| 267 |
repo_id=f"{username}/{model_name}",
|
| 268 |
repo_type="model",
|
|
@@ -275,6 +280,9 @@ def upload_model(api: HfApi, username: str, model_name: str) -> None:
|
|
| 275 |
|
| 276 |
|
| 277 |
def create_pod(model_name: str, username: str, n=10, wait_seconds=10):
|
|
|
|
|
|
|
|
|
|
| 278 |
for attempt in range(n):
|
| 279 |
try:
|
| 280 |
pod = runpod.create_pod(
|
|
@@ -309,6 +317,9 @@ def create_pod(model_name: str, username: str, n=10, wait_seconds=10):
|
|
| 309 |
|
| 310 |
|
| 311 |
def download_leaderboard():
|
|
|
|
|
|
|
|
|
|
| 312 |
url = "https://gist.githubusercontent.com/automerger/84af749b1c0ef7336858df408f46f388/raw"
|
| 313 |
file_path = "leaderboard.txt"
|
| 314 |
response = requests.get(url)
|
|
@@ -335,12 +346,30 @@ def convert_markdown_table_to_dataframe(md_content):
|
|
| 335 |
|
| 336 |
|
| 337 |
def get_dataframe():
|
|
|
|
|
|
|
|
|
|
| 338 |
content = download_leaderboard()
|
| 339 |
df = convert_markdown_table_to_dataframe(content)
|
| 340 |
return df
|
| 341 |
|
| 342 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
def merge_loop():
|
|
|
|
|
|
|
|
|
|
| 344 |
# Start HF API
|
| 345 |
api = HfApi(token=HF_TOKEN)
|
| 346 |
|
|
@@ -380,9 +409,13 @@ def merge_loop():
|
|
| 380 |
print("Upload model")
|
| 381 |
upload_model(api, USERNAME, model_name)
|
| 382 |
|
|
|
|
|
|
|
|
|
|
| 383 |
# Evaluate model on Runpod
|
| 384 |
create_pod(model_name, USERNAME)
|
| 385 |
|
|
|
|
| 386 |
# Install scrape-open-llm-leaderboard and mergekit
|
| 387 |
command = ["git", "clone", "-q", "https://github.com/Weyaxi/scrape-open-llm-leaderboard"]
|
| 388 |
subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
|
|
| 8 |
from io import StringIO
|
| 9 |
|
| 10 |
import runpod
|
| 11 |
+
import shutil
|
| 12 |
import requests
|
| 13 |
import gradio as gr
|
| 14 |
import pandas as pd
|
|
|
|
| 193 |
- merge
|
| 194 |
- mergekit
|
| 195 |
- lazymergekit
|
| 196 |
+
- automerger
|
| 197 |
---
|
| 198 |
|
| 199 |
# {{ model_name }}
|
|
|
|
| 265 |
|
| 266 |
|
| 267 |
def upload_model(api: HfApi, username: str, model_name: str) -> None:
|
| 268 |
+
"""
|
| 269 |
+
Upload merged model to the Hugging Face Hub.
|
| 270 |
+
"""
|
| 271 |
api.create_repo(
|
| 272 |
repo_id=f"{username}/{model_name}",
|
| 273 |
repo_type="model",
|
|
|
|
| 280 |
|
| 281 |
|
| 282 |
def create_pod(model_name: str, username: str, n=10, wait_seconds=10):
|
| 283 |
+
"""
|
| 284 |
+
Create a RunPod instance to run the evaluation.
|
| 285 |
+
"""
|
| 286 |
for attempt in range(n):
|
| 287 |
try:
|
| 288 |
pod = runpod.create_pod(
|
|
|
|
| 317 |
|
| 318 |
|
| 319 |
def download_leaderboard():
|
| 320 |
+
"""
|
| 321 |
+
Download the gist that contains the leaderboard.
|
| 322 |
+
"""
|
| 323 |
url = "https://gist.githubusercontent.com/automerger/84af749b1c0ef7336858df408f46f388/raw"
|
| 324 |
file_path = "leaderboard.txt"
|
| 325 |
response = requests.get(url)
|
|
|
|
| 346 |
|
| 347 |
|
| 348 |
def get_dataframe():
|
| 349 |
+
"""
|
| 350 |
+
Wrapper to update the Gradio dataframe.
|
| 351 |
+
"""
|
| 352 |
content = download_leaderboard()
|
| 353 |
df = convert_markdown_table_to_dataframe(content)
|
| 354 |
return df
|
| 355 |
|
| 356 |
|
| 357 |
+
def clear_data():
|
| 358 |
+
"""
|
| 359 |
+
Clear data so the Space doesn't crash...
|
| 360 |
+
"""
|
| 361 |
+
dir_path = "merge"
|
| 362 |
+
if os.path.exists(dir_path) and os.path.isdir(dir_path):
|
| 363 |
+
shutil.rmtree(dir_path)
|
| 364 |
+
print(f"The directory '{dir_path}' has been removed successfully.")
|
| 365 |
+
else:
|
| 366 |
+
print(f"The directory '{dir_path}' does not exist.")
|
| 367 |
+
|
| 368 |
+
|
| 369 |
def merge_loop():
|
| 370 |
+
"""
|
| 371 |
+
Main function that orchestrates the merge.
|
| 372 |
+
"""
|
| 373 |
# Start HF API
|
| 374 |
api = HfApi(token=HF_TOKEN)
|
| 375 |
|
|
|
|
| 409 |
print("Upload model")
|
| 410 |
upload_model(api, USERNAME, model_name)
|
| 411 |
|
| 412 |
+
# Clear data
|
| 413 |
+
clear_data()
|
| 414 |
+
|
| 415 |
# Evaluate model on Runpod
|
| 416 |
create_pod(model_name, USERNAME)
|
| 417 |
|
| 418 |
+
|
| 419 |
# Install scrape-open-llm-leaderboard and mergekit
|
| 420 |
command = ["git", "clone", "-q", "https://github.com/Weyaxi/scrape-open-llm-leaderboard"]
|
| 421 |
subprocess.run(command, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|