Spaces:
Running
Running
Commit
•
8d55e8b
1
Parent(s):
74df29d
Update app.py
Browse files
app.py
CHANGED
@@ -69,13 +69,13 @@ def download_file(url, filename, folder="."):
|
|
69 |
except requests.exceptions.RequestException as e:
|
70 |
print(f"Error downloading file: {e}")
|
71 |
|
72 |
-
def process_url(url,
|
73 |
json_data = get_json_data(url)
|
74 |
if json_data:
|
75 |
if check_nsfw(json_data):
|
76 |
info = extract_info(json_data)
|
77 |
if info:
|
78 |
-
if(
|
79 |
downloaded_files = download_files(info, folder)
|
80 |
else:
|
81 |
downloaded_files = []
|
@@ -127,7 +127,7 @@ def upload_civit_to_hf(profile: Optional[gr.OAuthProfile], url, progress=gr.Prog
|
|
127 |
info, downloaded_files = process_url(url, folder)
|
128 |
create_readme(info, downloaded_files, folder)
|
129 |
try:
|
130 |
-
api = HfApi(token=
|
131 |
username = api.whoami()["name"]
|
132 |
slug_name = slugify(info["name"])
|
133 |
repo_id = f"{username}/{slug_name}"
|
@@ -137,9 +137,12 @@ def upload_civit_to_hf(profile: Optional[gr.OAuthProfile], url, progress=gr.Prog
|
|
137 |
repo_id=repo_id,
|
138 |
repo_type="model"
|
139 |
)
|
|
|
|
|
140 |
except:
|
141 |
raise gr.Error("something went wrong")
|
142 |
-
return
|
|
|
143 |
|
144 |
|
145 |
def get_creator(username):
|
@@ -245,7 +248,7 @@ with gr.Blocks(css=css) as demo:
|
|
245 |
instructions = gr.HTML("")
|
246 |
try_again_button = gr.Button("I have added my HF profile to my account", visible=False)
|
247 |
submit_button_civit = gr.Button("Upload model to Hugging Face", interactive=False)
|
248 |
-
output = gr.
|
249 |
|
250 |
demo.load(fn=swap_fill, outputs=[disabled_area, enabled_area])
|
251 |
submit_source_civit.change(fn=check_civit_link, inputs=[submit_source_civit], outputs=[instructions, submit_button_civit, try_again_button])
|
|
|
69 |
except requests.exceptions.RequestException as e:
|
70 |
print(f"Error downloading file: {e}")
|
71 |
|
72 |
+
def process_url(url, do_download=True, folder="."):
|
73 |
json_data = get_json_data(url)
|
74 |
if json_data:
|
75 |
if check_nsfw(json_data):
|
76 |
info = extract_info(json_data)
|
77 |
if info:
|
78 |
+
if(do_download):
|
79 |
downloaded_files = download_files(info, folder)
|
80 |
else:
|
81 |
downloaded_files = []
|
|
|
127 |
info, downloaded_files = process_url(url, folder)
|
128 |
create_readme(info, downloaded_files, folder)
|
129 |
try:
|
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}"
|
|
|
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 |
+
transfer_repos(repo_id, f"{profile.preferred_username}/{slug_name}")
|
142 |
except:
|
143 |
raise gr.Error("something went wrong")
|
144 |
+
return f'''### Model uploaded!
|
145 |
+
Access it here [{profile.preferred_username}/{slug_name}](https://huggingface.co/{profile.preferred_username}/{slug_name}) '''
|
146 |
|
147 |
|
148 |
def get_creator(username):
|
|
|
248 |
instructions = gr.HTML("")
|
249 |
try_again_button = gr.Button("I have added my HF profile to my account", visible=False)
|
250 |
submit_button_civit = gr.Button("Upload model to Hugging Face", interactive=False)
|
251 |
+
output = gr.Markdown(label="Output progress", visible=False)
|
252 |
|
253 |
demo.load(fn=swap_fill, outputs=[disabled_area, enabled_area])
|
254 |
submit_source_civit.change(fn=check_civit_link, inputs=[submit_source_civit], outputs=[instructions, submit_button_civit, try_again_button])
|