Spaces:
Runtime error
Runtime error
arite commited on
Commit ·
a4c8210
1
Parent(s): 57793d2
Fix: HF Spaces compatible version - removed PyAudio dependencies
Browse files- app.py +7 -168
- requirements.txt +0 -4
app.py
CHANGED
|
@@ -7,9 +7,6 @@ import edge_tts
|
|
| 7 |
import tempfile
|
| 8 |
from datetime import datetime
|
| 9 |
import re
|
| 10 |
-
import speech_recognition as sr
|
| 11 |
-
import io
|
| 12 |
-
import numpy as np
|
| 13 |
|
| 14 |
class EternityKnowledgeBase:
|
| 15 |
def __init__(self):
|
|
@@ -268,40 +265,6 @@ def get_fallback_response(message):
|
|
| 268 |
else: # Péter
|
| 269 |
return f"Érdekes téma! Technikai szempontból hogyan közelítenéd meg ezt a problémát?", "📝 Alapválasz"
|
| 270 |
|
| 271 |
-
def transcribe_audio(audio_file):
|
| 272 |
-
"""Transcribe audio to text using speech recognition"""
|
| 273 |
-
if not audio_file:
|
| 274 |
-
return None, "Nincs audio fájl"
|
| 275 |
-
|
| 276 |
-
try:
|
| 277 |
-
# Initialize recognizer
|
| 278 |
-
r = sr.Recognizer()
|
| 279 |
-
|
| 280 |
-
# Load audio file
|
| 281 |
-
with sr.AudioFile(audio_file) as source:
|
| 282 |
-
# Adjust for ambient noise
|
| 283 |
-
r.adjust_for_ambient_noise(source, duration=0.5)
|
| 284 |
-
# Record the audio
|
| 285 |
-
audio = r.record(source)
|
| 286 |
-
|
| 287 |
-
# Recognize speech using Google's speech recognition
|
| 288 |
-
try:
|
| 289 |
-
# Try Hungarian first
|
| 290 |
-
text = r.recognize_google(audio, language='hu-HU')
|
| 291 |
-
return text, "✅ Felismerve"
|
| 292 |
-
except sr.UnknownValueError:
|
| 293 |
-
# Try English as fallback
|
| 294 |
-
try:
|
| 295 |
-
text = r.recognize_google(audio, language='en-US')
|
| 296 |
-
return text, "✅ Felismerve (EN)"
|
| 297 |
-
except sr.UnknownValueError:
|
| 298 |
-
return None, "❌ Nem érthető"
|
| 299 |
-
except sr.RequestError as e:
|
| 300 |
-
return None, f"❌ Hiba: {str(e)}"
|
| 301 |
-
|
| 302 |
-
except Exception as e:
|
| 303 |
-
return None, f"❌ Audio hiba: {str(e)}"
|
| 304 |
-
|
| 305 |
async def generate_tts(text, voice="hu-HU-NoemiNeural"):
|
| 306 |
"""Generate TTS audio using Edge-TTS"""
|
| 307 |
try:
|
|
@@ -412,24 +375,6 @@ def chat_with_avatar(message, history, use_tts, persona_selection, llm_preferenc
|
|
| 412 |
|
| 413 |
return history, "", audio_file, get_avatar_display(True, ai_response)
|
| 414 |
|
| 415 |
-
def voice_chat_with_avatar(audio_input, history, use_tts, persona_selection, llm_preference):
|
| 416 |
-
"""Voice chat function - transcribe audio and respond"""
|
| 417 |
-
if not audio_input:
|
| 418 |
-
return history, None, get_avatar_display(), "❌ Nincs audio bemenet"
|
| 419 |
-
|
| 420 |
-
# Transcribe audio
|
| 421 |
-
transcribed_text, transcribe_status = transcribe_audio(audio_input)
|
| 422 |
-
|
| 423 |
-
if not transcribed_text:
|
| 424 |
-
return history, None, get_avatar_display(), f"🎤 {transcribe_status}"
|
| 425 |
-
|
| 426 |
-
# Process the transcribed text as a regular chat message
|
| 427 |
-
updated_history, _, audio_output, avatar_display = chat_with_avatar(
|
| 428 |
-
transcribed_text, history, use_tts, persona_selection, llm_preference
|
| 429 |
-
)
|
| 430 |
-
|
| 431 |
-
return updated_history, audio_output, avatar_display, f"🎤 Felismert szöveg: '{transcribed_text}'"
|
| 432 |
-
|
| 433 |
def load_sample_persona(persona_key):
|
| 434 |
"""Load a sample persona"""
|
| 435 |
if persona_key in kb.sample_personas:
|
|
@@ -506,9 +451,6 @@ def get_api_status():
|
|
| 506 |
# TTS Status
|
| 507 |
status_lines.append("• TTS Rendszer: ✅ Aktív")
|
| 508 |
|
| 509 |
-
# Speech Recognition Status
|
| 510 |
-
status_lines.append("• Beszédfelismerés: ✅ Aktív")
|
| 511 |
-
|
| 512 |
# Current LLM preference
|
| 513 |
llm_pref = "🔮 Gemma-3-12B" if kb.llm_preference == "gemma" else "🤖 OpenAI"
|
| 514 |
status_lines.append(f"• Aktív LLM: {llm_pref}")
|
|
@@ -628,15 +570,15 @@ css = """
|
|
| 628 |
"""
|
| 629 |
|
| 630 |
def create_enhanced_eternity_interface():
|
| 631 |
-
"""Create the enhanced Eternity interface with
|
| 632 |
|
| 633 |
with gr.Blocks(css=css, title="🎭 Eternity - Magyar Beszélő Avatar POC v5.1", theme=gr.themes.Soft()) as interface:
|
| 634 |
|
| 635 |
gr.HTML("""
|
| 636 |
<div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 10px; margin-bottom: 20px; color: white;">
|
| 637 |
<h1 style="margin: 0; font-size: 2.5em; text-shadow: 2px 2px 4px rgba(0,0,0,0.3);">🎭 Eternity - Magyar Beszélő Avatar POC v5.1</h1>
|
| 638 |
-
<p style="margin: 10px 0 0 0; font-size: 1.2em; opacity: 0.9;">🔮 Gemma-3-12B + 🤖 OpenAI •
|
| 639 |
-
<p style="margin: 5px 0 0 0; font-size: 1em; opacity: 0.8;">
|
| 640 |
</div>
|
| 641 |
""")
|
| 642 |
|
|
@@ -650,7 +592,7 @@ def create_enhanced_eternity_interface():
|
|
| 650 |
label="Beszélgetés az Avatar-ral",
|
| 651 |
show_label=True,
|
| 652 |
container=True,
|
| 653 |
-
type="messages"
|
| 654 |
)
|
| 655 |
|
| 656 |
# LLM Selection
|
|
@@ -681,29 +623,6 @@ def create_enhanced_eternity_interface():
|
|
| 681 |
)
|
| 682 |
send_btn = gr.Button("📤 Küldés", scale=1, variant="primary")
|
| 683 |
|
| 684 |
-
# Voice Communication
|
| 685 |
-
with gr.Group():
|
| 686 |
-
gr.HTML("""
|
| 687 |
-
<div class="voice-controls">
|
| 688 |
-
<h4 style="margin: 0 0 10px 0;">🎤 Hangos Beszélgetés</h4>
|
| 689 |
-
<p style="margin: 0; opacity: 0.9; font-size: 0.9em;">Beszélj a mikrofonba és az avatar hangosan válaszol</p>
|
| 690 |
-
</div>
|
| 691 |
-
""")
|
| 692 |
-
|
| 693 |
-
with gr.Row():
|
| 694 |
-
voice_input = gr.Audio(
|
| 695 |
-
label="🎤 Mikrofon bemenet",
|
| 696 |
-
sources=["microphone"],
|
| 697 |
-
type="filepath"
|
| 698 |
-
)
|
| 699 |
-
voice_btn = gr.Button("🎤 Hangos Üzenet", variant="secondary")
|
| 700 |
-
|
| 701 |
-
voice_status = gr.Textbox(
|
| 702 |
-
label="🎤 Beszédfelismerés állapot",
|
| 703 |
-
value="Készen áll a hangos beszélgetésre",
|
| 704 |
-
interactive=False
|
| 705 |
-
)
|
| 706 |
-
|
| 707 |
# Settings
|
| 708 |
with gr.Row():
|
| 709 |
use_tts = gr.Checkbox(label="🗣️ Beszélő avatar (TTS)", value=True)
|
|
@@ -836,88 +755,18 @@ def create_enhanced_eternity_interface():
|
|
| 836 |
)
|
| 837 |
|
| 838 |
refresh_btn = gr.Button("🔄 Frissítés", variant="secondary")
|
| 839 |
-
|
| 840 |
-
# About Tab
|
| 841 |
-
with gr.Tab("ℹ️ Információ"):
|
| 842 |
-
gr.HTML("""
|
| 843 |
-
<div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea, #764ba2); border-radius: 10px; margin-bottom: 20px; color: white;">
|
| 844 |
-
<h2 style="margin: 0;">🎭 Eternity POC v5.1 - Optimalizált Verzió</h2>
|
| 845 |
-
<p style="margin: 10px 0 0 0; opacity: 0.9;">Magyar Beszélő Avatar Rendszer - Teljes Funkcionalitással</p>
|
| 846 |
-
</div>
|
| 847 |
-
|
| 848 |
-
## 🚀 Főbb Funkciók
|
| 849 |
-
|
| 850 |
-
### 🤖 Dual LLM Támogatás
|
| 851 |
-
- **🔮 Gemma-3-12B-IT-OZA:** Helyi magyar modell
|
| 852 |
-
- **🤖 OpenAI GPT-3.5:** Felhő alapú modell
|
| 853 |
-
- **🔄 Automatikus Fallback:** Ha az egyik nem elérhető, átvált a másikra
|
| 854 |
-
|
| 855 |
-
### 🎤 Hangos Kommunikáció
|
| 856 |
-
- **🎤 Beszédfelismerés:** Magyar és angol nyelv támogatás
|
| 857 |
-
- **🗣️ Text-to-Speech:** Edge-TTS magyar hangokkal
|
| 858 |
-
- **🔊 Automatikus Lejátszás:** Azonnali hangos válaszok
|
| 859 |
-
|
| 860 |
-
### 👤 Persona Rendszer
|
| 861 |
-
- **3 Mintapersona:** Péter (mérnök), Anna (tanár), Zsolti (munkás)
|
| 862 |
-
- **🎭 Egyedi Karakterek:** Saját persona létrehozása
|
| 863 |
-
- **🗣️ Persona-specifikus Hangok:** Férfi/női TTS hangok
|
| 864 |
-
|
| 865 |
-
### 📚 Tudásbázis
|
| 866 |
-
- **📄 Dokumentum Feltöltés:** TXT és MD fájlok
|
| 867 |
-
- **🔍 Kontextuális Keresés:** Releváns információk használata
|
| 868 |
-
- **💭 Beszélgetési Memória:** Korábbi üzenetek megjegyzése
|
| 869 |
-
|
| 870 |
-
### 🎨 Felhasználói Felület
|
| 871 |
-
- **🌙 Dark Mode:** Automatikus téma váltás
|
| 872 |
-
- **📱 Reszponzív:** Mobil és desktop optimalizálás
|
| 873 |
-
- **🎭 Animált Avatar:** Vizuális visszajelzések
|
| 874 |
-
|
| 875 |
-
---
|
| 876 |
-
|
| 877 |
-
## 🔧 Technikai Specifikáció
|
| 878 |
-
|
| 879 |
-
- **Frontend:** Gradio 4.0+ (optimalizált)
|
| 880 |
-
- **LLM Modellek:** Gemma-3-12B-IT-OZA + OpenAI GPT-3.5
|
| 881 |
-
- **TTS:** Microsoft Edge-TTS
|
| 882 |
-
- **STT:** Google Speech Recognition
|
| 883 |
-
- **Nyelv:** Magyar (elsődleges) + Angol (fallback)
|
| 884 |
-
|
| 885 |
-
---
|
| 886 |
-
|
| 887 |
-
## 🎯 Fejlesztési Roadmap
|
| 888 |
-
|
| 889 |
-
**Következő verziókban:**
|
| 890 |
-
- **🎥 Video Avatar:** Valósághű arcanimáció
|
| 891 |
-
- **🧠 Memória Bővítés:** Hosszú távú emlékek
|
| 892 |
-
- **🌐 Többnyelvűség:** További európai nyelvek
|
| 893 |
-
- **📊 Analytics:** Beszélgetési statisztikák
|
| 894 |
-
- **🔗 API Integráció:** Külső szolgáltatások
|
| 895 |
-
- **📱 Mobilalkalmazás:** Natív iOS/Android támogatás
|
| 896 |
-
|
| 897 |
-
---
|
| 898 |
-
|
| 899 |
-
**🎭 Eternity POC v5.1** - *Optimalizált és Teljes Funkcionalitással*
|
| 900 |
-
""")
|
| 901 |
|
| 902 |
-
# Event handlers
|
| 903 |
def handle_chat(message, history, use_tts, persona_selection, llm_preference):
|
| 904 |
-
# Convert history to proper format if needed
|
| 905 |
if history is None:
|
| 906 |
history = []
|
| 907 |
|
| 908 |
-
# Get response
|
| 909 |
updated_history, _, audio_file, avatar_display = chat_with_avatar(
|
| 910 |
message, history, use_tts, persona_selection, llm_preference
|
| 911 |
)
|
| 912 |
|
| 913 |
return updated_history, "", audio_file, avatar_display
|
| 914 |
|
| 915 |
-
def handle_voice_chat(audio_input, history, use_tts, persona_selection, llm_preference):
|
| 916 |
-
if history is None:
|
| 917 |
-
history = []
|
| 918 |
-
|
| 919 |
-
return voice_chat_with_avatar(audio_input, history, use_tts, persona_selection, llm_preference)
|
| 920 |
-
|
| 921 |
# Chat events
|
| 922 |
send_btn.click(
|
| 923 |
handle_chat,
|
|
@@ -931,13 +780,6 @@ def create_enhanced_eternity_interface():
|
|
| 931 |
outputs=[chatbot, msg_input, audio_output, avatar_display]
|
| 932 |
)
|
| 933 |
|
| 934 |
-
# Voice chat events
|
| 935 |
-
voice_btn.click(
|
| 936 |
-
handle_voice_chat,
|
| 937 |
-
inputs=[voice_input, chatbot, use_tts, persona_selector, llm_selector],
|
| 938 |
-
outputs=[chatbot, audio_output, avatar_display, voice_status]
|
| 939 |
-
)
|
| 940 |
-
|
| 941 |
# Persona events
|
| 942 |
load_sample_btn.click(
|
| 943 |
load_sample_persona,
|
|
@@ -1010,9 +852,9 @@ def create_enhanced_eternity_interface():
|
|
| 1010 |
|
| 1011 |
# Create and launch the interface
|
| 1012 |
if __name__ == "__main__":
|
| 1013 |
-
print("🎭 Eternity POC v5.1 -
|
| 1014 |
print("🔮 Gemma-3-12B-IT-OZA + 🤖 OpenAI GPT-3.5 támogatással")
|
| 1015 |
-
print("
|
| 1016 |
|
| 1017 |
# Check environment variables
|
| 1018 |
gemma_url = os.getenv('GEMMA_ENDPOINT_URL')
|
|
@@ -1029,10 +871,7 @@ if __name__ == "__main__":
|
|
| 1029 |
else:
|
| 1030 |
print("⚠️ OpenAI API kulcs nem található")
|
| 1031 |
|
| 1032 |
-
print("🗣️ TTS rendszer aktív - Edge-TTS magyar hangokkal")
|
| 1033 |
-
print("🎤 Beszédfelismerés aktív - Google Speech Recognition")
|
| 1034 |
print("🚀 Eternity POC v5.1 elindítva!")
|
| 1035 |
-
print("🌐 Elérhető: http://localhost:7860")
|
| 1036 |
|
| 1037 |
interface = create_enhanced_eternity_interface()
|
| 1038 |
interface.launch(
|
|
|
|
| 7 |
import tempfile
|
| 8 |
from datetime import datetime
|
| 9 |
import re
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
class EternityKnowledgeBase:
|
| 12 |
def __init__(self):
|
|
|
|
| 265 |
else: # Péter
|
| 266 |
return f"Érdekes téma! Technikai szempontból hogyan közelítenéd meg ezt a problémát?", "📝 Alapválasz"
|
| 267 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
async def generate_tts(text, voice="hu-HU-NoemiNeural"):
|
| 269 |
"""Generate TTS audio using Edge-TTS"""
|
| 270 |
try:
|
|
|
|
| 375 |
|
| 376 |
return history, "", audio_file, get_avatar_display(True, ai_response)
|
| 377 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
def load_sample_persona(persona_key):
|
| 379 |
"""Load a sample persona"""
|
| 380 |
if persona_key in kb.sample_personas:
|
|
|
|
| 451 |
# TTS Status
|
| 452 |
status_lines.append("• TTS Rendszer: ✅ Aktív")
|
| 453 |
|
|
|
|
|
|
|
|
|
|
| 454 |
# Current LLM preference
|
| 455 |
llm_pref = "🔮 Gemma-3-12B" if kb.llm_preference == "gemma" else "🤖 OpenAI"
|
| 456 |
status_lines.append(f"• Aktív LLM: {llm_pref}")
|
|
|
|
| 570 |
"""
|
| 571 |
|
| 572 |
def create_enhanced_eternity_interface():
|
| 573 |
+
"""Create the enhanced Eternity interface with LLM selection and TTS"""
|
| 574 |
|
| 575 |
with gr.Blocks(css=css, title="🎭 Eternity - Magyar Beszélő Avatar POC v5.1", theme=gr.themes.Soft()) as interface:
|
| 576 |
|
| 577 |
gr.HTML("""
|
| 578 |
<div style="text-align: center; padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 10px; margin-bottom: 20px; color: white;">
|
| 579 |
<h1 style="margin: 0; font-size: 2.5em; text-shadow: 2px 2px 4px rgba(0,0,0,0.3);">🎭 Eternity - Magyar Beszélő Avatar POC v5.1</h1>
|
| 580 |
+
<p style="margin: 10px 0 0 0; font-size: 1.2em; opacity: 0.9;">🔮 Gemma-3-12B + 🤖 OpenAI • 🗣️ Magyar TTS</p>
|
| 581 |
+
<p style="margin: 5px 0 0 0; font-size: 1em; opacity: 0.8;">Hugging Face Spaces kompatibilis verzió</p>
|
| 582 |
</div>
|
| 583 |
""")
|
| 584 |
|
|
|
|
| 592 |
label="Beszélgetés az Avatar-ral",
|
| 593 |
show_label=True,
|
| 594 |
container=True,
|
| 595 |
+
type="messages"
|
| 596 |
)
|
| 597 |
|
| 598 |
# LLM Selection
|
|
|
|
| 623 |
)
|
| 624 |
send_btn = gr.Button("📤 Küldés", scale=1, variant="primary")
|
| 625 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 626 |
# Settings
|
| 627 |
with gr.Row():
|
| 628 |
use_tts = gr.Checkbox(label="🗣️ Beszélő avatar (TTS)", value=True)
|
|
|
|
| 755 |
)
|
| 756 |
|
| 757 |
refresh_btn = gr.Button("🔄 Frissítés", variant="secondary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 758 |
|
| 759 |
+
# Event handlers
|
| 760 |
def handle_chat(message, history, use_tts, persona_selection, llm_preference):
|
|
|
|
| 761 |
if history is None:
|
| 762 |
history = []
|
| 763 |
|
|
|
|
| 764 |
updated_history, _, audio_file, avatar_display = chat_with_avatar(
|
| 765 |
message, history, use_tts, persona_selection, llm_preference
|
| 766 |
)
|
| 767 |
|
| 768 |
return updated_history, "", audio_file, avatar_display
|
| 769 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
# Chat events
|
| 771 |
send_btn.click(
|
| 772 |
handle_chat,
|
|
|
|
| 780 |
outputs=[chatbot, msg_input, audio_output, avatar_display]
|
| 781 |
)
|
| 782 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 783 |
# Persona events
|
| 784 |
load_sample_btn.click(
|
| 785 |
load_sample_persona,
|
|
|
|
| 852 |
|
| 853 |
# Create and launch the interface
|
| 854 |
if __name__ == "__main__":
|
| 855 |
+
print("🎭 Eternity POC v5.1 - HF Spaces Compatible Version")
|
| 856 |
print("🔮 Gemma-3-12B-IT-OZA + 🤖 OpenAI GPT-3.5 támogatással")
|
| 857 |
+
print("🗣️ TTS rendszer aktív - Edge-TTS magyar hangokkal")
|
| 858 |
|
| 859 |
# Check environment variables
|
| 860 |
gemma_url = os.getenv('GEMMA_ENDPOINT_URL')
|
|
|
|
| 871 |
else:
|
| 872 |
print("⚠️ OpenAI API kulcs nem található")
|
| 873 |
|
|
|
|
|
|
|
| 874 |
print("🚀 Eternity POC v5.1 elindítva!")
|
|
|
|
| 875 |
|
| 876 |
interface = create_enhanced_eternity_interface()
|
| 877 |
interface.launch(
|
requirements.txt
CHANGED
|
@@ -2,7 +2,3 @@ gradio>=4.0.0
|
|
| 2 |
requests
|
| 3 |
openai
|
| 4 |
edge-tts
|
| 5 |
-
SpeechRecognition
|
| 6 |
-
pyaudio
|
| 7 |
-
pydub
|
| 8 |
-
numpy
|
|
|
|
| 2 |
requests
|
| 3 |
openai
|
| 4 |
edge-tts
|
|
|
|
|
|
|
|
|
|
|
|