Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,96 +1,36 @@
|
|
| 1 |
-
import
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
"
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"mBART",
|
| 34 |
-
"mBART-50",
|
| 35 |
-
"MEGA",
|
| 36 |
-
"Megatron-BERT",
|
| 37 |
-
"Megatron-GPT2",
|
| 38 |
-
"MGP-STR",
|
| 39 |
-
"Mimi",
|
| 40 |
-
"Mistral",
|
| 41 |
-
"Mixtral",
|
| 42 |
-
"Mllama",
|
| 43 |
-
"mLUKE",
|
| 44 |
-
"MMS",
|
| 45 |
-
"MobileBERT",
|
| 46 |
-
"MobileNetV1",
|
| 47 |
-
"MobileNetV2",
|
| 48 |
-
"MobileViT",
|
| 49 |
-
"MobileViTV2",
|
| 50 |
-
"Moshi",
|
| 51 |
-
"MPNet",
|
| 52 |
-
"MPT",
|
| 53 |
-
"MRA",
|
| 54 |
-
"MT5",
|
| 55 |
-
"MusicGen",
|
| 56 |
-
]
|
| 57 |
-
|
| 58 |
-
# Create a dropdown menu for model selection
|
| 59 |
-
model_selector = pn.widgets.Select(options=model_list, value=model_list[0])
|
| 60 |
-
|
| 61 |
-
# Create a text input for the repository list file
|
| 62 |
-
repo_list_file = pn.widgets.TextInput(value="repo_list.txt")
|
| 63 |
-
|
| 64 |
-
# Create a text input for the output directory
|
| 65 |
-
output_dir = pn.widgets.TextInput(value="output_dir")
|
| 66 |
-
|
| 67 |
-
# Create a checkbox for dry run
|
| 68 |
-
dry_run = pn.widgets.Checkbox(value=False)
|
| 69 |
-
|
| 70 |
-
# Create a button to start the process
|
| 71 |
-
start_button = pn.widgets.Button(name="Start")
|
| 72 |
-
|
| 73 |
-
# Define the function to be executed when the button is clicked
|
| 74 |
-
def start_process(event):
|
| 75 |
-
# Get the selected model and repository list file
|
| 76 |
-
model = model_selector.value
|
| 77 |
-
repo_list_file_path = repo_list_file.value
|
| 78 |
-
output_dir_path = output_dir.value
|
| 79 |
-
dry_run_value = dry_run.value
|
| 80 |
-
|
| 81 |
-
# Call the script with the selected options
|
| 82 |
-
process_repos(output_dir_path, model, repo_list_file_path, dry_run_value)
|
| 83 |
-
|
| 84 |
-
# Link the button to the function
|
| 85 |
-
start_button.on_click(start_process)
|
| 86 |
-
|
| 87 |
-
# Create the UI
|
| 88 |
-
ui = pn.Column(
|
| 89 |
-
pn.Row(model_selector, repo_list_file, output_dir, dry_run),
|
| 90 |
-
start_button,
|
| 91 |
)
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
pn.extension("terminal", "notifications", notifications=True, design="bootstrap")
|
| 96 |
-
ui.servable()
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import subprocess
|
| 3 |
+
|
| 4 |
+
# Function to execute hf_merge.py with provided parameters
|
| 5 |
+
def run_hf_merge(repo_list, output_dir, staging='./staging', p=0.5, lambda_val=1.0, dry_run=False):
|
| 6 |
+
command = [
|
| 7 |
+
"python3", "hf_merge.py", repo_list, output_dir,
|
| 8 |
+
"-staging", staging, "-p", str(p), "-lambda", str(lambda_val)
|
| 9 |
+
]
|
| 10 |
+
if dry_run:
|
| 11 |
+
command.append("--dry")
|
| 12 |
+
|
| 13 |
+
result = subprocess.run(command, capture_output=True, text=True)
|
| 14 |
+
if result.returncode == 0:
|
| 15 |
+
return "Merge completed successfully.\n" + result.stdout
|
| 16 |
+
else:
|
| 17 |
+
return "Error during merge.\n" + result.stderr
|
| 18 |
+
|
| 19 |
+
# Gradio interface
|
| 20 |
+
interface = gr.Interface(
|
| 21 |
+
fn=run_hf_merge,
|
| 22 |
+
inputs=[
|
| 23 |
+
gr.Textbox(label="Repo List File"),
|
| 24 |
+
gr.Textbox(label="Output Directory"),
|
| 25 |
+
gr.Textbox(label="Staging Directory", value="./staging"),
|
| 26 |
+
gr.Number(label="Dropout Probability", value=0.5),
|
| 27 |
+
gr.Number(label="Scaling Factor", value=1.0),
|
| 28 |
+
gr.Checkbox(label="Dry Run")
|
| 29 |
+
],
|
| 30 |
+
outputs="text",
|
| 31 |
+
title="HuggingFace Model Merger",
|
| 32 |
+
description="Merge HuggingFace models using the technique described in 'Language Models are Super Mario: Absorbing Abilities from Homologous Models as a Free Lunch'."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
)
|
| 34 |
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
interface.launch()
|
|
|
|
|
|