File size: 1,346 Bytes
357a87d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from huggingface_hub import HfApi, hf_hub_download, upload_file
import os

def copy_file(source_repo, target_repo, filename):
    token = os.getenv("HF_TOKEN")
    api = HfApi(token=token)

    try:
        # Download the file from the source repository
        downloaded_path = hf_hub_download(
            repo_id=source_repo,
            filename=filename,
            repo_type="model",
            token=token
        )

        # Upload the file to the target repository
        api.upload_file(
            path_or_fileobj=downloaded_path,
            path_in_repo=filename,
            repo_id=target_repo,
            repo_type="model"
        )

        return f"βœ… Successfully copied `{filename}` from `{source_repo}` to `{target_repo}`."

    except Exception as e:
        return f"❌ An error occurred: {str(e)}"

# Define the Gradio interface
gr.Interface(
    fn=copy_file,
    inputs=[
        gr.Textbox(label="Source Repository (e.g., username/source-repo)"),
        gr.Textbox(label="Target Repository (e.g., username/target-repo)"),
        gr.Textbox(label="Filename (e.g., model.gguf)")
    ],
    outputs=gr.Textbox(label="Operation Status"),
    title="Hugging Face Repository File Copier",
    description="Copy files between Hugging Face repositories without using local bandwidth."
).launch()