Update app.py
Browse files
app.py
CHANGED
|
@@ -41,7 +41,7 @@ HTML_CONTENT = """
|
|
| 41 |
let response = await fetch("/chatbot", {
|
| 42 |
method: "POST",
|
| 43 |
headers: { "Content-Type": "application/json" },
|
| 44 |
-
body: JSON.stringify({ prompt: prompt })
|
| 45 |
});
|
| 46 |
let data = await response.json();
|
| 47 |
responseBox.innerText = data.text;
|
|
@@ -65,7 +65,7 @@ async def text_to_speech(text: str) -> str:
|
|
| 65 |
output_path = os.path.join(TEMP_DIR, "output.wav")
|
| 66 |
try:
|
| 67 |
print(f"🔄 Đang xử lý TTS với model {TTS_MODEL}...")
|
| 68 |
-
audio = client.text_to_speech(model=TTS_MODEL,
|
| 69 |
with open(output_path, "wb") as f:
|
| 70 |
f.write(audio)
|
| 71 |
with open(output_path, "rb") as f:
|
|
@@ -79,7 +79,7 @@ async def speech_to_text(file: UploadFile) -> str:
|
|
| 79 |
try:
|
| 80 |
print(f"🔄 Đang xử lý STT với model {STT_MODEL}...")
|
| 81 |
audio_data = await file.read()
|
| 82 |
-
response = client.automatic_speech_recognition(model=STT_MODEL,
|
| 83 |
return response.get("text", "Không nghe được gì.")
|
| 84 |
except Exception as e:
|
| 85 |
print(f"❌ Lỗi STT: {e}")
|
|
@@ -88,7 +88,7 @@ async def speech_to_text(file: UploadFile) -> str:
|
|
| 88 |
async def generate_text(prompt: str) -> str:
|
| 89 |
try:
|
| 90 |
print(f"🔄 Đang xử lý hội thoại với model {CHAT_MODEL}...")
|
| 91 |
-
output_text = client.text_generation(
|
| 92 |
return output_text.strip()
|
| 93 |
except Exception as e:
|
| 94 |
print(f"❌ Lỗi xử lý hội thoại: {e}")
|
|
|
|
| 41 |
let response = await fetch("/chatbot", {
|
| 42 |
method: "POST",
|
| 43 |
headers: { "Content-Type": "application/json" },
|
| 44 |
+
body: JSON.stringify({ "prompt": prompt })
|
| 45 |
});
|
| 46 |
let data = await response.json();
|
| 47 |
responseBox.innerText = data.text;
|
|
|
|
| 65 |
output_path = os.path.join(TEMP_DIR, "output.wav")
|
| 66 |
try:
|
| 67 |
print(f"🔄 Đang xử lý TTS với model {TTS_MODEL}...")
|
| 68 |
+
audio = client.text_to_speech(model=TTS_MODEL, inputs=text)
|
| 69 |
with open(output_path, "wb") as f:
|
| 70 |
f.write(audio)
|
| 71 |
with open(output_path, "rb") as f:
|
|
|
|
| 79 |
try:
|
| 80 |
print(f"🔄 Đang xử lý STT với model {STT_MODEL}...")
|
| 81 |
audio_data = await file.read()
|
| 82 |
+
response = client.automatic_speech_recognition(model=STT_MODEL, inputs=audio_data)
|
| 83 |
return response.get("text", "Không nghe được gì.")
|
| 84 |
except Exception as e:
|
| 85 |
print(f"❌ Lỗi STT: {e}")
|
|
|
|
| 88 |
async def generate_text(prompt: str) -> str:
|
| 89 |
try:
|
| 90 |
print(f"🔄 Đang xử lý hội thoại với model {CHAT_MODEL}...")
|
| 91 |
+
output_text = client.text_generation(model=CHAT_MODEL, inputs=prompt, max_new_tokens=100)
|
| 92 |
return output_text.strip()
|
| 93 |
except Exception as e:
|
| 94 |
print(f"❌ Lỗi xử lý hội thoại: {e}")
|