Rejekts commited on
Commit
b94e79b
1 Parent(s): 707ed34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -53,9 +53,9 @@ for file, link in files.items():
53
 
54
  def download_from_url(url, model):
55
  if url == '':
56
- return "URL cannot be left empty."
57
  if model =='':
58
- return "You need to name your model. For example: My-Model"
59
  url = url.strip()
60
  zip_dirs = ["zips", "unzips"]
61
  for directory in zip_dirs:
@@ -78,7 +78,7 @@ def download_from_url(url, model):
78
  zipfile_path = os.path.join("./zips/",filename)
79
  shutil.unpack_archive(zipfile_path, "./unzips", 'zip')
80
  else:
81
- return "No zipfile found."
82
  for root, dirs, files in os.walk('./unzips'):
83
  for file in files:
84
  file_path = os.path.join(root, file)
@@ -89,9 +89,9 @@ def download_from_url(url, model):
89
  shutil.copy(file_path,f'./assets/weights/{model}.pth')
90
  shutil.rmtree("zips")
91
  shutil.rmtree("unzips")
92
- return "Success."
93
  except:
94
- return "There's been an error."
95
 
96
  def show_available(filepath):
97
  return os.listdir(filepath)
@@ -137,7 +137,7 @@ with gr.Blocks() as app:
137
  model_rename = gr.Textbox(placeholder="My-Model", label="Name your model:",value="")
138
  with gr.Column():
139
  download_button = gr.Button("Download")
140
- download_button.click(fn=download_from_url,inputs=[url,model_rename],outputs=[url])
141
 
142
  with gr.Row():
143
  with gr.Tabs():
 
53
 
54
  def download_from_url(url, model):
55
  if url == '':
56
+ return "URL cannot be left empty.", {"choices":show_available("assets/weights"),"__type__":"update"}
57
  if model =='':
58
+ return "You need to name your model. For example: My-Model", {"choices":show_available("assets/weights"),"__type__":"update"}
59
  url = url.strip()
60
  zip_dirs = ["zips", "unzips"]
61
  for directory in zip_dirs:
 
78
  zipfile_path = os.path.join("./zips/",filename)
79
  shutil.unpack_archive(zipfile_path, "./unzips", 'zip')
80
  else:
81
+ return "No zipfile found.", {"choices":show_available("assets/weights"),"__type__":"update"}
82
  for root, dirs, files in os.walk('./unzips'):
83
  for file in files:
84
  file_path = os.path.join(root, file)
 
89
  shutil.copy(file_path,f'./assets/weights/{model}.pth')
90
  shutil.rmtree("zips")
91
  shutil.rmtree("unzips")
92
+ return "Success.", {"choices":show_available("assets/weights"),"__type__":"update"}
93
  except:
94
+ return "There's been an error.", {"choices":show_available("assets/weights"),"__type__":"update"}
95
 
96
  def show_available(filepath):
97
  return os.listdir(filepath)
 
137
  model_rename = gr.Textbox(placeholder="My-Model", label="Name your model:",value="")
138
  with gr.Column():
139
  download_button = gr.Button("Download")
140
+ download_button.click(fn=download_from_url,inputs=[url,model_rename],outputs=[url,model_picker])
141
 
142
  with gr.Row():
143
  with gr.Tabs():