Spaces:
Sleeping
Sleeping
File size: 2,009 Bytes
1b621fc 0e69513 1b621fc 0e69513 6897b6a 1b621fc 6897b6a 1b621fc 6897b6a 1b621fc 6897b6a 0e69513 1b621fc 6897b6a 0e69513 1b621fc 6897b6a 0e69513 1b621fc 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 |
import gradio as gr
import subprocess
from huggingface_hub import HfApi, HfFolder
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.inputs.Slider(minimum=0, maximum=1, default=0.13, label="Weight Drop Probability"),
gr.inputs.Number(default=3.0, label="Scaling Factor"),
gr.inputs.Textbox(label="Base Model File/Folder"),
gr.inputs.Textbox(label="Model to Merge"),
gr.inputs.Textbox(label="Output Path"),
gr.inputs.Textbox(label="Hugging Face Repo Name"),
gr.inputs.Textbox(label="Hugging Face Token", type="password")
],
outputs="text",
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() |