mobenta commited on
Commit
8ef2cda
·
verified ·
1 Parent(s): 8fa5b77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -19,9 +19,14 @@ 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 Space or model/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
 
@@ -37,11 +42,11 @@ def download_huggingface_repo(repo_id, hf_token):
37
  return f"An error occurred: {str(e)}"
38
 
39
  # Gradio Interface
40
- def download_repo(repo_type, repo_url_or_id, hf_token=""):
41
  if repo_type == "GitHub":
42
  return download_github_repo(repo_url_or_id)
43
  elif repo_type == "Hugging Face":
44
- return download_huggingface_repo(repo_url_or_id, hf_token)
45
  else:
46
  return "Invalid repository type selected."
47
 
@@ -50,12 +55,11 @@ interface = gr.Interface(
50
  fn=download_repo,
51
  inputs=[
52
  gr.Radio(choices=["GitHub", "Hugging Face"], label="Repository Type"),
53
- gr.Textbox(label="Repository URL (GitHub) or Repo ID (Hugging Face)"),
54
- gr.Textbox(label="Hugging Face Token (Leave blank if accessing public repo)", type="password")
55
  ],
56
  outputs="text",
57
  title="Repository Downloader",
58
- description="Enter the GitHub repo URL or Hugging Face repo ID to download. If using Hugging Face private repo, provide your access token."
59
  )
60
 
61
  # Launch the app
 
19
  except Exception as e:
20
  return f"An error occurred: {str(e)}"
21
 
22
+ # Function to download a Hugging Face Space or model/dataset using an environment variable for the token
23
+ def download_huggingface_repo(repo_id):
24
  try:
25
+ # Get Hugging Face token from environment variable
26
+ hf_token = os.getenv("HF_TOKEN")
27
+ if hf_token is None:
28
+ return "Hugging Face token not found. Please set the HF_TOKEN environment variable."
29
+
30
  # Log in using the Hugging Face token
31
  login(token=hf_token)
32
 
 
42
  return f"An error occurred: {str(e)}"
43
 
44
  # Gradio Interface
45
+ def download_repo(repo_type, repo_url_or_id):
46
  if repo_type == "GitHub":
47
  return download_github_repo(repo_url_or_id)
48
  elif repo_type == "Hugging Face":
49
+ return download_huggingface_repo(repo_url_or_id)
50
  else:
51
  return "Invalid repository type selected."
52
 
 
55
  fn=download_repo,
56
  inputs=[
57
  gr.Radio(choices=["GitHub", "Hugging Face"], label="Repository Type"),
58
+ gr.Textbox(label="Repository URL (GitHub) or Repo ID (Hugging Face)")
 
59
  ],
60
  outputs="text",
61
  title="Repository Downloader",
62
+ description="Enter the GitHub repo URL or Hugging Face repo ID to download."
63
  )
64
 
65
  # Launch the app