Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Step 2: Generate the audio

# this is a sample from the TinyStories dataset.
text ="""One day, a little girl named Lily found a needle in her room. She knew it was difficult to play with it because it was sharp. """
text ="""你好你好你好 """


# available_voices : ['Bella', 'Jasper', 'Luna', 'Bruno', 'Rosie', 'Hugo', 'Kiki', 'Leo']
Expand Down
18 changes: 18 additions & 0 deletions run_webui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
import sys

script_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, script_dir)

from webui.app import app

if __name__ == '__main__':
print("=" * 60)
print("[KittenTTS] WebUI 启动中...")
print("=" * 60)
print()
print("请在浏览器中访问: http://localhost:5000")
print()
print("=" * 60)

app.run(host='0.0.0.0', port=5000, debug=True)
132 changes: 132 additions & 0 deletions test_flask_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import sys
import os

# 添加项目路径到sys.path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

# 设置Flask应用的模板目录
from flask import Flask, render_template

# 创建一个测试Flask应用
app = Flask(__name__,
template_folder=os.path.join(os.path.dirname(os.path.abspath(__file__)), 'webui', 'templates'))

# 禁用模板缓存
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0

print("=" * 60)
print("Testing Flask template loading")
print("=" * 60)

# 打印模板目录
print(f"Template folder: {app.template_folder}")
print(f"Template folder exists: {os.path.exists(app.template_folder)}")

# 检查index.html文件
index_path = os.path.join(app.template_folder, 'index.html')
print(f"Index.html path: {index_path}")
print(f"Index.html exists: {os.path.exists(index_path)}")

if os.path.exists(index_path):
with open(index_path, 'r', encoding='utf-8') as f:
file_content = f.read()
print(f"File size: {len(file_content)} characters")

# 检查是否包含新增功能
checks = [
('themeToggle', 'theme toggle button'),
('file-upload-container', 'file upload container'),
('progress-container', 'progress bar container'),
('dark-mode', 'dark mode style'),
('initTheme', 'theme init function'),
('initFileUpload', 'file upload init function'),
('showProgress', 'progress bar show function'),
]

print("\nChecking file content:")
all_found = True
for check, name in checks:
if check in file_content:
print(f"[OK] Found: {name}")
else:
print(f"[MISSING] Not found: {name}")
all_found = False

if all_found:
print("\n[OK] All new features are in the file!")
else:
print("\n[ERROR] Some features are missing from the file!")
else:
print("[ERROR] index.html file does not exist!")

# 现在测试Flask的render_template函数
print("\n" + "=" * 60)
print("Testing render_template function")
print("=" * 60)

with app.app_context():
try:
rendered = render_template('index.html')
print(f"Rendered template size: {len(rendered)} characters")

print("\nChecking rendered content:")
all_found_rendered = True
for check, name in checks:
if check in rendered:
print(f"[OK] Found: {name}")
else:
print(f"[MISSING] Not found: {name}")
all_found_rendered = False

if all_found_rendered:
print("\n[OK] All new features are in the rendered template!")
else:
print("\n[ERROR] Some features are missing from the rendered template!")

# 显示渲染内容的前1000个字符
print("\nFirst 1000 characters of rendered content:")
print("-" * 60)
print(rendered[:1000])
print("-" * 60)

except Exception as e:
print(f"[ERROR] Error rendering template: {e}")
import traceback
traceback.print_exc()

# 比较文件内容和渲染内容
if os.path.exists(index_path):
with open(index_path, 'r', encoding='utf-8') as f:
file_content = f.read()

with app.app_context():
try:
rendered = render_template('index.html')

print("\n" + "=" * 60)
print("Comparing file content and rendered content")
print("=" * 60)

if file_content == rendered:
print("[OK] File content and rendered content are identical!")
else:
print("[ERROR] File content and rendered content are different!")
print(f"File size: {len(file_content)}")
print(f"Rendered size: {len(rendered)}")

# 找出差异
if len(file_content) != len(rendered):
print(f"\nSize difference: {abs(len(file_content) - len(rendered))} characters")

# 检查前100个字符是否相同
min_len = min(len(file_content), len(rendered))
for i in range(min_len):
if file_content[i] != rendered[i]:
print(f"\nFirst difference at position {i}")
print(f"File: {file_content[max(0, i-20):i+20]}")
print(f"Rendered: {rendered[max(0, i-20):i+20]}")
break

except Exception as e:
print(f"[ERROR] Error comparing: {e}")
81 changes: 81 additions & 0 deletions test_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import urllib.request
import sys
import os

# 设置控制台编码
sys.stdout.reconfigure(encoding='utf-8')

# 首先检查本地文件
print("=" * 60)
print("Checking local index.html file")
print("=" * 60)

html_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'webui', 'templates', 'index.html')
print(f"File path: {html_path}")
print(f"File exists: {os.path.exists(html_path)}")

if os.path.exists(html_path):
with open(html_path, 'r', encoding='utf-8') as f:
html = f.read()

print(f"File size: {len(html)} characters")

# 检查是否包含所有新增的元素
checks = [
('themeToggle', 'theme toggle button'),
('file-upload-container', 'file upload container'),
('progress-container', 'progress bar container'),
('dark-mode', 'dark mode style'),
('initTheme', 'theme init function'),
('initFileUpload', 'file upload init function'),
('showProgress', 'progress bar show function'),
]

all_found = True
for check, name in checks:
if check in html:
print(f"[OK] Found: {name}")
else:
print(f"[MISSING] Not found: {name}")
all_found = False

if all_found:
print("\n[OK] All new features are in the local file!")
else:
print("\n[ERROR] Some features are missing from the local file!")
else:
print("[ERROR] Local index.html file does not exist!")

# 然后检查Flask服务返回的内容
print("\n" + "=" * 60)
print("Checking Flask server response")
print("=" * 60)

try:
with urllib.request.urlopen('http://localhost:5000') as response:
server_html = response.read().decode('utf-8')

print(f"Server response size: {len(server_html)} characters")

# 检查是否包含所有新增的元素
all_found_server = True
for check, name in checks:
if check in server_html:
print(f"[OK] Found: {name}")
else:
print(f"[MISSING] Not found: {name}")
all_found_server = False

if all_found_server:
print("\n[OK] All new features are in the server response!")
else:
print("\n[ERROR] Some features are missing from the server response!")

# 显示前1000个字符,看看返回的是什么
print("\nFirst 1000 characters of server response:")
print("-" * 60)
print(server_html[:1000])
print("-" * 60)

except Exception as e:
print(f"[ERROR] Error connecting to server: {e}")
3 changes: 3 additions & 0 deletions webui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .app import app

__all__ = ['app']
Loading