Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,29 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import subprocess
|
| 3 |
-
|
| 4 |
-
# --- instalacja TTS jeśli brak ---
|
| 5 |
-
try:
|
| 6 |
-
from TTS.api import TTS
|
| 7 |
-
except ModuleNotFoundError:
|
| 8 |
-
subprocess.run(["pip", "install", "TTS==0.22.0", "torch", "torchaudio", "gradio==4.44.0"], check=True)
|
| 9 |
-
from TTS.api import TTS
|
| 10 |
-
|
| 11 |
import gradio as gr
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
tts = TTS(model_name="tts_models/pl/mai_female/vits", progress_bar=False, gpu=
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
tts.tts_to_file(text=response, file_path="output.wav")
|
| 19 |
return response, "output.wav"
|
| 20 |
|
|
|
|
| 21 |
with gr.Blocks() as demo:
|
| 22 |
-
gr.Markdown("
|
| 23 |
-
|
| 24 |
-
msg = gr.Textbox(label="
|
| 25 |
-
audio_output = gr.Audio(label="Głos Małej",
|
| 26 |
-
send = gr.Button("Wyślij 💬")
|
| 27 |
|
| 28 |
-
def
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
return
|
| 32 |
|
| 33 |
-
|
| 34 |
|
| 35 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from TTS.api import TTS
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Inicjalizacja modelu TTS (głos: Mai, PL)
|
| 6 |
+
tts = TTS(model_name="tts_models/pl/mai_female/vits", progress_bar=False, gpu=torch.cuda.is_available())
|
| 7 |
|
| 8 |
+
# Funkcja czatu + automatyczny głos
|
| 9 |
+
def chat_and_speak(message, history):
|
| 10 |
+
response = f"Hejka mała, to ja mała — ty mała, haha! Usłyszałam: {message}"
|
| 11 |
+
# Zapisz głos do pliku
|
| 12 |
tts.tts_to_file(text=response, file_path="output.wav")
|
| 13 |
return response, "output.wav"
|
| 14 |
|
| 15 |
+
# Interfejs Gradio
|
| 16 |
with gr.Blocks() as demo:
|
| 17 |
+
gr.Markdown("<h1 style='text-align: center;'>🖤 MAŁA CHAT 🖤</h1>")
|
| 18 |
+
chatbot = gr.Chatbot()
|
| 19 |
+
msg = gr.Textbox(label="Zadaj pytanie lub zagadaj do Małej 😏")
|
| 20 |
+
audio_output = gr.Audio(label="Głos Małej 🎤", autoplay=True)
|
|
|
|
| 21 |
|
| 22 |
+
def respond(message, history):
|
| 23 |
+
response, audio = chat_and_speak(message, history)
|
| 24 |
+
history.append((message, response))
|
| 25 |
+
return history, gr.update(value="", interactive=True), audio
|
| 26 |
|
| 27 |
+
msg.submit(respond, [msg, chatbot], [chatbot, msg, audio_output])
|
| 28 |
|
| 29 |
demo.launch()
|