Rejekts commited on
Commit
fe96a3d
1 Parent(s): 5adbe94

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +89 -12
app.py CHANGED
@@ -8,9 +8,23 @@ os.environ['weight_root']="assets/weights"
8
  from infer.modules.vc.modules import VC
9
  from configs.config import Config
10
  import torch
 
 
11
  config = Config()
12
  vc = VC(config)
13
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  def load_model(model_picker,index_picker):
15
  logs = show_available("logs")
16
  if model_picker.replace(".pth","") in logs:
@@ -75,7 +89,7 @@ for file, link in files.items():
75
  subprocess.run(['wget', link, '-O', file_path], check=True)
76
  except subprocess.CalledProcessError as e:
77
  print(f"Error downloading {file}: {e}")
78
-
79
  def download_from_url(url, model):
80
  if model =='':
81
  try:
@@ -115,22 +129,81 @@ def download_from_url(url, model):
115
  if filename.endswith(".zip"):
116
  zipfile_path = os.path.join("./zips/",filename)
117
  shutil.unpack_archive(zipfile_path, "./unzips", 'zip')
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  else:
119
  return "No zipfile found.", {"choices":show_available("assets/weights"),"__type__":"update"}
120
- for root, dirs, files in os.walk('./unzips'):
121
- for file in files:
122
- file_path = os.path.join(root, file)
123
- if file.endswith(".index"):
124
- os.mkdir(f'./logs/{model}')
125
- shutil.copy2(file_path,f'./logs/{model}')
126
- elif "G_" not in file and "D_" not in file and file.endswith(".pth"):
127
- shutil.copy(file_path,f'./assets/weights/{model}.pth')
128
  shutil.rmtree("zips")
129
  shutil.rmtree("unzips")
130
  return "Success.", {"choices":show_available("assets/weights"),"__type__":"update"}
131
  except:
132
  return "There's been an error.", {"choices":show_available("assets/weights"),"__type__":"update"}
133
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
134
  def show_available(filepath,format=None):
135
  if format:
136
  print(f"Format: {format}")
@@ -177,9 +250,9 @@ def update_audio_player(choice):
177
  with gr.Blocks() as app:
178
  with gr.Row():
179
  with gr.Column():
180
- gr.HTML("<div><img src='file/a.png' alt='easyGUI'></div>")
181
  with gr.Column():
182
- gr.HTML("<a href='https://ko-fi.com/rejekts' target='_blank'><img src='file/kofi_button.png' alt='Support Me'></a>")
183
  with gr.Row():
184
  with gr.Column():
185
  with gr.Tabs():
@@ -196,6 +269,10 @@ with gr.Blocks() as app:
196
  with gr.Column():
197
  download_button = gr.Button("Download")
198
  download_button.click(fn=download_from_url,inputs=[url,model_rename],outputs=[url,model_picker])
 
 
 
 
199
  with gr.TabItem("Advanced"):
200
  index_rate = gr.Slider(label='Index Rate: ',minimum=0,maximum=1,value=0.66,step=0.01)
201
  pitch = gr.Slider(label='Pitch (-12 lowers it an octave, 0 keeps the original pitch, 12 lifts it an octave): ',minimum =-12, maximum=12, step=1, value=0, interactive=True)
@@ -219,4 +296,4 @@ with gr.Blocks() as app:
219
  audio_picker.change(fn=update_audio_player, inputs=[audio_picker],outputs=[audio_player])
220
  convert_button.click(convert, inputs=inputs,outputs=[audio_picker,audio_player])
221
 
222
- app.queue().launch()
 
8
  from infer.modules.vc.modules import VC
9
  from configs.config import Config
10
  import torch
11
+ import pandas as pd
12
+
13
  config = Config()
14
  vc = VC(config)
15
 
16
+ URL = "https://docs.google.com/spreadsheets/d/1tAUaQrEHYgRsm1Lvrnj14HFHDwJWl0Bd9x0QePewNco/edit#gid=1977693859"
17
+ csv_url = URL.replace('/edit#gid=', '/export?format=csv&gid=')
18
+ if os.path.exists("spreadsheet.csv"):
19
+ cached_data = pd.read_csv("spreadsheet.csv")
20
+ else:
21
+ cached_data = pd.read_csv(csv_url)
22
+ cached_data.to_csv("spreadsheet.csv", index=False)
23
+ models = {}
24
+
25
+ for url, filename in zip(cached_data['URL'], cached_data['Filename']):
26
+ models[filename] = url
27
+
28
  def load_model(model_picker,index_picker):
29
  logs = show_available("logs")
30
  if model_picker.replace(".pth","") in logs:
 
89
  subprocess.run(['wget', link, '-O', file_path], check=True)
90
  except subprocess.CalledProcessError as e:
91
  print(f"Error downloading {file}: {e}")
92
+
93
  def download_from_url(url, model):
94
  if model =='':
95
  try:
 
129
  if filename.endswith(".zip"):
130
  zipfile_path = os.path.join("./zips/",filename)
131
  shutil.unpack_archive(zipfile_path, "./unzips", 'zip')
