import gradio as gr from TTS.api import TTS import torch # Inicjalizacja modelu TTS (głos: Mai, PL) tts = TTS(model_name="tts_models/pl/mai_female/vits", progress_bar=False, gpu=torch.cuda.is_available()) # Funkcja czatu + automatyczny głos def chat_and_speak(message, history): response = f"Hejka mała, to ja mała — ty mała, haha! Usłyszałam: {message}" # Zapisz głos do pliku tts.tts_to_file(text=response, file_path="output.wav") return response, "output.wav" # Interfejs Gradio with gr.Blocks() as demo: gr.Markdown("

🖤 MAŁA CHAT 🖤

") chatbot = gr.Chatbot() msg = gr.Textbox(label="Zadaj pytanie lub zagadaj do Małej 😏") audio_output = gr.Audio(label="Głos Małej 🎤", autoplay=True) def respond(message, history): response, audio = chat_and_speak(message, history) history.append((message, response)) return history, gr.update(value="", interactive=True), audio msg.submit(respond, [msg, chatbot], [chatbot, msg, audio_output]) demo.launch()