Spaces:
Running
Running
Commit
•
a1c95a9
1
Parent(s):
5e31c93
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import requests
|
2 |
import os
|
3 |
import gradio as gr
|
4 |
-
from huggingface_hub import HfApi
|
5 |
from slugify import slugify
|
6 |
import gradio as gr
|
7 |
import uuid
|
@@ -130,33 +130,40 @@ def upload_civit_to_hf(profile: Optional[gr.OAuthProfile], url, progress=gr.Prog
|
|
130 |
username = api.whoami()["name"]
|
131 |
slug_name = slugify(info["name"])
|
132 |
repo_id = f"{username}/{profile.preferred_username}-{slug_name}"
|
133 |
-
api.create_repo(repo_id=repo_id, exist_ok=True)
|
134 |
api.upload_folder(
|
135 |
folder_path=folder,
|
136 |
repo_id=repo_id,
|
137 |
-
repo_type="model"
|
138 |
)
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
|
|
|
|
|
|
|
|
147 |
user_repo_id = f"{profile.preferred_username}/{slug_name}-{i}"
|
148 |
response_code = transfer_repos(repo_id, user_repo_id)
|
149 |
i += 1
|
150 |
-
elif response_code == "409" and i >= 3:
|
151 |
-
raise gr.Error("It seems this model has been uploaded already in your account.")
|
152 |
else:
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
|
155 |
-
|
156 |
-
|
157 |
-
raise gr.Error("something went wrong")
|
158 |
-
return f'''### Model uploaded!
|
159 |
-
Access it here [{user_repo_id}](https://huggingface.co/{user_repo_id}) '''
|
160 |
|
161 |
|
162 |
def get_creator(username):
|
|
|
1 |
import requests
|
2 |
import os
|
3 |
import gradio as gr
|
4 |
+
from huggingface_hub import HfApi, update_repo_visibility
|
5 |
from slugify import slugify
|
6 |
import gradio as gr
|
7 |
import uuid
|
|
|
130 |
username = api.whoami()["name"]
|
131 |
slug_name = slugify(info["name"])
|
132 |
repo_id = f"{username}/{profile.preferred_username}-{slug_name}"
|
133 |
+
api.create_repo(repo_id=repo_id, private=True, exist_ok=True)
|
134 |
api.upload_folder(
|
135 |
folder_path=folder,
|
136 |
repo_id=repo_id,
|
137 |
+
repo_type="model",
|
138 |
)
|
139 |
+
api.update_repo_visibility(repo_id=repo_id, private=False)
|
140 |
+
except:
|
141 |
+
raise gr.Error("something went wrong")
|
142 |
+
|
143 |
+
transfer_repos = gr.load("multimodalart/transfer_repos", hf_token=os.environ["HUGGING_FACE_HUB_TOKEN"], src="spaces")
|
144 |
+
user_repo_id = f"{profile.preferred_username}/{slug_name}"
|
145 |
+
response_code = transfer_repos(repo_id, user_repo_id)
|
146 |
+
i = 0
|
147 |
+
while response_code != "200":
|
148 |
+
message = None
|
149 |
+
if response_code == "409":
|
150 |
+
if i < 3:
|
151 |
user_repo_id = f"{profile.preferred_username}/{slug_name}-{i}"
|
152 |
response_code = transfer_repos(repo_id, user_repo_id)
|
153 |
i += 1
|
|
|
|
|
154 |
else:
|
155 |
+
message = "It seems this model has been uploaded already in your account."
|
156 |
+
elif response_code == "404":
|
157 |
+
message = "Something went wrong with the model upload. Try again."
|
158 |
+
else:
|
159 |
+
message = f"Unexpected response code: {response_code}."
|
160 |
+
|
161 |
+
if message:
|
162 |
+
api.delete_repo(repo_id=repo_id, repo_type="model")
|
163 |
+
raise gr.Error(message)
|
164 |
|
165 |
+
return f'''# Model uploaded to 🤗!
|
166 |
+
## Access it here [{user_repo_id}](https://huggingface.co/{user_repo_id}) '''
|
|
|
|
|
|
|
167 |
|
168 |
|
169 |
def get_creator(username):
|