132
+ for root, dirs, files in os.walk('./unzips'):
133
+ for file in files:
134
+ file_path = os.path.join(root, file)
135
+ if file.endswith(".index"):
136
+ os.mkdir(f'./logs/{model}')
137
+ shutil.copy2(file_path,f'./logs/{model}')
138
+ elif "G_" not in file and "D_" not in file and file.endswith(".pth"):
139
+ shutil.copy(file_path,f'./assets/weights/{model}.pth')
140
+ elif filename.endswith(".pth"):
141
+ shutil.copy2(os.path.join("./zips/",filename),f'./assets/weights/{model}.pth')
142
+ elif filename.endswith(".index"):
143
+ os.mkdir(f'./logs/{model}')
144
+ shutil.copy2(os.path.join("./zips/",filename),f'./logs/{model}/')
145
  else:
146
  return "No zipfile found.", {"choices":show_available("assets/weights"),"__type__":"update"}
 
 
 
 
 
 
 
 
147
  shutil.rmtree("zips")
148
  shutil.rmtree("unzips")
149
  return "Success.", {"choices":show_available("assets/weights"),"__type__":"update"}
150
  except:
151
  return "There's been an error.", {"choices":show_available("assets/weights"),"__type__":"update"}
152
 
153
+ def import_from_name(model):
154
+ try:
155
+ url = models[f'{model}']
156
+ except:
157
+ return "", {"__type__":"update"}
158
+ url=url.replace('/blob/main/','/resolve/main/')
159
+ print(f"Model name: {model}")
160
+ if url == '':
161
+ return "", {"__type__":"update"}
162
+ url = url.strip()
163
+ zip_dirs = ["zips", "unzips"]
164
+ for directory in zip_dirs:
165
+ if os.path.exists(directory):
166
+ shutil.rmtree(directory)
167
+ os.makedirs("zips", exist_ok=True)
168
+ os.makedirs("unzips", exist_ok=True)
169
+ zipfile = model + '.zip'
170
+ zipfile_path = './zips/' + zipfile
171
+ try:
172
+ if url.endswith('.pth'):
173
+ subprocess.run(["wget", url, "-O", f'./assets/weights/{model}.pth'])
174
+ return f"", {"choices":show_available("assets/weights"),"__type__":"update","value":f"{model}.pth"}
175
+ if "drive.google.com" in url:
176
+ subprocess.run(["gdown", url, "--fuzzy", "-O", zipfile_path])
177
+ elif "mega.nz" in url:
178
+ m = Mega()
179
+ m.download_url(url, './zips')
180
+ else:
181
+ subprocess.run(["wget", url, "-O", zipfile_path])
182
+ for filename in os.listdir("./zips"):
183
+ if filename.endswith(".zip"):
184
+ zipfile_path = os.path.join("./zips/",filename)
185
+ shutil.unpack_archive(zipfile_path, "./unzips", 'zip')
186
+ for root, dirs, files in os.walk('./unzips'):
187
+ for file in files:
188
+ file_path = os.path.join(root, file)
189
+ if file.endswith(".index"):
190
+ os.mkdir(f'./logs/{model}')
191
+ shutil.copy2(file_path,f'./logs/{model}')
192
+ elif "G_" not in file and "D_" not in file and file.endswith(".pth"):
193
+ shutil.copy(file_path,f'./assets/weights/{model}.pth')
194
+ elif filename.endswith(".pth"):
195
+ shutil.copy2(os.path.join("./zips/",filename),f'./assets/weights/{model}.pth')
196
+ elif filename.endswith(".index"):
197
+ os.mkdir(f'./logs/{model}')
198
+ shutil.copy2(os.path.join("./zips/",filename),f'./logs/{model}/')
199
+ else:
200
+ return "", {"__type__":"update"}
201
+ shutil.rmtree("zips")
202
+ shutil.rmtree("unzips")
203
+ return "", {"choices":show_available("assets/weights"),"__type__":"update","value":f"{model}.pth"}
204
+ except:
205
+ return "", {"__type__":"update"}
206
+
207
  def show_available(filepath,format=None):
208
  if format:
209
  print(f"Format: {format}")
 
250
  with gr.Blocks() as app:
251
  with gr.Row():
252
  with gr.Column():
253
+ gr.Markdown("# 📱 EasyGUI PlayGround")
254
  with gr.Column():
255
+ gr.HTML("<a href='https://ko-fi.com/rejekts' target='_blank'><img src='file/kofi_button.png' alt='🤝 Support Me'></a>")
256
  with gr.Row():
257
  with gr.Column():
258
  with gr.Tabs():
 
269
  with gr.Column():
270
  download_button = gr.Button("Download")
271
  download_button.click(fn=download_from_url,inputs=[url,model_rename],outputs=[url,model_picker])
272
+ with gr.Row():
273
+ selected_import = gr.Dropdown(choices=list(models.keys())[:999],label="OR Search Models (Quality UNKNOWN)",scale=5)
274
+ import_model = gr.Button("Download")
275
+ import_model.click(fn=import_from_name,inputs=[selected_import],outputs=[selected_import,model_picker])
276
  with gr.TabItem("Advanced"):
277
  index_rate = gr.Slider(label='Index Rate: ',minimum=0,maximum=1,value=0.66,step=0.01)
278
  pitch = gr.Slider(label='Pitch (-12 lowers it an octave, 0 keeps the original pitch, 12 lifts it an octave): ',minimum =-12, maximum=12, step=1, value=0, interactive=True)
 
296
  audio_picker.change(fn=update_audio_player, inputs=[audio_picker],outputs=[audio_player])
297
  convert_button.click(convert, inputs=inputs,outputs=[audio_picker,audio_player])
298
 
299
+ app.queue().launch(debug=True)