Spaces:
Sleeping
Sleeping
| 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() | |