Spaces:
Runtime error
Runtime error
Mainlst commited on
Commit ·
65169fd
1
Parent(s): 2f7518b
Hugging Face Space
Browse files
app.py
CHANGED
|
@@ -2,6 +2,22 @@ import tempfile
|
|
| 2 |
import time
|
| 3 |
import os
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
from scipy.io.wavfile import write as write_wav
|
| 7 |
|
|
@@ -22,49 +38,46 @@ def clone_and_generate(uploaded_audio_path, transcript, script):
|
|
| 22 |
if uploaded_audio_path is None or not transcript or not script:
|
| 23 |
return None, "⚠️ 音声・文字起こし・台本をすべて入力してください"
|
| 24 |
|
| 25 |
-
# 入力ファイルパス
|
| 26 |
audio_path = uploaded_audio_path
|
| 27 |
-
|
| 28 |
-
# 一意なプロンプト名でクローンプロンプト生成
|
| 29 |
prompt_name = f"prompt_{int(time.time())}"
|
| 30 |
make_prompt(name=prompt_name, audio_prompt_path=audio_path, transcript=transcript)
|
| 31 |
-
|
| 32 |
-
# 合成実行
|
| 33 |
audio_array = generate_audio(script, prompt=prompt_name)
|
| 34 |
-
|
| 35 |
-
# 出力WAV保存
|
| 36 |
out_path = os.path.join(tempfile.gettempdir(), f"{prompt_name}_generated.wav")
|
| 37 |
write_wav(out_path, SAMPLE_RATE, audio_array)
|
| 38 |
-
|
| 39 |
return out_path, "✅ 生成完了しました!🎉"
|
| 40 |
|
| 41 |
# ---------------- Gradio UI 定義 ----------------
|
| 42 |
-
with gr.Blocks(title="VALL‑E‑
|
| 43 |
gr.Markdown("""
|
| 44 |
-
#
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
""")
|
| 52 |
|
| 53 |
with gr.Row():
|
| 54 |
with gr.Column():
|
| 55 |
audio_in = gr.Audio(label="① クローン元音声", type="filepath")
|
| 56 |
-
transcript_in = gr.Textbox(label="② 文字起こし", lines=2, placeholder="例)これはテストの音声です。")
|
| 57 |
-
script_in = gr.Textbox(label="③ 台本セリフ", lines=4, placeholder="例)今日はいい天気ですね、ご主人様。")
|
| 58 |
generate_btn = gr.Button("🎙️ 音声生成", variant="primary")
|
| 59 |
|
| 60 |
with gr.Column():
|
| 61 |
-
output_audio = gr.Audio(label="生成された音声", interactive=
|
| 62 |
-
status = gr.Textbox(label="ステータス", interactive=False)
|
| 63 |
|
| 64 |
generate_btn.click(fn=clone_and_generate,
|
| 65 |
inputs=[audio_in, transcript_in, script_in],
|
| 66 |
outputs=[output_audio, status])
|
| 67 |
|
| 68 |
-
# Spaces環境ではこの1行でOK
|
| 69 |
if __name__ == "__main__":
|
| 70 |
-
|
|
|
|
|
|
| 2 |
import time
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Monkey patch to avoid gradio_client.utils APIInfoParseError when parsing schemas
|
| 6 |
+
try:
|
| 7 |
+
import gradio_client.utils as client_utils
|
| 8 |
+
def _safe_json_schema_to_python_type(schema, defs=None):
|
| 9 |
+
if isinstance(schema, bool):
|
| 10 |
+
return "Any"
|
| 11 |
+
try:
|
| 12 |
+
return client_utils._orig_json_schema_to_python_type(schema, defs)
|
| 13 |
+
except Exception:
|
| 14 |
+
return "Any"
|
| 15 |
+
if not hasattr(client_utils, "_orig_json_schema_to_python_type"):
|
| 16 |
+
client_utils._orig_json_schema_to_python_type = client_utils._json_schema_to_python_type
|
| 17 |
+
client_utils._json_schema_to_python_type = _safe_json_schema_to_python_type
|
| 18 |
+
except ImportError:
|
| 19 |
+
pass
|
| 20 |
+
|
| 21 |
import gradio as gr
|
| 22 |
from scipy.io.wavfile import write as write_wav
|
| 23 |
|
|
|
|
| 38 |
if uploaded_audio_path is None or not transcript or not script:
|
| 39 |
return None, "⚠️ 音声・文字起こし・台本をすべて入力してください"
|
| 40 |
|
|
|
|
| 41 |
audio_path = uploaded_audio_path
|
|
|
|
|
|
|
| 42 |
prompt_name = f"prompt_{int(time.time())}"
|
| 43 |
make_prompt(name=prompt_name, audio_prompt_path=audio_path, transcript=transcript)
|
|
|
|
|
|
|
| 44 |
audio_array = generate_audio(script, prompt=prompt_name)
|
|
|
|
|
|
|
| 45 |
out_path = os.path.join(tempfile.gettempdir(), f"{prompt_name}_generated.wav")
|
| 46 |
write_wav(out_path, SAMPLE_RATE, audio_array)
|
|
|
|
| 47 |
return out_path, "✅ 生成完了しました!🎉"
|
| 48 |
|
| 49 |
# ---------------- Gradio UI 定義 ----------------
|
| 50 |
+
with gr.Blocks(title="VALL‑E‑X 音声クローン Web アプリ (Spaces向け)") as demo:
|
| 51 |
gr.Markdown("""
|
| 52 |
+
# 🐾 VALL‑E‑X 音声クローン Web アプリ (Hugging Face Spaces 向け)
|
| 53 |
+
|
| 54 |
+
1. **クローン元音声**(1〜3秒の WAV 推奨)をアップロード
|
| 55 |
+
2. **文字起こし**(クローン元音声に対応するテキスト)を入力
|
| 56 |
+
3. **台本**(生成したいセリフ)を入力
|
| 57 |
+
4. **▶️ 音声生成** ボタンを押すと自動で生成されます
|
| 58 |
|
| 59 |
+
**📝 Hugging Face Spaces でのデプロイ方法**
|
| 60 |
+
- このリポジトリを Spaces のコードタブにコピー
|
| 61 |
+
- `app.py` を設定後、Spaces の `Settings` > `Hardware` で GPU を有効化(必要に応じて)
|
| 62 |
+
- `requirements.txt` に必要パッケージを追加
|
| 63 |
+
- 変更をコミットすると自動でビルド&公開されます
|
| 64 |
""")
|
| 65 |
|
| 66 |
with gr.Row():
|
| 67 |
with gr.Column():
|
| 68 |
audio_in = gr.Audio(label="① クローン元音声", type="filepath")
|
| 69 |
+
transcript_in = gr.Textbox(label="② クローン元文字起こし", lines=2, placeholder="例)これはテストの音声です。")
|
| 70 |
+
script_in = gr.Textbox(label="③ 台本(生成したいセリフ)", lines=4, placeholder="例)今日はいい天気ですね、ご主人様。")
|
| 71 |
generate_btn = gr.Button("🎙️ 音声生成", variant="primary")
|
| 72 |
|
| 73 |
with gr.Column():
|
| 74 |
+
output_audio = gr.Audio(label="生成された音声", interactive=False)
|
| 75 |
+
status = gr.Textbox(label="ステータス / ログ", interactive=False)
|
| 76 |
|
| 77 |
generate_btn.click(fn=clone_and_generate,
|
| 78 |
inputs=[audio_in, transcript_in, script_in],
|
| 79 |
outputs=[output_audio, status])
|
| 80 |
|
|
|
|
| 81 |
if __name__ == "__main__":
|
| 82 |
+
# Spaces 環境では share=True は不要
|
| 83 |
+
demo.launch(share=True)
|