File size: 1,992 Bytes
1b621fc
 
03295cc
c282e5d
1b621fc
c282e5d
0e69513
6897b6a
1b621fc
6897b6a
 
 
 
1b621fc
6897b6a
 
1b621fc
6897b6a
0e69513
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b621fc
6897b6a
 
0e69513
1b621fc
03295cc
 
 
 
 
 
 
1b621fc
03295cc
0e69513
 
9867227
 
6897b6a
 
1
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import gradio as gr
import subprocess
from huggingface_hub import HfApi
import spaces

@spaces.GPU
def merge_and_upload(weight_drop_prob, scaling_factor, base_model, model_to_merge, output_path, repo_name, token):
    # Construct the command to run hf_merge.py
    command = [
        "python3", "hf_merge.py",
        "-p", str(weight_drop_prob),
        "-lambda", str(scaling_factor),
        base_model, model_to_merge, output_path
    ]
    
    # Run the command and capture the output
    result = subprocess.run(command, capture_output=True, text=True)
    
    # Check if the merge was successful
    if result.returncode != 0:
        return f"Error in merging models: {result.stderr}"
    
    # Upload the result to Hugging Face Hub
    api = HfApi()
    try:
        # Create a new repo or update an existing one
        api.create_repo(repo_id=repo_name, token=token, exist_ok=True)
        
        # Upload the file
        api.upload_file(
            path_or_fileobj=output_path,
            path_in_repo=output_path.split('/')[-1],
            repo_id=repo_name,
            token=token
        )
        return f"Model merged and uploaded successfully to {repo_name}!"
    except Exception as e:
        return f"Error uploading to Hugging Face Hub: {str(e)}"

# Define the Gradio interface
iface = gr.Interface(
    fn=merge_and_upload,
    inputs=[
        gr.Slider(minimum=0, maximum=1, value=0.13, label="Weight Drop Probability"),
        gr.Number(value=3.0, label="Scaling Factor"),
        gr.Textbox(label="Base Model File/Folder"),
        gr.Textbox(label="Model to Merge"),
        gr.Textbox(label="Output Path"),
        gr.Textbox(label="Hugging Face Repo Name"),
        gr.Textbox(label="Hugging Face Token", type="password")
    ],
    outputs=gr.Textbox(label="Output"),
    title="Model Merger and Uploader",
    description="Merge two models using the Super Mario merge method and upload to Hugging Face Hub."
)

# Launch the interface
iface.launch()