Rejekts commited on
Commit
6f7d938
1 Parent(s): b53f2d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -16
app.py CHANGED
@@ -97,36 +97,38 @@ def download_from_url(url, model):
97
 
98
  def show_available(filepath,format=None):
99
  if format:
 
100
  files = []
101
  for file in os.listdir(filepath):
102
- if file in os.listdir(filepath).endswith(format):
 
103
  files.append(file)
 
 
 
104
  return files
105
  return os.listdir(filepath)
106
 
107
  def upload_file(file):
108
  audio_formats = ['.wav', '.mp3', '.ogg', '.flac', '.aac']
109
- _, ext = os.path.splitext(file.name)
110
- filename = os.path.basename(file.name)
111
- file_path = file.name
 
 
 
 
 
112
  if ext.lower() in audio_formats:
113
  if os.path.exists(f'audios/{filename}'):
114
  os.remove(f'audios/{filename}')
115
  shutil.move(file_path,'audios')
116
- elif ext.lower().endswith('.pth'):
117
- if os.path.exists(f'assets/weights/{filename}'):
118
- os.remove(f'assets/weights/{filename}')
119
- shutil.move(file_path,'assets/weights')
120
- elif ext.lower().endswith('.index'):
121
- if os.path.exists(f'logs/{filename}'):
122
- os.remove(f'logs/{filename}')
123
- shutil.move(file_path,'logs')
124
  else:
125
  gr.Warning('File incompatible')
126
- return {"choices":show_available('audios'),"__type__": "update"},{"choices":show_available('assets/weights'),"__type__": "update"},None
127
 
128
  def refresh():
129
- return {"choices":show_available('audios'),"__type__": "update"},{"choices":show_available('assets/weights'),"__type__": "update"}
130
 
131
  def update_audio_player(choice):
132
  return os.path.join("audios",choice)
@@ -150,10 +152,12 @@ with gr.Blocks() as app:
150
  with gr.Row():
151
  with gr.Tabs():
152
  with gr.TabItem("2.Choose an audio file:"):
 
153
  audio_picker = gr.Dropdown(label="",choices=show_available('audios'),value='',interactive=True)
 
154
  with gr.TabItem("(Or upload a new file here)"):
155
- dropbox = gr.File(label="Drop an audio here. (You can also drop a .pth or .index file here)")
156
- dropbox.upload(fn=upload_file, inputs=[dropbox],outputs=[audio_picker,model_picker,dropbox])
157
  audio_refresher = gr.Button("Refresh")
158
  audio_refresher.click(fn=refresh,inputs=[],outputs=[audio_picker,model_picker])
159
  convert_button = gr.Button("Convert")
 
97
 
98
  def show_available(filepath,format=None):
99
  if format:
100
+ print(f"Format: {format}")
101
  files = []
102
  for file in os.listdir(filepath):
103
+ if file.endswith(format):
104
+ print(f"Matches format: {file}")
105
  files.append(file)
106
+ else:
107
+ print(f"Does not match format: {file}")
108
+ print(f"Matches: {files}")
109
  return files
110
  return os.listdir(filepath)
111
 
112
  def upload_file(file):
113
  audio_formats = ['.wav', '.mp3', '.ogg', '.flac', '.aac']
114
+ try:
115
+ _, ext = os.path.splitext(file.name)
116
+ filename = os.path.basename(file.name)
117
+ file_path = file.name
118
+ except AttributeError:
119
+ _, ext = os.path.splitext(file)
120
+ filename = os.path.basename(file)
121
+ file_path = file
122
  if ext.lower() in audio_formats:
123
  if os.path.exists(f'audios/{filename}'):
124
  os.remove(f'audios/{filename}')
125
  shutil.move(file_path,'audios')
 
 
 
 
 
 
 
 
126
  else:
127
  gr.Warning('File incompatible')
128
+ return {"choices":show_available('audios'),"__type__": "update","value":filename}
129
 
130
  def refresh():
131
+ return {"choices":show_available("audios"),"__type__": "update"},{"choices":show_available("assets/weights",".pth"),"__type__": "update"}
132
 
133
  def update_audio_player(choice):
134
  return os.path.join("audios",choice)
 
152
  with gr.Row():
153
  with gr.Tabs():
154
  with gr.TabItem("2.Choose an audio file:"):
155
+ recorder = gr.Microphone(label="Record audio here...",type='filepath')
156
  audio_picker = gr.Dropdown(label="",choices=show_available('audios'),value='',interactive=True)
157
+ recorder.stop_recording(upload_file, inputs=[recorder],outputs=[audio_picker])
158
  with gr.TabItem("(Or upload a new file here)"):
159
+ dropbox = gr.Audio(label="Drop an audio here.",sources=['upload'])
160
+ dropbox.upload(fn=upload_file, inputs=[dropbox],outputs=[audio_picker])
161
  audio_refresher = gr.Button("Refresh")
162
  audio_refresher.click(fn=refresh,inputs=[],outputs=[audio_picker,model_picker])
163
  convert_button = gr.Button("Convert")