Update and #26
Browse files28 unmodified lines29303132333435363771 unmodified lines10911011111211311441 unmodified lines15615715815916016138 unmodified lines200201202203204205265 unmodified lines4714724734744754764779 unmodified lines48748848949049149249319 unmodified lines513514515516517518519520521101 unmodified lines62362462562662762862963063163263363463563663792 unmodified lines73073173273373473573673773873974074174274374474541 unmodified lines7877887897907917927935 unmodified lines79980080180280380480580680780880981081181281371 unmodified lines88588688788888989089189289345 unmodified lines9399409419429439449452 unmodified lines94894995095195295395495595695795895928 unmodified linesimport torchimport fairseqfrom picklescan.scanner import scan_file_pathALLOWED_DOMAINS = {"huggingface.co", "hf.co"}parser = argparse.ArgumentParser(description="Run the app with optional sharing")parser.add_argument(71 unmodified linesprint(f"Integrity check skipped for {file_path}: {e}")async def get_voices_list(proxy=None):"""Print all available voices."""from edge_tts import list_voices41 unmodified linescheck_model_safety(a_)return a_, b_txt_files = []for base_file in [a_, b_]:if base_file is not None and base_file.endswith(".txt"):38 unmodified linesif not index:gr.Warning("Index not found")return model, index265 unmodified linesaudio_effects,type_output,steps,play_audio=False,):if not audio_files:raise ValueError("The audio pls")9 unmodified linesif file_m is not None and (file_m.endswith(".txt") or file_m.endswith(".zip")):file_m, file_index = find_my_model(file_m, file_index)print(file_m, file_index)random_tag = "USER_"+str(random.randint(10000000, 99999999))19 unmodified linesif audio_effects:result = add_audio_effects(result, type_output)player_audio = result[0] if (play_audio and result and len(result) > 0) else Nonereturn result, player_audiodef audio_conf():101 unmodified lines)def active_tts_conf():return gr.Checkbox(False,label="TTS",# info="",container=False,)def tts_voice_conf():return gr.Dropdown(label="tts voice",92 unmodified linesreturn [out_path], player_audiodef show_components_tts(value_active):return gr.update(visible=value_active), gr.update(visible=value_active), gr.update(visible=value_active)def down_active_conf():return gr.Checkbox(False,41 unmodified linesgr.Markdown(title)gr.Markdown(description)active_tts = active_tts_conf()with gr.Row():with gr.Column(scale=1):tts_text = tts_text_conf()5 unmodified linestts_button = tts_button_conf()active_tts.change(fn=show_components_tts,inputs=[active_tts],outputs=[tts_voice, tts_text, tts_button],)aud = audio_conf()# gr.HTML("<hr>")down_active_gui = down_active_conf()down_info = gr.Markdown(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}`",71 unmodified lineseffects_gui,format_out,steps_gui,player_gui,],outputs=[output_base, player_audio],)gr.Examples(45 unmodified linesenvel_r,const,],outputs=[output_base, player_audio],cache_examples=False,)gr.Markdown(RESOURCES)2 unmodified linesif __name__ == "__main__":tts_voice_list = asyncio.new_event_loop().run_until_complete(get_voices_list(proxy=None))voices = sorted([(" - ".join(reversed(v["FriendlyName"].split("-"))).replace("Microsoft ", "").replace("Online (Natural)", f"({v['Gender']})").strip(), f"{v['ShortName']}-{v['Gender']}")for v in tts_voice_list])app = get_gui(theme)app.queue(default_concurrency_limit=40)28 unmodified lines293031323334353637383971 unmodified lines11111211311411511611711811912012112212312441 unmodified lines16616716816917017117217317417517617717817918018118218318418518618718818919019138 unmodified lines230231232233234235236237238265 unmodified lines5045055065075085099 unmodified lines51952052152252352452519 unmodified lines545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581101 unmodified lines68368468568668768892 unmodified lines78178278378478578678778878979079179279379479579679779879980080141 unmodified lines8438448458468478488495 unmodified lines85585685785885986086186286386486586686786886987087187287387487587671 unmodified lines94894995095195295395495595695795895996096196296396445 unmodified lines10101011101210131014101510162 unmodified lines101910201021102210231024102510261027102810291030103110321033103428 unmodified linesimport torchimport fairseqfrom picklescan.scanner import scan_file_pathimport hashlibALLOWED_DOMAINS = {"huggingface.co", "hf.co"}MODEL_CACHE = {}parser = argparse.ArgumentParser(description="Run the app with optional sharing")parser.add_argument(71 unmodified linesprint(f"Integrity check skipped for {file_path}: {e}")def get_file_hash(file_path: str) -> str:hasher = hashlib.sha256()with open(file_path, "rb") as f:while chunk := f.read(65536):hasher.update(chunk)return hasher.hexdigest()async def get_voices_list(proxy=None):"""Print all available voices."""from edge_tts import list_voices41 unmodified linescheck_model_safety(a_)return a_, b_input_hash = Noneif a_ and os.path.exists(a_):input_hash = get_file_hash(a_)if b_ and os.path.exists(b_):input_hash += "_" + get_file_hash(b_)if input_hash and input_hash in MODEL_CACHE:cached_model, cached_index = MODEL_CACHE[input_hash]model_exists = cached_model and os.path.exists(cached_model)index_exists = (cached_index is None) or os.path.exists(cached_index)if model_exists and index_exists:check_model_safety(cached_model)gr.Info(f"Model found: {cached_model}")if cached_index:gr.Info(f"Index found: {cached_index}")return cached_model, cached_indexelse:del MODEL_CACHE[input_hash]txt_files = []for base_file in [a_, b_]:if base_file is not None and base_file.endswith(".txt"):38 unmodified linesif not index:gr.Warning("Index not found")if model and input_hash:MODEL_CACHE[input_hash] = (model, index)return model, index265 unmodified linesaudio_effects,type_output,steps,):if not audio_files:raise ValueError("The audio pls")9 unmodified linesif file_m is not None and (file_m.endswith(".txt") or file_m.endswith(".zip")):file_m, file_index = find_my_model(file_m, file_index)# print(file_m, file_index)random_tag = "USER_"+str(random.randint(10000000, 99999999))19 unmodified linesif audio_effects:result = add_audio_effects(result, type_output)return resultdef clear_player():return Nonedef load_first_audio(output_files, play_audio):if not play_audio or not output_files:return Nonefirst_file = output_files[0]if isinstance(first_file, dict):first_file = first_file.get("name")return first_filedef audio_source_conf():return gr.Radio(choices=["📁 Upload", "🗣️ TTS", "🎙️ Record"],value="📁 Upload",label="Audio Source",)def mic_conf():return gr.Audio(sources=["microphone"],type="filepath",label="Record Audio",visible=False,)def audio_conf():101 unmodified lines)def tts_voice_conf():return gr.Dropdown(label="tts voice",92 unmodified linesreturn [out_path], player_audiodef show_components_source(mode):return (gr.update(visible=(mode == "🗣️ TTS")),gr.update(visible=(mode == "🗣️ TTS")),gr.update(visible=(mode == "🗣️ TTS")),gr.update(visible=(mode == "🎙️ Record")),)def sync_mic_audio(mic_path):if not mic_path:return Nonereturn [mic_path]def down_active_conf():return gr.Checkbox(False,41 unmodified linesgr.Markdown(title)gr.Markdown(description)audio_source = audio_source_conf()with gr.Row():with gr.Column(scale=1):tts_text = tts_text_conf()5 unmodified linestts_button = tts_button_conf()mic_aud = mic_conf()aud = audio_conf()# gr.HTML("<hr>")audio_source.change(fn=show_components_source,inputs=[audio_source],outputs=[tts_voice, tts_text, tts_button, mic_aud],)mic_aud.change(fn=sync_mic_audio,inputs=[mic_aud],outputs=[aud],)down_active_gui = down_active_conf()down_info = gr.Markdown(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}`",71 unmodified lineseffects_gui,format_out,steps_gui,],outputs=[output_base],).success(clear_player,inputs=None,outputs=[player_audio],queue=False,).success(load_first_audio,inputs=[output_base, player_gui],outputs=[player_audio],)gr.Examples(45 unmodified linesenvel_r,const,],outputs=[output_base],cache_examples=False,)gr.Markdown(RESOURCES)2 unmodified linesif __name__ == "__main__":try:tts_voice_list = asyncio.new_event_loop().run_until_complete(get_voices_list(proxy=None))voices = sorted([(" - ".join(reversed(v["FriendlyName"].split("-"))).replace("Microsoft ", "").replace("Online (Natural)", f"({v['Gender']})").strip(), f"{v['ShortName']}-{v['Gender']}")for v in tts_voice_list])except Exception as e:print(f"Warning: Could not retrieve online voices ({e}). Using default preset.")voices = [("English (United States) - EmmaMultilingual (Female)", "en-US-EmmaMultilingualNeural-Female")]app = get_gui(theme)app.queue(default_concurrency_limit=40)
app.py+111-36