ykarout commited on
Commit
357a87d
·
verified ·
1 Parent(s): 5006602

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import HfApi, hf_hub_download, upload_file
3
+ import os
4
+
5
+ def copy_file(source_repo, target_repo, filename):
6
+ token = os.getenv("HF_TOKEN")
7
+ api = HfApi(token=token)
8
+
9
+ try:
10
+ # Download the file from the source repository
11
+ downloaded_path = hf_hub_download(
12
+ repo_id=source_repo,
13
+ filename=filename,
14
+ repo_type="model",
15
+ token=token
16
+ )
17
+
18
+ # Upload the file to the target repository
19
+ api.upload_file(
20
+ path_or_fileobj=downloaded_path,
21
+ path_in_repo=filename,
22
+ repo_id=target_repo,
23
+ repo_type="model"
24
+ )
25
+
26
+ return f"✅ Successfully copied `{filename}` from `{source_repo}` to `{target_repo}`."
27
+
28
+ except Exception as e:
29
+ return f"❌ An error occurred: {str(e)}"
30
+
31
+ # Define the Gradio interface
32
+ gr.Interface(
33
+ fn=copy_file,
34
+ inputs=[
35
+ gr.Textbox(label="Source Repository (e.g., username/source-repo)"),
36
+ gr.Textbox(label="Target Repository (e.g., username/target-repo)"),
37
+ gr.Textbox(label="Filename (e.g., model.gguf)")
38
+ ],
39
+ outputs=gr.Textbox(label="Operation Status"),
40
+ title="Hugging Face Repository File Copier",
41
+ description="Copy files between Hugging Face repositories without using local bandwidth."
42
+ ).launch()