Amirox commited on
Commit
d9a4295
·
1 Parent(s): 54f012e

Add safe logging functions and enhance URL handling in app.py; update requirements for Gradio

Browse files
Files changed (2) hide show
  1. app.py +65 -7
  2. requirements.txt +1 -1
app.py CHANGED
@@ -24,6 +24,34 @@ import threading
24
  import argparse
25
  import sys
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
  parser = argparse.ArgumentParser(description="Run the app with optional sharing")
28
  parser.add_argument(
29
  '--share',
@@ -152,16 +180,16 @@ def find_my_model(a_, b_):
152
  for ff in end_files:
153
  if ff.endswith(".pth"):
154
  model = os.path.join(directory, ff)
155
- gr.Info(f"Model found: {ff}")
156
  if ff.endswith(".index"):
157
  index = os.path.join(directory, ff)
158
- gr.Info(f"Index found: {ff}")
159
 
160
  if not model:
161
- gr.Error(f"Model not found in: {end_files}")
162
 
163
  if not index:
164
- gr.Warning("Index not found")
165
 
166
  return model, index
167
 
@@ -232,16 +260,16 @@ def get_my_model(url_data, progress=gr.Progress(track_tqdm=True)):
232
  for ff in end_files:
233
  if ff.endswith(".pth"):
234
  model = ff
235
- gr.Info(f"Model found: {ff}")
236
  if ff.endswith(".index"):
237
  index = ff
238
- gr.Info(f"Index found: {ff}")
239
 
240
  if not model:
241
  raise ValueError(f"Model not found in: {end_files}")
242
 
243
  if not index:
244
- gr.Warning("Index not found")
245
  else:
246
  index = os.path.abspath(index)
247
 
@@ -366,6 +394,27 @@ def run(
366
  type_output,
367
  steps,
368
  ):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
369
  if not audio_files:
370
  raise ValueError("The audio pls")
371
 
@@ -378,6 +427,14 @@ def run(
378
  except Exception as e:
379
  print(e)
380
 
 
 
 
 
 
 
 
 
381
  if file_m is not None and file_m.endswith(".txt"):
382
  file_m, file_index = find_my_model(file_m, file_index)
383
  print(file_m, file_index)
@@ -853,4 +910,5 @@ if __name__ == "__main__":
853
  quiet=False,
854
  debug=IS_COLAB,
855
  ssr_mode=False,
 
856
  )
 
24
  import argparse
25
  import sys
26
 
27
+ # Safe wrappers for gr.Info/Warning/Error that work in both UI and MCP contexts
28
+ def safe_info(message):
29
+ """Show info message in UI, log in MCP context."""
30
+ try:
31
+ gr.Info(message)
32
+ except Exception:
33
+ print(f"[INFO] {message}")
34
+
35
+ def safe_warning(message):
36
+ """Show warning in UI, log in MCP context."""
37
+ try:
38
+ gr.Warning(message)
39
+ except Exception:
40
+ print(f"[WARNING] {message}")
41
+
42
+ def safe_error(message):
43
+ """Show error in UI, log in MCP context."""
44
+ try:
45
+ gr.Error(message)
46
+ except Exception:
47
+ print(f"[ERROR] {message}")
48
+
49
+ def is_url(path):
50
+ """Check if path is a URL."""
51
+ if path is None:
52
+ return False
53
+ return isinstance(path, str) and path.strip().startswith(("http://", "https://"))
54
+
55
  parser = argparse.ArgumentParser(description="Run the app with optional sharing")
56
  parser.add_argument(
57
  '--share',
 
180
  for ff in end_files:
181
  if ff.endswith(".pth"):
182
  model = os.path.join(directory, ff)
183
+ safe_info(f"Model found: {ff}")
184
  if ff.endswith(".index"):
185
  index = os.path.join(directory, ff)
186
+ safe_info(f"Index found: {ff}")
187
 
188
  if not model:
189
+ safe_error(f"Model not found in: {end_files}")
190
 
191
  if not index:
192
+ safe_warning("Index not found")
193
 
194
  return model, index
195
 
 
260
  for ff in end_files:
261
  if ff.endswith(".pth"):
262
  model = ff
263
+ safe_info(f"Model found: {ff}")
264
  if ff.endswith(".index"):
265
  index = ff
266
+ safe_info(f"Index found: {ff}")
267
 
268
  if not model:
269
  raise ValueError(f"Model not found in: {end_files}")
270
 
271
  if not index:
272
+ safe_warning("Index not found")
273
  else:
274
  index = os.path.abspath(index)
275
 
 
394
  type_output,
395
  steps,
396
  ):
397
+ """
398
+ Convert audio files using RVC voice conversion.
399
+
400
+ Args:
401
+ audio_files: Audio file(s) to convert. Can be file path(s) or URL(s).
402
+ file_m: Model file (.pth) - can be a file path or URL to model/zip file.
403
+ pitch_alg: Pitch algorithm (pm, harvest, crepe, rmvpe, rmvpe+).
404
+ pitch_lvl: Pitch level adjustment (-24 to 24).
405
+ file_index: Index file (.index) - can be a file path or URL.
406
+ index_inf: Index influence (0 to 1).
407
+ r_m_f: Respiration median filtering (0 to 7).
408
+ e_r: Envelope ratio (0 to 1).
409
+ c_b_p: Consonant breath protection (0 to 0.5).
410
+ active_noise_reduce: Apply noise reduction.
411
+ audio_effects: Apply audio effects (reverb, compression).
412
+ type_output: Output format (wav, mp3, flac).
413
+ steps: Number of conversion steps (1 to 3).
414
+
415
+ Returns:
416
+ List of converted audio file paths.
417
+ """
418
  if not audio_files:
419
  raise ValueError("The audio pls")
420
 
 
427
  except Exception as e:
428
  print(e)
429
 
430
+ # Handle URL inputs for model and index files
431
+ if is_url(file_m) or is_url(file_index):
432
+ url_data = file_m if is_url(file_m) else ""
433
+ if is_url(file_index):
434
+ url_data = f"{url_data}, {file_index}" if url_data else file_index
435
+ file_m, file_index = get_my_model(url_data.strip(", "))
436
+ print(f"Downloaded model: {file_m}, index: {file_index}")
437
+
438
  if file_m is not None and file_m.endswith(".txt"):
439
  file_m, file_index = find_my_model(file_m, file_index)
440
  print(file_m, file_index)
 
910
  quiet=False,
911
  debug=IS_COLAB,
912
  ssr_mode=False,
913
+ mcp_server=True,
914
  )
requirements.txt CHANGED
@@ -6,6 +6,6 @@ noisereduce
6
  numpy==1.23.5
7
  transformers<=4.48.3
8
  pydantic==2.10.6
9
- gradio==5.43.1
10
  spaces
11
  matplotlib-inline
 
6
  numpy==1.23.5
7
  transformers<=4.48.3
8
  pydantic==2.10.6
9
+ gradio[mcp]==5.43.1
10
  spaces
11
  matplotlib-inline