Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -61,10 +61,15 @@ for file, link in files.items():
|
|
61 |
print(f"Error downloading {file}: {e}")
|
62 |
|
63 |
def download_from_url(url, model):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
if url == '':
|
65 |
return "URL cannot be left empty.", {"choices":show_available("assets/weights"),"__type__":"update"}
|
66 |
-
if model =='':
|
67 |
-
return "You need to name your model. For example: My-Model", {"choices":show_available("assets/weights"),"__type__":"update"}
|
68 |
url = url.strip()
|
69 |
zip_dirs = ["zips", "unzips"]
|
70 |
for directory in zip_dirs:
|
@@ -75,6 +80,13 @@ def download_from_url(url, model):
|
|
75 |
zipfile = model + '.zip'
|
76 |
zipfile_path = './zips/' + zipfile
|
77 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
if "drive.google.com" in url:
|
79 |
subprocess.run(["gdown", url, "--fuzzy", "-O", zipfile_path])
|
80 |
elif "mega.nz" in url:
|
@@ -101,7 +113,7 @@ def download_from_url(url, model):
|
|
101 |
return "Success.", {"choices":show_available("assets/weights"),"__type__":"update"}
|
102 |
except:
|
103 |
return "There's been an error.", {"choices":show_available("assets/weights"),"__type__":"update"}
|
104 |
-
|
105 |
def show_available(filepath,format=None):
|
106 |
if format:
|
107 |
print(f"Format: {format}")
|
|
|
61 |
print(f"Error downloading {file}: {e}")
|
62 |
|
63 |
def download_from_url(url, model):
|
64 |
+
if model =='':
|
65 |
+
try:
|
66 |
+
model = model.split('/')[-1].split('?')[0]
|
67 |
+
except:
|
68 |
+
return "You need to name your model. For example: My-Model", {"choices":show_available("assets/weights"),"__type__":"update"}
|
69 |
+
url=url.replace('/blob/main/','/resolve/main/')
|
70 |
+
model=model.replace('.pth','').replace('.index','').replace('.zip','')
|
71 |
if url == '':
|
72 |
return "URL cannot be left empty.", {"choices":show_available("assets/weights"),"__type__":"update"}
|
|
|
|
|
73 |
url = url.strip()
|
74 |
zip_dirs = ["zips", "unzips"]
|
75 |
for directory in zip_dirs:
|
|
|
80 |
zipfile = model + '.zip'
|
81 |
zipfile_path = './zips/' + zipfile
|
82 |
try:
|
83 |
+
if url.endswith('.pth'):
|
84 |
+
subprocess.run(["wget", url, "-O", f'./assets/weights/{model}.pth'])
|
85 |
+
return f"Sucessfully downloaded as {model}.pth", {"choices":show_available("assets/weights"),"__type__":"update"}
|
86 |
+
if url.endswith('.index'):
|
87 |
+
if not os.path.exists(f'./logs/{model}'): os.makedirs(f'./logs/{model}')
|
88 |
+
subprocess.run(["wget", url, "-O", f'./logs/{model}/added_{model}.index'])
|
89 |
+
return f"Successfully downloaded as added_{model}.index", {"choices":show_available("assets/weights"),"__type__":"update"}
|
90 |
if "drive.google.com" in url:
|
91 |
subprocess.run(["gdown", url, "--fuzzy", "-O", zipfile_path])
|
92 |
elif "mega.nz" in url:
|
|
|
113 |
return "Success.", {"choices":show_available("assets/weights"),"__type__":"update"}
|
114 |
except:
|
115 |
return "There's been an error.", {"choices":show_available("assets/weights"),"__type__":"update"}
|
116 |
+
|
117 |
def show_available(filepath,format=None):
|
118 |
if format:
|
119 |
print(f"Format: {format}")
|