Update app.py
Browse files
app.py
CHANGED
@@ -8,7 +8,15 @@ api = HfApi()
|
|
8 |
|
9 |
|
10 |
def process(git_repo_url, space_destination, user_token):
|
|
|
11 |
your_username = api.whoami(token=user_token)["name"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
# Create a temporary directory to clone the repository
|
14 |
tmp_dir = tempfile.mkdtemp()
|
@@ -39,6 +47,7 @@ def process(git_repo_url, space_destination, user_token):
|
|
39 |
# Check if the error is a "Repository Not Found" error
|
40 |
if "404 Client Error" in str(e) and "Repository Not Found" in str(e):
|
41 |
print("Repository not found. Maybe we should Create the repository...")
|
|
|
42 |
else:
|
43 |
# Re-raise the exception if it's not a "Repository Not Found" error
|
44 |
raise e
|
@@ -52,16 +61,18 @@ div#col-container{
|
|
52 |
|
53 |
with gr.Blocks(css=css) as demo:
|
54 |
with gr.Column(elem_id="col-container"):
|
|
|
55 |
git_repo_url = gr.Textbox(
|
56 |
label="Git repo to clone"
|
57 |
)
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
65 |
submit_btn = gr.Button("Clone git repo to my space")
|
66 |
status = gr.Textbox(
|
67 |
label="Status"
|
|
|
8 |
|
9 |
|
10 |
def process(git_repo_url, space_destination, user_token):
|
11 |
+
|
12 |
your_username = api.whoami(token=user_token)["name"]
|
13 |
+
|
14 |
+
# Check if space ID is correct including username
|
15 |
+
if str(your_username) in str(space_destination):
|
16 |
+
print "username is present: good to continue"
|
17 |
+
else:
|
18 |
+
space_destination = f"{your_username}/{space_destination}"
|
19 |
+
print "user forgot to mention his username in space_destination"
|
20 |
|
21 |
# Create a temporary directory to clone the repository
|
22 |
tmp_dir = tempfile.mkdtemp()
|
|
|
47 |
# Check if the error is a "Repository Not Found" error
|
48 |
if "404 Client Error" in str(e) and "Repository Not Found" in str(e):
|
49 |
print("Repository not found. Maybe we should Create the repository...")
|
50 |
+
return "Repository not found. Maybe we should Create the repository..."
|
51 |
else:
|
52 |
# Re-raise the exception if it's not a "Repository Not Found" error
|
53 |
raise e
|
|
|
61 |
|
62 |
with gr.Blocks(css=css) as demo:
|
63 |
with gr.Column(elem_id="col-container"):
|
64 |
+
gr.Markdown("# Clone GitHub repo to Space")
|
65 |
git_repo_url = gr.Textbox(
|
66 |
label="Git repo to clone"
|
67 |
)
|
68 |
+
with gr.Row():
|
69 |
+
space_destination = gr.Textbox(
|
70 |
+
label="Space ID"
|
71 |
+
)
|
72 |
+
user_token = gr.Textbox(
|
73 |
+
label="Write permissions token",
|
74 |
+
type="password"
|
75 |
+
)
|
76 |
submit_btn = gr.Button("Clone git repo to my space")
|
77 |
status = gr.Textbox(
|
78 |
label="Status"
|