Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
-
import
|
4 |
|
5 |
-
|
6 |
-
def merge_models(weight_drop_prob, scaling_factor, base_model, model_to_merge, output_path):
|
7 |
# Construct the command to run hf_merge.py
|
8 |
command = [
|
9 |
"python3", "hf_merge.py",
|
@@ -15,22 +14,42 @@ def merge_models(weight_drop_prob, scaling_factor, base_model, model_to_merge, o
|
|
15 |
# Run the command and capture the output
|
16 |
result = subprocess.run(command, capture_output=True, text=True)
|
17 |
|
18 |
-
#
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
# Define the Gradio interface
|
22 |
iface = gr.Interface(
|
23 |
-
fn=
|
24 |
inputs=[
|
25 |
gr.inputs.Slider(minimum=0, maximum=1, default=0.13, label="Weight Drop Probability"),
|
26 |
gr.inputs.Number(default=3.0, label="Scaling Factor"),
|
27 |
gr.inputs.Textbox(label="Base Model File/Folder"),
|
28 |
gr.inputs.Textbox(label="Model to Merge"),
|
29 |
-
gr.inputs.Textbox(label="Output Path")
|
|
|
|
|
30 |
],
|
31 |
outputs="text",
|
32 |
-
title="Model Merger",
|
33 |
-
description="Merge two models using the Super Mario merge method."
|
34 |
)
|
35 |
|
36 |
# Launch the interface
|
|
|
1 |
import gradio as gr
|
2 |
import subprocess
|
3 |
+
from huggingface_hub import HfApi, HfFolder
|
4 |
|
5 |
+
def merge_and_upload(weight_drop_prob, scaling_factor, base_model, model_to_merge, output_path, repo_name, token):
|
|
|
6 |
# Construct the command to run hf_merge.py
|
7 |
command = [
|
8 |
"python3", "hf_merge.py",
|
|
|
14 |
# Run the command and capture the output
|
15 |
result = subprocess.run(command, capture_output=True, text=True)
|
16 |
|
17 |
+
# Check if the merge was successful
|
18 |
+
if result.returncode != 0:
|
19 |
+
return f"Error in merging models: {result.stderr}"
|
20 |
+
|
21 |
+
# Upload the result to Hugging Face Hub
|
22 |
+
api = HfApi()
|
23 |
+
try:
|
24 |
+
# Create a new repo or update an existing one
|
25 |
+
api.create_repo(repo_id=repo_name, token=token, exist_ok=True)
|
26 |
+
|
27 |
+
# Upload the file
|
28 |
+
api.upload_file(
|
29 |
+
path_or_fileobj=output_path,
|
30 |
+
path_in_repo=output_path.split('/')[-1],
|
31 |
+
repo_id=repo_name,
|
32 |
+
token=token
|
33 |
+
)
|
34 |
+
return f"Model merged and uploaded successfully to {repo_name}!"
|
35 |
+
except Exception as e:
|
36 |
+
return f"Error uploading to Hugging Face Hub: {str(e)}"
|
37 |
|
38 |
# Define the Gradio interface
|
39 |
iface = gr.Interface(
|
40 |
+
fn=merge_and_upload,
|
41 |
inputs=[
|
42 |
gr.inputs.Slider(minimum=0, maximum=1, default=0.13, label="Weight Drop Probability"),
|
43 |
gr.inputs.Number(default=3.0, label="Scaling Factor"),
|
44 |
gr.inputs.Textbox(label="Base Model File/Folder"),
|
45 |
gr.inputs.Textbox(label="Model to Merge"),
|
46 |
+
gr.inputs.Textbox(label="Output Path"),
|
47 |
+
gr.inputs.Textbox(label="Hugging Face Repo Name"),
|
48 |
+
gr.inputs.Textbox(label="Hugging Face Token", type="password")
|
49 |
],
|
50 |
outputs="text",
|
51 |
+
title="Model Merger and Uploader",
|
52 |
+
description="Merge two models using the Super Mario merge method and upload to Hugging Face Hub."
|
53 |
)
|
54 |
|
55 |
# Launch the interface
|