MaluttkaLilkaa commited on
Commit
81c8ca2
·
verified ·
1 Parent(s): 67124be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -24
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
- # --- inicjalizacja modelu głosu ---
14
- tts = TTS(model_name="tts_models/pl/mai_female/vits", progress_bar=False, gpu=False)
15
 
16
- def respond(message):
17
- response = f"Hejka mordzia 💋 Mała mówi: {message}"
 
 
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("## 🩷 Czat z Małą — mówi po polsku na żywo 🩷")
23
- chat = gr.Chatbot(label="Czat z Małą")
24
- msg = gr.Textbox(label="Napisz coś do Małej")
25
- audio_output = gr.Audio(label="Głos Małej", type="filepath")
26
- send = gr.Button("Wyślij 💬")
27
 
28
- def chat_with_tts(user_message, chat_history):
29
- bot_response, audio_path = respond(user_message)
30
- chat_history.append((user_message, bot_response))
31
- return chat_history, "", audio_path
32
 
33
- send.click(chat_with_tts, [msg, chat], [chat, msg, audio_output])
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()