Rejekts commited on
Commit
6978e41
·
verified ·
1 Parent(s): 5ae2c60

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -2
app.py CHANGED
@@ -829,10 +829,15 @@ def save_wav(file):
829
  return None
830
 
831
  def download_from_url(url, model):
 
 
 
 
 
 
 
832
  if url == '':
833
  return "URL cannot be left empty."
834
- if model =='':
835
- return "You need to name your model. For example: My-Model"
836
  url = url.strip()
837
  zip_dirs = ["zips", "unzips"]
838
  for directory in zip_dirs:
@@ -843,6 +848,13 @@ def download_from_url(url, model):
843
  zipfile = model + '.zip'
844
  zipfile_path = './zips/' + zipfile
845
  try:
 
 
 
 
 
 
 
846
  if "drive.google.com" in url:
847
  subprocess.run(["gdown", url, "--fuzzy", "-O", zipfile_path])
848
  elif "mega.nz" in url:
 
829
  return None
830
 
831
  def download_from_url(url, model):
832
+ if model =='':
833
+ try:
834
+ model = url.split('/')[-1]
835
+ except:
836
+ return "You need to name your model. For example: My-Model"
837
+ url=url.replace('/blob/main/','/resolve/main/')
838
+ model=model.replace('.pth','').replace('.index','').replace('.zip','')
839
  if url == '':
840
  return "URL cannot be left empty."
 
 
841
  url = url.strip()
842
  zip_dirs = ["zips", "unzips"]
843
  for directory in zip_dirs:
 
848
  zipfile = model + '.zip'
849
  zipfile_path = './zips/' + zipfile
850
  try:
851
+ if url.endswith('.pth'):
852
+ subprocess.run(["wget", url, "-O", f'./assets/weights/{model}.pth'])
853
+ return f"Sucessfully downloaded as {model}.pth"
854
+ if url.endswith('.index'):
855
+ if not os.path.exists(f'./logs/{model}'): os.makedirs(f'./logs/{model}')
856
+ subprocess.run(["wget", url, "-O", f'./logs/{model}/added_{model}.index'])
857
+ return f"Successfully downloaded as added_{model}.index"
858
  if "drive.google.com" in url:
859
  subprocess.run(["gdown", url, "--fuzzy", "-O", zipfile_path])
860
  elif "mega.nz" in url: