fffiloni commited on
Commit
0a800aa
1 Parent(s): 4018f06

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -2,9 +2,13 @@ import gradio as gr
2
  import tempfile
3
  import os
4
  from git import Repo
 
 
5
 
6
 
7
  def process(git_repo_url, space_destination, user_token):
 
 
8
  # Create a temporary directory to clone the repository
9
  tmp_dir = tempfile.mkdtemp()
10
 
@@ -13,7 +17,7 @@ def process(git_repo_url, space_destination, user_token):
13
 
14
  # Log the contents of the tmp_dir with its subfolders
15
  print("Contents of the cloned repository:")
16
- for root, dirs, files in os.walk(tmp_dir):
17
  level = root.replace(tmp_dir, '').count(os.sep)
18
  indent = ' ' * 4 * level
19
  print(f"{indent}{os.path.basename(root)}/")
@@ -21,6 +25,12 @@ def process(git_repo_url, space_destination, user_token):
21
  for f in files:
22
  print(f"{sub_indent}{f}")
23
 
 
 
 
 
 
 
24
 
25
  return "hello"
26
 
 
2
  import tempfile
3
  import os
4
  from git import Repo
5
+ from huggingface_hub import HfApi, create_repo, upload_folder
6
+ api = HfApi()
7
 
8
 
9
  def process(git_repo_url, space_destination, user_token):
10
+ your_username = api.whoami(token=user_token)["name"]
11
+
12
  # Create a temporary directory to clone the repository
13
  tmp_dir = tempfile.mkdtemp()
14
 
 
17
 
18
  # Log the contents of the tmp_dir with its subfolders
19
  print("Contents of the cloned repository:")
20
+ for root, dirs, files in os.walk(repo):
21
  level = root.replace(tmp_dir, '').count(os.sep)
22
  indent = ' ' * 4 * level
23
  print(f"{indent}{os.path.basename(root)}/")
 
25
  for f in files:
26
  print(f"{sub_indent}{f}")
27
 
28
+ api.upload_folder(
29
+ folder_path=repo,
30
+ repo_id=space_destination,
31
+ repo_type="space",
32
+ token=user_token
33
+ )
34
 
35
  return "hello"
36