Download app.py from easyadaptor/Voice-Matcher-AI: direct link, hf CLI and curl.
- Browser
- Download file 18.6 kB
-
https://huggingface.co/spaces/easyadaptor/Voice-Matcher-AI/resolve/main/app.py
- Command line
-
hf download hf://spaces/easyadaptor/Voice-Matcher-AI/app.py
-
curl -L -o app.py https://huggingface.co/spaces/easyadaptor/Voice-Matcher-AI/resolve/main/app.py
18.6 kB
| import gradio as gr | |
| import librosa | |
| import numpy as np | |
| import torch | |
| import os | |
| import json | |
| import base64 | |
| import tempfile | |
| import soundfile as sf | |
| from datetime import datetime | |
| from speechbrain.inference import EncoderClassifier | |
| from huggingface_hub import login | |
| from datasets import load_dataset, Dataset | |
| # 1. ์ด๊ธฐ ์ธํ ๋ฐ ํ ํฐ ๋ก๊ทธ์ธ | |
| HF_TOKEN = os.environ.get("HF_TOKEN") | |
| if HF_TOKEN: | |
| login(token=HF_TOKEN) | |
| DATASET_REPO = "easyadaptor/Voice-Matcher-DB" | |
| # 2. ํ์ ์๋ฒ ๋ฉ ๋ชจ๋ธ ๋ก๋ (SpeechBrain) | |
| classifier = EncoderClassifier.from_hparams( | |
| source="speechbrain/spkrec-ecapa-voxceleb", | |
| savedir="pretrained_models/spkrec-ecapa-voxceleb" | |
| ) | |
| # 3. ์ค๋์ค ํน์ฑ ์๋ ์ถ์ถ ํจ์ | |
| def extract_audio_features(file_path): | |
| y, sr = librosa.load(file_path, sr=16000) | |
| onset_env = librosa.onset.onset_strength(y=y, sr=sr) | |
| tempo, _ = librosa.beat.beat_track(onset_envelope=onset_env, sr=sr) | |
| pitches, _ = librosa.piptrack(y=y, sr=sr) | |
| mean_pitch = np.mean(pitches[pitches > 0]) if np.any(pitches > 0) else 0 | |
| tags =[] | |
| if mean_pitch > 200: tags.append("์ฒญ์ํ ๊ณ ์") | |
| elif mean_pitch < 120: tags.append("๋ฌต์งํ ์ ์") | |
| else: tags.append("์์ ์ ์ธ ์ค์") | |
| if tempo > 130: tags.append("๋น ๋ฅด๊ณ ๊ฒฝ์พํ ํ ํฌ") | |
| elif tempo < 100: tags.append("์ฐจ๋ถํ๊ณ ๋๋ฆฐ ํ ํฌ") | |
| else: tags.append("์ ๋นํ ํ ํฌ") | |
| return tags | |
| # 4.[๊ด๋ฆฌ์์ฉ] ๋ค์ค ํ์ผ ๋์ ์ ๋ก๋ ๋ฐ ๋ณํฉ ๋ก์ง | |
| def register_voice(actor_name, audio_files, gender, age, atmosphere, content): | |
| if not actor_name: | |
| return "์ฑ์ฐ ์ด๋ฆ์ ์ ๋ ฅํด์ฃผ์ธ์." | |
| if not audio_files: | |
| return "์ต์ 1๊ฐ ์ด์์ ์ค๋์ค ํ์ผ์ ์ ๋ก๋ํด์ฃผ์ธ์." | |
| try: | |
| combined_y =[] | |
| for f in audio_files: | |
| y, sr = librosa.load(f, sr=16000) | |
| combined_y.append(y) | |
| final_signal_np = np.concatenate(combined_y, axis=0) | |
| temp_audio = tempfile.NamedTemporaryFile(delete=False, suffix=".wav") | |
| sf.write(temp_audio.name, final_signal_np, 16000) | |
| combined_audio_path = temp_audio.name | |
| auto_tags = extract_audio_features(combined_audio_path) | |
| y_final, sr_final = librosa.load(combined_audio_path, sr=16000) | |
| signal = torch.tensor(y_final).unsqueeze(0) | |
| embedding = classifier.encode_batch(signal).squeeze().tolist() | |
| with open(combined_audio_path, "rb") as f: | |
| audio_b64 = base64.b64encode(f.read()).decode("utf-8") | |
| new_data = { | |
| "actor_name":[actor_name], | |
| "tags":[json.dumps(auto_tags)], | |
| "embedding":[json.dumps(embedding)], | |
| "registered_at":[datetime.now().strftime("%Y-%m-%d %H:%M:%S")], | |
| "audio_b64":[audio_b64], | |
| "gender":[gender if gender else ""], | |
| "age":[age if age else ""], | |
| "atmosphere":[json.dumps(atmosphere if atmosphere else [])], | |
| "content":[json.dumps(content if content else [])] | |
| } | |
| try: | |
| ds = load_dataset(DATASET_REPO, split="train") | |
| if actor_name in ds["actor_name"]: | |
| ds = ds.filter(lambda x: x["actor_name"] != actor_name) | |
| msg_prefix = "๐[์ ๋ณด ์์ ]" | |
| else: | |
| msg_prefix = "โ [์ ๊ท ๋ฑ๋ก]" | |
| new_ds = Dataset.from_dict(new_data) | |
| from datasets import concatenate_datasets | |
| updated_ds = concatenate_datasets([ds, new_ds]) | |
| except Exception: | |
| updated_ds = Dataset.from_dict(new_data) | |
| msg_prefix = "โ [์ ๊ท ๋ฑ๋ก]" | |
| updated_ds.push_to_hub(DATASET_REPO, token=HF_TOKEN) | |
| return f"{msg_prefix} ์๋ฃ![{actor_name}] ์ฑ์ฐ์ ์ ๋ณด๊ฐ ๋ฐ์๋์์ต๋๋ค." | |
| except Exception as e: | |
| return f"โ ์ค๋ฅ ๋ฐ์: {str(e)}" | |
| # 5.[์ฌ์ฉ์์ฉ] ์ ์ฌ๋ ๋ถ์ ๋ฐ ๊ฒฐ๊ณผ ์ค๋์ค ๋ฐํ | |
| def match_voice(user_audio): | |
| if user_audio is None: | |
| return "๋ถ์ํ ์ค๋์ค๋ฅผ ์ ๋ก๋ํ๊ฑฐ๋ ๋ น์ํด์ฃผ์ธ์.", "", None | |
| target_audio = user_audio | |
| try: | |
| user_tags = extract_audio_features(target_audio) | |
| y_user, sr_user = librosa.load(target_audio, sr=16000) | |
| signal = torch.tensor(y_user).unsqueeze(0) | |
| user_embedding = classifier.encode_batch(signal).squeeze() | |
| except Exception as e: | |
| return f"โ ์ค๋์ค ๋ถ์์ ์คํจํ์ต๋๋ค. ์ ํจํ ์์ฑ์ธ์ง ํ์ธํด์ฃผ์ธ์.\n(์๋ฌ: {str(e)})", "", None | |
| try: | |
| ds = load_dataset(DATASET_REPO, split="train") | |
| except Exception: | |
| return "๋ฑ๋ก๋ ์ฑ์ฐ ๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค. ๊ด๋ฆฌ์ ํญ์์ ๋จผ์ ๋ฑ๋กํด์ฃผ์ธ์.", "", None | |
| best_match = None | |
| highest_score = -1 | |
| best_audio_b64 = None | |
| cos = torch.nn.CosineSimilarity(dim=-1) | |
| for row in ds: | |
| db_emb = torch.tensor(json.loads(row["embedding"])) | |
| score = cos(user_embedding, db_emb).item() | |
| if score > highest_score: | |
| highest_score = score | |
| best_match = row["actor_name"] | |
| best_audio_b64 = row.get("audio_b64", None) | |
| similarity_percent = round((highest_score + 1) / 2 * 100, 2) | |
| ment = f"๋ถ์๋ ์์ฑ์ '{user_tags[0]}'๊ณผ '{user_tags[1]}'๋ฅผ ๊ฐ์ง๊ณ ์์ต๋๋ค.\n" | |
| ment += f"์ด๋ฌํ ํน์ฑ๊ณผ ์ฑ๋ ํํ์ด ๊ฐ์ฅ ์ผ์นํ๋ ์ฑ์ฐ๋ก **[{best_match}]** ๋์ ์ถ์ฒํฉ๋๋ค! (์ผ์น์จ: {similarity_percent}%)" | |
| matched_audio_path = None | |
| if best_audio_b64: | |
| try: | |
| audio_bytes = base64.b64decode(best_audio_b64) | |
| temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav") | |
| temp_file.write(audio_bytes) | |
| temp_file.close() | |
| matched_audio_path = temp_file.name | |
| except Exception: | |
| pass | |
| return ment, best_match, matched_audio_path | |
| def save_feedback(best_match, feedback_score): | |
| return f"[{best_match}] ์ถ์ฒ์ ๋ํ ํผ๋๋ฐฑ({feedback_score}์ )์ด ์์ ํ๊ฒ ์ ์ฅ๋์์ต๋๋ค." | |
| # 6.[๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ฐ ๊ด๋ฆฌ์ ๊ณตํต์ฉ] | |
| def get_actor_list(): | |
| try: | |
| ds = load_dataset(DATASET_REPO, split="train") | |
| return sorted([row["actor_name"] for row in ds]) | |
| except: | |
| return[] | |
| def get_filtered_actors(genders, ages, atmos, contents): | |
| try: | |
| ds = load_dataset(DATASET_REPO, split="train") | |
| filtered_list =[] | |
| for row in ds: | |
| r_gender = row.get("gender", "") | |
| r_age = row.get("age", "") | |
| r_atmos = json.loads(row.get("atmosphere", "[]")) if row.get("atmosphere") else[] | |
| r_content = json.loads(row.get("content", "[]")) if row.get("content") else[] | |
| if genders and r_gender not in genders: continue | |
| if ages and r_age not in ages: continue | |
| if atmos and not any(a in r_atmos for a in atmos): continue | |
| if contents and not any(c in r_content for c in contents): continue | |
| filtered_list.append(row["actor_name"]) | |
| filtered_list = sorted(filtered_list) | |
| return gr.Radio(choices=filtered_list, value=None, label="๊ฒ์๋ ์ฑ์ฐ ์ ํ (๋ฐ๋ก ํด๋ฆญํ์ธ์)") | |
| except: | |
| return gr.Radio(choices=[], value=None, label="๊ฒ์๋ ์ฑ์ฐ ์ ํ (๋ฐ๋ก ํด๋ฆญํ์ธ์)") | |
| def load_actor_details(actor_name): | |
| if not actor_name: | |
| return None, "์ฑ์ฐ๋ฅผ ์ ํํด์ฃผ์ธ์." | |
| try: | |
| ds = load_dataset(DATASET_REPO, split="train") | |
| for row in ds: | |
| if row["actor_name"] == actor_name: | |
| auto_tags = ", ".join(json.loads(row.get("tags", "[]"))) | |
| r_gender = row.get("gender", "") | |
| r_age = row.get("age", "") | |
| r_atmos = ", ".join(json.loads(row.get("atmosphere", "[]"))) if row.get("atmosphere") else "" | |
| r_content = ", ".join(json.loads(row.get("content", "[]"))) if row.get("content") else "" | |
| info_text = f"**[AI ๋ถ์ ํน์ง]** {auto_tags}\n" | |
| info_text += f"**[์ฑ๋ณ/์ฐ๋ น]** {r_gender} / {r_age}\n" | |
| info_text += f"**[๋ถ์๊ธฐ]** {r_atmos}\n" | |
| info_text += f"**[์ถ์ฒ ์ฝํ ์ธ ]** {r_content}" | |
| if "audio_b64" in row and row["audio_b64"]: | |
| audio_bytes = base64.b64decode(row["audio_b64"]) | |
| temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav") | |
| temp_file.write(audio_bytes) | |
| temp_file.close() | |
| return temp_file.name, info_text | |
| else: | |
| return None, f"{info_text}\n\n(์ค๋์ค ํ์ผ์ด ์๋ ์ด๊ธฐ ๋ฐ์ดํฐ์ ๋๋ค)" | |
| return None, "์ ๋ณด๋ฅผ ์ฐพ์ ์ ์์ต๋๋ค." | |
| except Exception as e: | |
| return None, f"์ค๋ฅ ๋ฐ์: {str(e)}" | |
| # UI ์นดํ ๊ณ ๋ฆฌ ์ ์ | |
| UI_GENDER =["๋จ์ฑ", "์ฌ์ฑ"] | |
| UI_AGE =["์๋", "์ฒญ์๋ ", "์ฒญ๋ ", "์ค๋ ", "์ฅ๋ "] | |
| UI_ATMOS =["ํ ์๋", "๋ฐ์", "๊ท์ฌ์ด", "๊ฐ๋ฒผ์ด", "์ธ๋ จ๋", "๋ฐ๋ปํ", "์ฐจ๋ถํ", "์ ๋ขฐ๊ฐ์๋", "์ฐจ๊ฐ์ด", "๊ฐ์ฑ์ ์ธ", "๊ธฐํ"] | |
| UI_CONTENT =["๋คํ/๋ฆฌ๋ทฐ", "๋ญ๋ /์ค๋์ค๋ถ", "๊ธฐ์/์๋์ด์", "๋ผ๋์ค/ํ์บ์คํธ", "๊ด๊ณ /์ด๋ฒคํธ", "๊ต์ก/๊ฐ์", "์๋ด์์ฑ/ARS", "๊ฒ์/์ ๋", "์์ /์ํฐํ ์ธ๋จผํธ"] | |
| # 7. Gradio UI | |
| with gr.Blocks(theme=gr.themes.Soft()) as demo: | |
| with gr.Row(elem_id="header-row"): | |
| gr.Markdown("# ๐๏ธ AI ์ฑ์ฐ ๋ชฉ์๋ฆฌ ๋งค์นญ ์๋น์ค") | |
| logout_btn = gr.Button("๐ ๋ก๊ทธ์์", size="sm", variant="secondary", scale=0, min_width=100) | |
| logout_btn.click(fn=None, inputs=None, outputs=None, js="() => { window.location.href = '/logout'; }") | |
| with gr.Tabs(): | |
| with gr.Tab("์ฌ์ฉ์ ๊ฒ์ (Voice Matcher)"): | |
| gr.Markdown("์ฐพ๊ณ ์ถ์ ๋ ํผ๋ฐ์ค ๋ชฉ์๋ฆฌ๋ฅผ **์ง์ ๋ น์**ํ๊ฑฐ๋ **ํ์ผ๋ก ์ ๋ก๋**ํด์ฃผ์ธ์.") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| # ๐ sources=["upload", "microphone"] ์ถ๊ฐ๋ก ๋ น์๊ณผ ์ ๋ก๋๋ฅผ ๋์ ์ง์! | |
| user_audio = gr.Audio(sources=["upload", "microphone"], type="filepath", label="๐ต ์ง์ ๋ น์(๋ง์ดํฌ) ๋๋ ํ์ผ ์ ๋ก๋") | |
| gr.HTML(""" | |
| <div style="background-color: #f9f9f9; padding: 12px; border-radius: 8px; margin-top: 10px; font-size: 13px; color: #555;"> | |
| ๐ก <b>์ ํ๋ธ ์์์ ๋ชฉ์๋ฆฌ๋ฅผ ์ฐพ๊ณ ์ถ์ผ์ ๊ฐ์?</b><br> | |
| 1. ๊ฐ์ฅ ์ฌ์ด ๋ฐฉ๋ฒ: ์ ํ๋ธ๋ฅผ ์คํผ์ปค๋ก ํ์ด๋๊ณ ์ ์นธ์ <b>[๋ง์ดํฌ ์์ด์ฝ]</b>์ ๋๋ฌ 10์ด๊ฐ ๋ น์ํ์ธ์!<br> | |
| 2. ๊ณ ์์ง ํ์ผ์ด ํ์ํ๋ค๋ฉด: <a href="https://cobalt.tools/" target="_blank" style="color: #0066cc; font-weight: bold; text-decoration: underline;">์ฌ๊ธฐ(์์ ํ ๋ฌด๋ฃ ์ถ์ถ ์ฌ์ดํธ ์์ฐฝ์ด๊ธฐ)</a>์์ mp3๋ฅผ ๋ค์ด๋ฐ์ ์ ๋ก๋ํ์ธ์. | |
| </div> | |
| """) | |
| match_btn = gr.Button("๊ฐ์ฅ ๋น์ทํ ์ฑ์ฐ ์ฐพ๊ธฐ", variant="primary") | |
| with gr.Column(scale=1): | |
| result_text = gr.Textbox(label="๋ถ์ ๋ฐ ์ถ์ฒ ๊ฒฐ๊ณผ", lines=4) | |
| matched_audio_preview = gr.Audio(label="๐ง ์ถ์ฒ๋ ์ฑ์ฐ ๋ชฉ์๋ฆฌ ๋ฏธ๋ฆฌ๋ฃ๊ธฐ", interactive=False) | |
| matched_actor = gr.State() | |
| gr.Markdown("---") | |
| feedback_slider = gr.Slider(1, 5, step=1, label="์ถ์ฒ ๋ง์กฑ๋ ํ๊ฐ") | |
| feedback_btn = gr.Button("ํผ๋๋ฐฑ ์ ์ถ") | |
| feedback_out = gr.Textbox(label="์์คํ ๋ฉ์์ง") | |
| match_btn.click(fn=match_voice, inputs=[user_audio], outputs=[result_text, matched_actor, matched_audio_preview]) | |
| feedback_btn.click(fn=save_feedback, inputs=[matched_actor, feedback_slider], outputs=feedback_out) | |
| with gr.Tab("์ฑ์ฐ ๋ผ์ด๋ธ๋ฌ๋ฆฌ (๋ฏธ๋ฆฌ๋ฃ๊ธฐ)"): | |
| gr.Markdown("์กฐ๊ฑด์ ์ ํํ๊ณ ํํฐ๋ฅผ ์ ์ฉํ์ฌ ์ํ๋ ์ฑ์ฐ์ ๋ชฉ์๋ฆฌ๋ฅผ ์ง์ ๋ค์ด๋ณด์ธ์.") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| gr.Markdown("### ๐ ์กฐ๊ฑด ๊ฒ์") | |
| lib_gender = gr.CheckboxGroup(choices=UI_GENDER, label="์ฑ๋ณ") | |
| lib_age = gr.CheckboxGroup(choices=UI_AGE, label="์ฐ๋ น์ธต") | |
| lib_atmos = gr.CheckboxGroup(choices=UI_ATMOS, label="๋ถ์๊ธฐ") | |
| lib_content = gr.CheckboxGroup(choices=UI_CONTENT, label="์ฝํ ์ธ ") | |
| filter_btn = gr.Button("ํํฐ ์ ์ฉํ์ฌ ๊ฒ์", variant="secondary") | |
| with gr.Column(scale=2): | |
| gr.Markdown("### ๐ง ๊ฒ์ ๊ฒฐ๊ณผ ๋ฐ ๋ฏธ๋ฆฌ๋ฃ๊ธฐ") | |
| actor_dropdown = gr.Radio(choices=[], label="๊ฒ์๋ ์ฑ์ฐ ์ ํ (๋ฐ๋ก ํด๋ฆญํ์ธ์)") | |
| library_audio = gr.Audio(label="๋ชฉ์๋ฆฌ ๋ฏธ๋ฆฌ๋ฃ๊ธฐ", interactive=False) | |
| library_tags = gr.Markdown("์ฑ์ฐ๋ฅผ ์ ํํ๋ฉด ์์ธ ์ ๋ณด๊ฐ ์ฌ๊ธฐ์ ํ์๋ฉ๋๋ค.") | |
| filter_btn.click(fn=get_filtered_actors, inputs=[lib_gender, lib_age, lib_atmos, lib_content], outputs=actor_dropdown) | |
| actor_dropdown.change(fn=load_actor_details, inputs=actor_dropdown, outputs=[library_audio, library_tags]) | |
| with gr.Tab("๊ด๋ฆฌ์ ํญ (์ฑ์ฐ ๋ฑ๋ก ๋ฐ ์์ )"): | |
| gr.Markdown("์๋ก์ด ์ฑ์ฐ๋ฅผ ๋ฑ๋กํ๊ฑฐ๋ ๊ธฐ์กด ์ฑ์ฐ์ ์ ๋ณด๋ฅผ ์์ ํ ์ ์์ต๋๋ค.") | |
| with gr.Row(): | |
| admin_clear_btn = gr.Button("โจ ์ ๊ท ๋ฑ๋ก์ ์ํด ํผ ์ ์ฒด ๋น์ฐ๊ธฐ", variant="secondary") | |
| with gr.Accordion("๐ ๊ธฐ์กด ์ฑ์ฐ ์ ๋ณด ๋ถ๋ฌ์ค๊ธฐ (ํด๋ฆญํด์ ์ด๊ธฐ)", open=False): | |
| admin_edit_dropdown = gr.Radio(choices=[], label="โ๏ธ ์์ ํ ์ฑ์ฐ๋ฅผ ์ ํํ๋ฉด ์๋ ํผ์ ์ ๋ณด๊ฐ ์ฑ์์ง๋๋ค") | |
| admin_refresh_btn = gr.Button("๋ฑ๋ก๋ ์ฑ์ฐ ๋ชฉ๋ก ์๋ก๊ณ ์นจ") | |
| gr.Markdown("---") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| admin_name = gr.Textbox(label="์ฑ์ฐ ์ด๋ฆ (ํ์)") | |
| admin_audio_files = gr.File( | |
| file_count="multiple", | |
| file_types=["audio"], | |
| type="filepath", | |
| label="๐ต ์์ฑ ์ํ ๋ค์ค ์ ๋ก๋ (์ฌ๋ฌ ํ์ผ์ ํ๋ฒ์ ๋๋๊ทธํ๊ฑฐ๋ ์ ํํ์ธ์)" | |
| ) | |
| admin_audio_preview = gr.Audio(label="์ ์ฅ๋ ์์ฑ ํ์ธ์ฉ (๊ธฐ์กด ์ ๋ณด ๋ถ๋ฌ์ค๊ธฐ ์ ์ฌ์)", interactive=False) | |
| with gr.Column(scale=1): | |
| admin_gender = gr.Radio(choices=UI_GENDER, label="์ฑ๋ณ") | |
| admin_age = gr.Radio(choices=UI_AGE, label="์ฐ๋ น์ธต") | |
| admin_atmos = gr.CheckboxGroup(choices=UI_ATMOS, label="๋ถ์๊ธฐ (๋ค์ค ์ ํ ๊ฐ๋ฅ)") | |
| admin_content = gr.CheckboxGroup(choices=UI_CONTENT, label="์ถ์ฒ ์ฝํ ์ธ (๋ค์ค ์ ํ ๊ฐ๋ฅ)") | |
| admin_btn = gr.Button("์ฑ์ฐ DB์ ๋ฑ๋ก/์์ ํ๊ธฐ", variant="primary") | |
| admin_out = gr.Textbox(label="์ฒ๋ฆฌ ๊ฒฐ๊ณผ") | |
| admin_refresh_btn.click(fn=lambda: gr.Radio(choices=get_actor_list(), label="โ๏ธ ์์ ํ ์ฑ์ฐ๋ฅผ ์ ํํ๋ฉด ์๋ ํผ์ ์ ๋ณด๊ฐ ์ฑ์์ง๋๋ค"), outputs=admin_edit_dropdown) | |
| def clear_admin_form(): | |
| return None, "", None, None, None, None, [],[], "" | |
| admin_clear_btn.click( | |
| fn=clear_admin_form, | |
| outputs=[admin_edit_dropdown, admin_name, admin_audio_files, admin_audio_preview, admin_gender, admin_age, admin_atmos, admin_content, admin_out] | |
| ) | |
| def load_for_admin_edit(name): | |
| if not name: return name, None, None, None, None,[],[] | |
| try: | |
| ds = load_dataset(DATASET_REPO, split="train") | |
| for row in ds: | |
| if row["actor_name"] == name: | |
| r_gender = row.get("gender", None) | |
| r_age = row.get("age", None) | |
| r_atmos = json.loads(row.get("atmosphere", "[]")) if row.get("atmosphere") else[] | |
| r_content = json.loads(row.get("content", "[]")) if row.get("content") else[] | |
| audio_path = None | |
| if "audio_b64" in row and row["audio_b64"]: | |
| audio_bytes = base64.b64decode(row["audio_b64"]) | |
| temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav") | |
| temp_file.write(audio_bytes) | |
| temp_file.close() | |
| audio_path = temp_file.name | |
| return name,[audio_path] if audio_path else None, audio_path, r_gender, r_age, r_atmos, r_content | |
| except: | |
| pass | |
| return name, None, None, None, None,[],[] | |
| admin_edit_dropdown.change( | |
| fn=load_for_admin_edit, | |
| inputs=admin_edit_dropdown, | |
| outputs=[admin_name, admin_audio_files, admin_audio_preview, admin_gender, admin_age, admin_atmos, admin_content] | |
| ) | |
| admin_btn.click( | |
| fn=register_voice, | |
| inputs=[admin_name, admin_audio_files, admin_gender, admin_age, admin_atmos, admin_content], | |
| outputs=admin_out | |
| ) | |
| if __name__ == "__main__": | |
| admin_pw = os.environ.get("ADMIN_PASSWORD", "admin0000") | |
| guest_pw = os.environ.get("GUEST_PASSWORD", "guest0000") | |
| demo.queue() | |
| demo.launch( | |
| server_name="0.0.0.0", | |
| auth=[ | |
| ("admin", admin_pw), | |
| ("guest", guest_pw) | |
| ] | |
| ) | |