Update app.py
Browse files
app.py
CHANGED
|
@@ -248,37 +248,33 @@ def get_my_model(url_data, progress=gr.Progress(track_tqdm=True)):
|
|
| 248 |
t.start()
|
| 249 |
|
| 250 |
|
| 251 |
-
# ========== नया फ़ंक्शन: logs फोल्डर से मॉडल
|
| 252 |
def scan_models():
|
| 253 |
-
"""logs/ फोल्डर के अंदर
|
| 254 |
logs_dir = "logs"
|
| 255 |
if not os.path.isdir(logs_dir):
|
| 256 |
return []
|
| 257 |
-
|
| 258 |
models = []
|
| 259 |
for model_name in os.listdir(logs_dir):
|
| 260 |
model_path = os.path.join(logs_dir, model_name)
|
| 261 |
if not os.path.isdir(model_path):
|
| 262 |
continue
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
index_file = os.path.join(model_path, index_candidates[0])
|
| 274 |
-
else:
|
| 275 |
-
continue # इस फोल्डर में जरूरी फाइलें नहीं हैं
|
| 276 |
-
models.append((model_name, pth_file, index_file))
|
| 277 |
return models
|
| 278 |
|
| 279 |
|
| 280 |
-
def
|
| 281 |
-
"""
|
| 282 |
models = scan_models()
|
| 283 |
for name, pth, idx in models:
|
| 284 |
if name == model_name:
|
|
@@ -321,14 +317,14 @@ def add_audio_effects(audio_list, type_output):
|
|
| 321 |
result.append(output_path)
|
| 322 |
except Exception as e:
|
| 323 |
traceback.print_exc()
|
| 324 |
-
print(f"Error
|
| 325 |
result.append(audio_path)
|
| 326 |
|
| 327 |
return result
|
| 328 |
|
| 329 |
|
| 330 |
def apply_noisereduce(audio_list, type_output):
|
| 331 |
-
print("
|
| 332 |
|
| 333 |
result = []
|
| 334 |
for audio_path in audio_list:
|
|
@@ -336,14 +332,12 @@ def apply_noisereduce(audio_list, type_output):
|
|
| 336 |
|
| 337 |
try:
|
| 338 |
audio = AudioSegment.from_file(audio_path)
|
| 339 |
-
|
| 340 |
samples = np.array(audio.get_array_of_samples())
|
| 341 |
-
|
| 342 |
reduced_noise = nr.reduce_noise(samples, sr=audio.frame_rate, prop_decrease=0.6)
|
| 343 |
|
| 344 |
reduced_audio = AudioSegment(
|
| 345 |
-
reduced_noise.tobytes(),
|
| 346 |
-
frame_rate=audio.frame_rate,
|
| 347 |
sample_width=audio.sample_width,
|
| 348 |
channels=audio.channels
|
| 349 |
)
|
|
@@ -369,16 +363,15 @@ def convert_now(audio_files, random_tag, converter, type_output, steps):
|
|
| 369 |
parallel_workers=(2 if IS_COLAB else 8),
|
| 370 |
type_output=type_output,
|
| 371 |
)
|
| 372 |
-
|
| 373 |
return audio_files
|
| 374 |
|
| 375 |
|
| 376 |
def run(
|
| 377 |
audio_files,
|
| 378 |
-
file_m,
|
| 379 |
pitch_alg,
|
| 380 |
pitch_lvl,
|
| 381 |
-
file_index,
|
| 382 |
index_inf,
|
| 383 |
r_m_f,
|
| 384 |
e_r,
|
|
@@ -389,7 +382,7 @@ def run(
|
|
| 389 |
steps,
|
| 390 |
):
|
| 391 |
if not audio_files:
|
| 392 |
-
raise ValueError("
|
| 393 |
|
| 394 |
if isinstance(audio_files, str):
|
| 395 |
audio_files = [audio_files]
|
|
@@ -400,12 +393,11 @@ def run(
|
|
| 400 |
except Exception as e:
|
| 401 |
print(e)
|
| 402 |
|
| 403 |
-
# अगर file_m टेक्स्ट फाइल है तो पुराने लॉजिक से हैंडल करें
|
| 404 |
if file_m is not None and file_m.endswith(".txt"):
|
| 405 |
file_m, file_index = find_my_model(file_m, file_index)
|
| 406 |
print(file_m, file_index)
|
| 407 |
|
| 408 |
-
random_tag = "USER_"+str(random.randint(10000000, 99999999))
|
| 409 |
|
| 410 |
converter.apply_conf(
|
| 411 |
tag=random_tag,
|
|
@@ -432,7 +424,7 @@ def run(
|
|
| 432 |
return result
|
| 433 |
|
| 434 |
|
| 435 |
-
# ========== UI कॉन्फ़िगरेशन
|
| 436 |
|
| 437 |
def audio_conf():
|
| 438 |
return gr.File(
|
|
@@ -444,21 +436,20 @@ def audio_conf():
|
|
| 444 |
|
| 445 |
|
| 446 |
def model_dropdown_conf():
|
| 447 |
-
"""मॉडल चुनने के लिए ड्रॉपडाउन बनाएँ"""
|
| 448 |
models = scan_models()
|
| 449 |
choices = [name for name, _, _ in models]
|
| 450 |
return gr.Dropdown(
|
|
|
|
| 451 |
choices=choices,
|
| 452 |
value=choices[0] if choices else None,
|
| 453 |
-
label="Select Model",
|
| 454 |
interactive=True,
|
| 455 |
)
|
| 456 |
|
| 457 |
|
| 458 |
-
# ये दो छुपे हुए टेक्स्टबॉक्स हैं जिनमें असली फाइल पथ जाएँगे
|
| 459 |
def hidden_model_path_conf():
|
| 460 |
return gr.Textbox(visible=False)
|
| 461 |
|
|
|
|
| 462 |
def hidden_index_path_conf():
|
| 463 |
return gr.Textbox(visible=False)
|
| 464 |
|
|
@@ -551,9 +542,9 @@ def active_tts_conf():
|
|
| 551 |
def tts_voice_conf():
|
| 552 |
return gr.Dropdown(
|
| 553 |
label="tts voice",
|
| 554 |
-
choices=
|
| 555 |
visible=False,
|
| 556 |
-
value=
|
| 557 |
)
|
| 558 |
|
| 559 |
|
|
@@ -613,6 +604,7 @@ def format_output_gui():
|
|
| 613 |
value="wav",
|
| 614 |
)
|
| 615 |
|
|
|
|
| 616 |
def denoise_conf():
|
| 617 |
return gr.Checkbox(
|
| 618 |
False,
|
|
@@ -633,7 +625,7 @@ def effects_conf():
|
|
| 633 |
|
| 634 |
def infer_tts_audio(tts_voice, tts_text, play_tts):
|
| 635 |
out_dir = "output"
|
| 636 |
-
folder_tts = "USER_"+str(random.randint(10000, 99999))
|
| 637 |
|
| 638 |
os.makedirs(out_dir, exist_ok=True)
|
| 639 |
os.makedirs(os.path.join(out_dir, folder_tts), exist_ok=True)
|
|
@@ -646,14 +638,11 @@ def infer_tts_audio(tts_voice, tts_text, play_tts):
|
|
| 646 |
|
| 647 |
|
| 648 |
def show_components_tts(value_active):
|
| 649 |
-
return
|
| 650 |
-
visible=value_active
|
| 651 |
-
|
| 652 |
-
visible=value_active
|
| 653 |
-
|
| 654 |
-
visible=value_active
|
| 655 |
-
), gr.update(
|
| 656 |
-
visible=value_active
|
| 657 |
)
|
| 658 |
|
| 659 |
|
|
@@ -684,12 +673,10 @@ def down_button_conf():
|
|
| 684 |
|
| 685 |
|
| 686 |
def show_components_down(value_active):
|
| 687 |
-
return
|
| 688 |
-
visible=value_active
|
| 689 |
-
|
| 690 |
-
visible=value_active
|
| 691 |
-
), gr.update(
|
| 692 |
-
visible=value_active
|
| 693 |
)
|
| 694 |
|
| 695 |
|
|
@@ -703,12 +690,13 @@ CSS = """
|
|
| 703 |
}
|
| 704 |
"""
|
| 705 |
|
|
|
|
| 706 |
def get_gui(theme):
|
| 707 |
with gr.Blocks(theme=theme, css=CSS, fill_width=True, fill_height=False, delete_cache=delete_cache_time) as app:
|
| 708 |
gr.Markdown(title)
|
| 709 |
gr.Markdown(description)
|
| 710 |
|
| 711 |
-
# ===== TTS सेक्शन
|
| 712 |
active_tts = active_tts_conf()
|
| 713 |
with gr.Row():
|
| 714 |
with gr.Column(scale=1):
|
|
@@ -737,7 +725,28 @@ def get_gui(theme):
|
|
| 737 |
outputs=[aud, tts_play],
|
| 738 |
)
|
| 739 |
|
| 740 |
-
# ===== URL-to-Model सेक्शन
|
| 741 |
down_active_gui = down_active_conf()
|
| 742 |
down_info = gr.Markdown(
|
| 743 |
-
f"Provide a link to a zip file, like this one: `https://huggingface.co/MrDawg/ToothBrushing/resolve/main/ToothBrushing.zip?download=true`, or
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
t.start()
|
| 249 |
|
| 250 |
|
| 251 |
+
# ========== नया फ़ंक्शन: logs/ फोल्डर से सभी मॉडल स्कैन करें ==========
|
| 252 |
def scan_models():
|
| 253 |
+
"""logs/ फोल्डर के अंदर हर सबफोल्डर को एक मॉडल मानें और उसकी .pth व .index फाइलें ढूंढें।"""
|
| 254 |
logs_dir = "logs"
|
| 255 |
if not os.path.isdir(logs_dir):
|
| 256 |
return []
|
| 257 |
+
|
| 258 |
models = []
|
| 259 |
for model_name in os.listdir(logs_dir):
|
| 260 |
model_path = os.path.join(logs_dir, model_name)
|
| 261 |
if not os.path.isdir(model_path):
|
| 262 |
continue
|
| 263 |
+
|
| 264 |
+
# फोल्डर के अंदर .pth और .index फाइलें देखें
|
| 265 |
+
pth_files = [f for f in os.listdir(model_path) if f.endswith(".pth")]
|
| 266 |
+
index_files = [f for f in os.listdir(model_path) if f.endswith(".index")]
|
| 267 |
+
|
| 268 |
+
if pth_files and index_files:
|
| 269 |
+
# पहली मिलने वाली फाइल ले लें (या आप नाम से मिलान कर सकते हैं)
|
| 270 |
+
pth_path = os.path.join(model_path, pth_files[0])
|
| 271 |
+
index_path = os.path.join(model_path, index_files[0])
|
| 272 |
+
models.append((model_name, pth_path, index_path))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
return models
|
| 274 |
|
| 275 |
|
| 276 |
+
def update_model_paths(model_name):
|
| 277 |
+
"""चुने गए मॉडल के अनुसार pth और index के पूरे पथ लौटाएँ।"""
|
| 278 |
models = scan_models()
|
| 279 |
for name, pth, idx in models:
|
| 280 |
if name == model_name:
|
|
|
|
| 317 |
result.append(output_path)
|
| 318 |
except Exception as e:
|
| 319 |
traceback.print_exc()
|
| 320 |
+
print(f"Error audio effects: {str(e)}")
|
| 321 |
result.append(audio_path)
|
| 322 |
|
| 323 |
return result
|
| 324 |
|
| 325 |
|
| 326 |
def apply_noisereduce(audio_list, type_output):
|
| 327 |
+
print("Noise reduce")
|
| 328 |
|
| 329 |
result = []
|
| 330 |
for audio_path in audio_list:
|
|
|
|
| 332 |
|
| 333 |
try:
|
| 334 |
audio = AudioSegment.from_file(audio_path)
|
|
|
|
| 335 |
samples = np.array(audio.get_array_of_samples())
|
|
|
|
| 336 |
reduced_noise = nr.reduce_noise(samples, sr=audio.frame_rate, prop_decrease=0.6)
|
| 337 |
|
| 338 |
reduced_audio = AudioSegment(
|
| 339 |
+
reduced_noise.tobytes(),
|
| 340 |
+
frame_rate=audio.frame_rate,
|
| 341 |
sample_width=audio.sample_width,
|
| 342 |
channels=audio.channels
|
| 343 |
)
|
|
|
|
| 363 |
parallel_workers=(2 if IS_COLAB else 8),
|
| 364 |
type_output=type_output,
|
| 365 |
)
|
|
|
|
| 366 |
return audio_files
|
| 367 |
|
| 368 |
|
| 369 |
def run(
|
| 370 |
audio_files,
|
| 371 |
+
file_m,
|
| 372 |
pitch_alg,
|
| 373 |
pitch_lvl,
|
| 374 |
+
file_index,
|
| 375 |
index_inf,
|
| 376 |
r_m_f,
|
| 377 |
e_r,
|
|
|
|
| 382 |
steps,
|
| 383 |
):
|
| 384 |
if not audio_files:
|
| 385 |
+
raise ValueError("Please provide audio files")
|
| 386 |
|
| 387 |
if isinstance(audio_files, str):
|
| 388 |
audio_files = [audio_files]
|
|
|
|
| 393 |
except Exception as e:
|
| 394 |
print(e)
|
| 395 |
|
|
|
|
| 396 |
if file_m is not None and file_m.endswith(".txt"):
|
| 397 |
file_m, file_index = find_my_model(file_m, file_index)
|
| 398 |
print(file_m, file_index)
|
| 399 |
|
| 400 |
+
random_tag = "USER_" + str(random.randint(10000000, 99999999))
|
| 401 |
|
| 402 |
converter.apply_conf(
|
| 403 |
tag=random_tag,
|
|
|
|
| 424 |
return result
|
| 425 |
|
| 426 |
|
| 427 |
+
# ========== UI कॉन्फ़िगरेशन ==========
|
| 428 |
|
| 429 |
def audio_conf():
|
| 430 |
return gr.File(
|
|
|
|
| 436 |
|
| 437 |
|
| 438 |
def model_dropdown_conf():
|
|
|
|
| 439 |
models = scan_models()
|
| 440 |
choices = [name for name, _, _ in models]
|
| 441 |
return gr.Dropdown(
|
| 442 |
+
label="Select Model",
|
| 443 |
choices=choices,
|
| 444 |
value=choices[0] if choices else None,
|
|
|
|
| 445 |
interactive=True,
|
| 446 |
)
|
| 447 |
|
| 448 |
|
|
|
|
| 449 |
def hidden_model_path_conf():
|
| 450 |
return gr.Textbox(visible=False)
|
| 451 |
|
| 452 |
+
|
| 453 |
def hidden_index_path_conf():
|
| 454 |
return gr.Textbox(visible=False)
|
| 455 |
|
|
|
|
| 542 |
def tts_voice_conf():
|
| 543 |
return gr.Dropdown(
|
| 544 |
label="tts voice",
|
| 545 |
+
choices=[],
|
| 546 |
visible=False,
|
| 547 |
+
value=None,
|
| 548 |
)
|
| 549 |
|
| 550 |
|
|
|
|
| 604 |
value="wav",
|
| 605 |
)
|
| 606 |
|
| 607 |
+
|
| 608 |
def denoise_conf():
|
| 609 |
return gr.Checkbox(
|
| 610 |
False,
|
|
|
|
| 625 |
|
| 626 |
def infer_tts_audio(tts_voice, tts_text, play_tts):
|
| 627 |
out_dir = "output"
|
| 628 |
+
folder_tts = "USER_" + str(random.randint(10000, 99999))
|
| 629 |
|
| 630 |
os.makedirs(out_dir, exist_ok=True)
|
| 631 |
os.makedirs(os.path.join(out_dir, folder_tts), exist_ok=True)
|
|
|
|
| 638 |
|
| 639 |
|
| 640 |
def show_components_tts(value_active):
|
| 641 |
+
return (
|
| 642 |
+
gr.update(visible=value_active),
|
| 643 |
+
gr.update(visible=value_active),
|
| 644 |
+
gr.update(visible=value_active),
|
| 645 |
+
gr.update(visible=value_active),
|
|
|
|
|
|
|
|
|
|
| 646 |
)
|
| 647 |
|
| 648 |
|
|
|
|
| 673 |
|
| 674 |
|
| 675 |
def show_components_down(value_active):
|
| 676 |
+
return (
|
| 677 |
+
gr.update(visible=value_active),
|
| 678 |
+
gr.update(visible=value_active),
|
| 679 |
+
gr.update(visible=value_active),
|
|
|
|
|
|
|
| 680 |
)
|
| 681 |
|
| 682 |
|
|
|
|
| 690 |
}
|
| 691 |
"""
|
| 692 |
|
| 693 |
+
|
| 694 |
def get_gui(theme):
|
| 695 |
with gr.Blocks(theme=theme, css=CSS, fill_width=True, fill_height=False, delete_cache=delete_cache_time) as app:
|
| 696 |
gr.Markdown(title)
|
| 697 |
gr.Markdown(description)
|
| 698 |
|
| 699 |
+
# ===== TTS सेक्शन =====
|
| 700 |
active_tts = active_tts_conf()
|
| 701 |
with gr.Row():
|
| 702 |
with gr.Column(scale=1):
|
|
|
|
| 725 |
outputs=[aud, tts_play],
|
| 726 |
)
|
| 727 |
|
| 728 |
+
# ===== URL-to-Model सेक्शन =====
|
| 729 |
down_active_gui = down_active_conf()
|
| 730 |
down_info = gr.Markdown(
|
| 731 |
+
f"Provide a link to a zip file, like this one: `https://huggingface.co/MrDawg/ToothBrushing/resolve/main/ToothBrushing.zip?download=true`, or separate links with a comma for the .pth and .index files, like this: `{test_model}`",
|
| 732 |
+
visible=False
|
| 733 |
+
)
|
| 734 |
+
with gr.Row():
|
| 735 |
+
with gr.Column(scale=3):
|
| 736 |
+
down_url_gui = down_url_conf()
|
| 737 |
+
with gr.Column(scale=1):
|
| 738 |
+
down_button_gui = down_button_conf()
|
| 739 |
+
|
| 740 |
+
# ये हैं असली मॉडल पथ वाले छुप��� हुए टेक्स्टबॉक्स
|
| 741 |
+
hidden_model_path = hidden_model_path_conf()
|
| 742 |
+
hidden_index_path = hidden_index_path_conf()
|
| 743 |
+
|
| 744 |
+
down_active_gui.change(
|
| 745 |
+
show_components_down,
|
| 746 |
+
[down_active_gui],
|
| 747 |
+
[down_info, down_url_gui, down_button_gui]
|
| 748 |
+
)
|
| 749 |
+
|
| 750 |
+
# जब URL से मॉडल डाउनलोड हो, तो उसके पथ छुपे हुए टेक्स्टबॉक्स में डालें
|
| 751 |
+
def update_from_url(url_data):
|
| 752 |
+
model_path, index_path = get_my_model
|