Spaces:
Running
Running
Commit
·
b224f1d
1
Parent(s):
5158f4a
Update app.py
Browse files
app.py
CHANGED
@@ -130,19 +130,34 @@ def upload_civit_to_hf(profile: Optional[gr.OAuthProfile], url, progress=gr.Prog
|
|
130 |
api = HfApi(token=os.environ["HUGGING_FACE_HUB_TOKEN"])
|
131 |
username = api.whoami()["name"]
|
132 |
slug_name = slugify(info["name"])
|
133 |
-
repo_id = f"{username}/{slug_name}"
|
134 |
-
api.create_repo(repo_id=repo_id,
|
135 |
api.upload_folder(
|
136 |
folder_path=folder,
|
137 |
repo_id=repo_id,
|
138 |
repo_type="model"
|
139 |
)
|
140 |
-
transfer_repos = gr.load("multimodalart/transfer_repos", api_key=os.environ["HUGGING_FACE_HUB_TOKEN"])
|
141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
except:
|
143 |
raise gr.Error("something went wrong")
|
144 |
return f'''### Model uploaded!
|
145 |
-
Access it here [{
|
146 |
|
147 |
|
148 |
def get_creator(username):
|
|
|
130 |
api = HfApi(token=os.environ["HUGGING_FACE_HUB_TOKEN"])
|
131 |
username = api.whoami()["name"]
|
132 |
slug_name = slugify(info["name"])
|
133 |
+
repo_id = f"{username}/{profile.preferred_username}-{slug_name}"
|
134 |
+
api.create_repo(repo_id=repo_id, exist_ok=True)
|
135 |
api.upload_folder(
|
136 |
folder_path=folder,
|
137 |
repo_id=repo_id,
|
138 |
repo_type="model"
|
139 |
)
|
140 |
+
transfer_repos = gr.load("multimodalart/transfer_repos", api_key=os.environ["HUGGING_FACE_HUB_TOKEN"], src="spaces")
|
141 |
+
user_repo_id = f"{profile.preferred_username}/{slug_name}"
|
142 |
+
response_code = transfer_repos(repo_id, user_repo_id)
|
143 |
+
i = 0
|
144 |
+
while response_code != 200:
|
145 |
+
if response_code == 404:
|
146 |
+
raise gr.Error("Something went wrong with the model upload. Try again.")
|
147 |
+
elif response_code == 409 and i < 3:
|
148 |
+
user_repo_id = f"{profile.preferred_username}/{slug_name}-{i}"
|
149 |
+
response_code = transfer_repos(repo_id, user_repo_id)
|
150 |
+
i += 1
|
151 |
+
elif response_code == 409 and i >= 3:
|
152 |
+
raise gr.Error("It seems this model has been uploaded already in your account.")
|
153 |
+
else:
|
154 |
+
raise gr.Error(f"Unexpected response code: {response_code}.")
|
155 |
+
|
156 |
+
|
157 |
except:
|
158 |
raise gr.Error("something went wrong")
|
159 |
return f'''### Model uploaded!
|
160 |
+
Access it here [{user_repo_id}](https://huggingface.co/{user_repo_id}) '''
|
161 |
|
162 |
|
163 |
def get_creator(username):
|