umair007 commited on
Commit
4677e57
·
1 Parent(s): 302674c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -75
app.py CHANGED
@@ -10,55 +10,6 @@ from safetensors.torch import save_file, load_file
10
  from huggingface_hub import model_info, create_repo, create_branch, upload_folder
11
  from huggingface_hub.utils import RepositoryNotFoundError, RevisionNotFoundError
12
 
13
- def check_link(torrent_url):
14
- if torrent_url.endswith('.torrent') or torrent_url.startswith('magnet:?xt=urn:btih:'):
15
- return True
16
- else:
17
- return False
18
-
19
- def download_torrent(torrent_url):
20
- # Create the file directory if it doesn't exist
21
- os.makedirs("torrent", exist_ok=True)
22
- if check_link(torrent_url):
23
- # command to download torrent file
24
- command = os.system(f"aria2c --enable-dht --dir=torrent --summary-interval=10 --seed-ratio=0.1 --allow-overwrite=true {torrent_url}")
25
- return "download torrent done!"
26
- else:
27
- # command to download regular file
28
- command = os.system(f"aria2c --dir=torrent --summary-interval=10 -c -x 10 -k 1M -s 10 {torrent_url}")
29
- return "download torrent done!"
30
- subprocess.run(command, shell=True)
31
-
32
- def push_torrent(model_to, token, branch):
33
- try:
34
- repo_exists = True
35
- r_info = model_info(model_to, token=token)
36
- except RepositoryNotFoundError:
37
- repo_exists = False
38
- finally:
39
- if repo_exists:
40
- print(r_info)
41
- else:
42
- create_repo(model_to, private=True, token=token)
43
- try:
44
- branch_exists = True
45
- b_info = model_info(model_to, revision=branch, token=token)
46
- except RevisionNotFoundError:
47
- branch_exists = False
48
- finally:
49
- if branch_exists:
50
- print(b_info)
51
- else:
52
- create_branch(model_to, branch=branch, token=token)
53
- # Create the torrent directory if it doesn't exist
54
- os.makedirs("torrent", exist_ok=True)
55
- upload_folder(folder_path="torrent", path_in_repo="", revision=branch, repo_id=model_to, commit_message=f"torrent", token=token)
56
- return "push torrent done!"
57
-
58
- def delete_torrent():
59
- os.system(f"rm -rf torrent")
60
- return "delete torrent done!"
61
-
62
  def download_file(file_url_1, file_name_1):
63
  # Create the file directory if it doesn't exist
64
  os.makedirs("file", exist_ok=True)
@@ -370,6 +321,7 @@ with block:
370
  """
371
 
372
  ## 🚨 Please first click all delete buttons 🚨 🎉<br />
 
373
  ## Almost all Download site link works<br />
374
  ### Special thanks to [@camenduru](https://huggingface.co/camenduru) for creating initial script <br />
375
  ### Modified By [@umair007](https://huggingface.co/umair007)<br />
@@ -427,32 +379,7 @@ with block:
427
  btn_delete_file = gr.Button("Delete file")
428
  btn_download_file.click(download_file, inputs=[text_file_url_1, text_file_name_1], outputs=out_file)
429
  btn_push_file_1.click(push_file_1, inputs=[text_file_model_to, text_file_token, text_file_branch], outputs=out_file)
430
- btn_delete_file.click(delete_file, outputs=out_file)
431
-
432
- gr.Markdown(
433
- """
434
- ### download and push torrent file <br />
435
- ckpt_url = example.com/file.torrent<br />
436
- folder_name = openjourney <br />
437
- ckpt_model_to = camenduru/openjourney <br />
438
- branch = torrent <br />
439
- token = get from [https://huggingface.co/settings/tokens](https://huggingface.co/settings/tokens) new token role=write <br />
440
- """)
441
- with gr.Group():
442
- with gr.Box():
443
- with gr.Row().style(equal_height=True):
444
- text_torrent_url = gr.Textbox(show_label=False, max_lines=1, placeholder="torrent_url")
445
- text_torrent_model_to = gr.Textbox(show_label=False, max_lines=1, placeholder="torrent_model_to")
446
- text_torrent_branch = gr.Textbox(show_label=False, value="torrent", max_lines=1, placeholder="torrent_branch")
447
- text_torrent_token = gr.Textbox(show_label=False, max_lines=1, placeholder="🤗 token")
448
- out_torrent = gr.Textbox(show_label=False)
449
- with gr.Row().style(equal_height=True):
450
- btn_download_torrent = gr.Button("Download torrent")
451
- btn_push_torrent = gr.Button("Push torrent to 🤗")
452
- btn_delete_torrent = gr.Button("Delete torrent")
453
- btn_download_torrent.click(download_torrent, inputs=[text_torrent_url], outputs=out_torrent)
454
- btn_push_torrent.click(push_torrent, inputs=[text_torrent_model_to, text_torrent_token, text_torrent_branch], outputs=out_torrent)
455
- btn_delete_torrent.click(delete_torrent, outputs=out_torrent)
456
 
457
  gr.Markdown(
458
  """
 
10
  from huggingface_hub import model_info, create_repo, create_branch, upload_folder
11
  from huggingface_hub.utils import RepositoryNotFoundError, RevisionNotFoundError
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  def download_file(file_url_1, file_name_1):
14
  # Create the file directory if it doesn't exist
15
  os.makedirs("file", exist_ok=True)
 
321
  """
322
 
323
  ## 🚨 Please first click all delete buttons 🚨 🎉<br />
324
+ ##Using aria2c for better downloading
325
  ## Almost all Download site link works<br />
326
  ### Special thanks to [@camenduru](https://huggingface.co/camenduru) for creating initial script <br />
327
  ### Modified By [@umair007](https://huggingface.co/umair007)<br />
 
379
  btn_delete_file = gr.Button("Delete file")
380
  btn_download_file.click(download_file, inputs=[text_file_url_1, text_file_name_1], outputs=out_file)
381
  btn_push_file_1.click(push_file_1, inputs=[text_file_model_to, text_file_token, text_file_branch], outputs=out_file)
382
+ btn_delete_file.click(delete_file, outputs=out_file)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
 
384
  gr.Markdown(
385
  """