File size: 1,075 Bytes
9590253
81c8ca2
 
9590253
81c8ca2
 
9590253
81c8ca2
 
 
 
9590253
 
 
81c8ca2
9590253
81c8ca2
 
 
 
9590253
81c8ca2
 
 
 
9590253
81c8ca2
83daca7
9590253
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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("<h1 style='text-align: center;'>🖤 MAŁA CHAT 🖤</h1>")
    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()