Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
import pyttsx3
|
| 4 |
+
|
| 5 |
+
# Inicializace modelu Hugging Face pro generování textu
|
| 6 |
+
generator = pipeline("text-generation", model="gpt2")
|
| 7 |
+
|
| 8 |
+
# TTS: Funkce pro syntézu hlasu
|
| 9 |
+
engine = pyttsx3.init()
|
| 10 |
+
def speak(text):
|
| 11 |
+
engine.say(text)
|
| 12 |
+
engine.runAndWait()
|
| 13 |
+
|
| 14 |
+
# Funkce pro zpracování uživatelského vstupu
|
| 15 |
+
def chatbot(user_input):
|
| 16 |
+
response = generator(user_input, max_length=50, num_return_sequences=1)
|
| 17 |
+
generated_text = response[0]["generated_text"]
|
| 18 |
+
speak(generated_text) # Přečte odpověď
|
| 19 |
+
return generated_text
|
| 20 |
+
|
| 21 |
+
# Vytvoření jednoduchého uživatelského rozhraní
|
| 22 |
+
interface = gr.Interface(
|
| 23 |
+
fn=chatbot,
|
| 24 |
+
inputs=gr.Textbox(label="Zadej svou otázku:"),
|
| 25 |
+
outputs=gr.Textbox(label="Odpověď od chatbota:"),
|
| 26 |
+
live=True
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Spuštění aplikace
|
| 30 |
+
interface.launch()
|