Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import git
|
4 |
-
from huggingface_hub import snapshot_download
|
5 |
import shutil
|
6 |
|
7 |
# Function to clone a GitHub repository
|
@@ -19,21 +19,24 @@ def download_github_repo(repo_url):
|
|
19 |
except Exception as e:
|
20 |
return f"An error occurred: {str(e)}"
|
21 |
|
22 |
-
# Function to download a Hugging Face model or dataset
|
23 |
-
def download_huggingface_repo(repo_id):
|
24 |
try:
|
|
|
|
|
|
|
25 |
# Download the Hugging Face model or dataset snapshot
|
26 |
-
repo_path = snapshot_download(repo_id)
|
27 |
return f"Hugging Face repository '{repo_id}' downloaded successfully."
|
28 |
except Exception as e:
|
29 |
return f"An error occurred: {str(e)}"
|
30 |
|
31 |
# Gradio Interface
|
32 |
-
def download_repo(repo_type, repo_url_or_id):
|
33 |
if repo_type == "GitHub":
|
34 |
return download_github_repo(repo_url_or_id)
|
35 |
elif repo_type == "Hugging Face":
|
36 |
-
return download_huggingface_repo(repo_url_or_id)
|
37 |
else:
|
38 |
return "Invalid repository type selected."
|
39 |
|
@@ -42,11 +45,12 @@ interface = gr.Interface(
|
|
42 |
fn=download_repo,
|
43 |
inputs=[
|
44 |
gr.Radio(choices=["GitHub", "Hugging Face"], label="Repository Type"),
|
45 |
-
gr.Textbox(label="Repository URL (GitHub) or Repo ID (Hugging Face)")
|
|
|
46 |
],
|
47 |
outputs="text",
|
48 |
title="Repository Downloader",
|
49 |
-
description="Enter the GitHub repo URL or Hugging Face repo ID to download."
|
50 |
)
|
51 |
|
52 |
# Launch the app
|
|
|
1 |
import gradio as gr
|
2 |
import os
|
3 |
import git
|
4 |
+
from huggingface_hub import snapshot_download, login
|
5 |
import shutil
|
6 |
|
7 |
# Function to clone a GitHub repository
|
|
|
19 |
except Exception as e:
|
20 |
return f"An error occurred: {str(e)}"
|
21 |
|
22 |
+
# Function to download a Hugging Face model or dataset with authentication
|
23 |
+
def download_huggingface_repo(repo_id, hf_token):
|
24 |
try:
|
25 |
+
# Log in using the Hugging Face token
|
26 |
+
login(token=hf_token)
|
27 |
+
|
28 |
# Download the Hugging Face model or dataset snapshot
|
29 |
+
repo_path = snapshot_download(repo_id, token=hf_token)
|
30 |
return f"Hugging Face repository '{repo_id}' downloaded successfully."
|
31 |
except Exception as e:
|
32 |
return f"An error occurred: {str(e)}"
|
33 |
|
34 |
# Gradio Interface
|
35 |
+
def download_repo(repo_type, repo_url_or_id, hf_token=""):
|
36 |
if repo_type == "GitHub":
|
37 |
return download_github_repo(repo_url_or_id)
|
38 |
elif repo_type == "Hugging Face":
|
39 |
+
return download_huggingface_repo(repo_url_or_id, hf_token)
|
40 |
else:
|
41 |
return "Invalid repository type selected."
|
42 |
|
|
|
45 |
fn=download_repo,
|
46 |
inputs=[
|
47 |
gr.Radio(choices=["GitHub", "Hugging Face"], label="Repository Type"),
|
48 |
+
gr.Textbox(label="Repository URL (GitHub) or Repo ID (Hugging Face)"),
|
49 |
+
gr.Textbox(label="Hugging Face Token (Leave blank if accessing public repo)", type="password")
|
50 |
],
|
51 |
outputs="text",
|
52 |
title="Repository Downloader",
|
53 |
+
description="Enter the GitHub repo URL or Hugging Face repo ID to download. If using Hugging Face private repo, provide your access token."
|
54 |
)
|
55 |
|
56 |
# Launch the app
|