update for dictation model

This commit is contained in:
Wolfang Torres
2026-06-20 14:10:54 +08:00
parent c5bad326f1
commit fe54900bdf
4 changed files with 58 additions and 26 deletions

View File

@@ -31,7 +31,7 @@ def create_app():
app.config.from_pyfile("config.py", silent=True)
for blueprint in (homescreen, mainapp):
# for blueprint in (homescreen,):
# for blueprint in (homescreen,):
app.register_blueprint(blueprint)
return app

View File

@@ -3,7 +3,7 @@ from pathlib import Path
# Pip
from anki_hsk_creator import api
from anki_hsk_creator.constants import DICT_TYPE, PHRASES_TYPE
from anki_hsk_creator.constants import DICTATION_TYPE, DICT_TYPE, PHRASES_TYPE
from anki_hsk_creator.utility import ProcessFile
from flask import (
Blueprint,
@@ -27,33 +27,44 @@ mainapp = Blueprint(
@mainapp.route("/", methods=["GET"])
def app():
"""Main app entry pages"""
return render_template("app.html")
return redirect(url_for("mainapp.file_list"))
# return render_template("app.html")
@mainapp.route("/list", methods=["GET"])
@mainapp.route("/list/", methods=["GET"])
@mainapp.route("/list/<path:listing_path>", methods=["GET"])
@mainapp.route("/list", methods=["GET", "POST", "DELETE"])
@mainapp.route("/list/", methods=["GET", "POST", "DELETE"])
@mainapp.route("/list/<path:listing_path>", methods=["GET", "POST", "DELETE"])
def file_list(listing_path=""):
"""Path for file lister"""
listing_path = Path(listing_path)
root_files = {file: [] for file in api.list_input_files()}
level = root_files
level_path = Path()
for part in listing_path.parts:
level_path = level_path / part
level[level_path] = {file: [] for file in api.list_input_files(level_path)}
level = level[level_path]
if request.method == "GET":
listing_path = Path(listing_path)
root_files = {file: [] for file in api.list_input_files()}
level = root_files
level_path = Path()
for part in listing_path.parts:
level_path = level_path / part
level[level_path] = {file: [] for file in api.list_input_files(level_path)}
level = level[level_path]
if listing_path:
file_data = api.analize_input_files(listing_path)
else:
file_data = api.analize_input_files(None)
return render_template(
"file_list.html",
file_data=file_data,
root_files=root_files,
listing_path=listing_path,
)
if listing_path:
file_data = api.analize_input_files(listing_path)
else:
file_data = api.analize_input_files(None)
return render_template(
"file_list.html",
file_data=file_data,
root_files=root_files,
listing_path=listing_path,
)
if request.method == "POST":
form = request.form.to_dict()
listing_path = Path(listing_path)
process_file = ProcessFile(listing_path)
if process_file.absolute_input_file.is_file():
listing_path = listing_path.parent
return redirect(
(url_for("mainapp.create", listing_path=listing_path / form["name"]))
)
@mainapp.route("/download/<path:listing_path>", methods=["GET"])
@@ -127,6 +138,13 @@ def create(listing_path=""):
)
response.set_cookie("download_started", "true", max_age=10)
return response
elif args["deck_type"] in DICTATION_TYPE:
final_file = api.process_a_dictation_file(process_file, args["language_id"])
response = make_response(
send_from_directory(final_file.parent, final_file.name)
)
response.set_cookie("download_started", "true", max_age=10)
return response
@mainapp.route("/process/<path:listing_path>", methods=["GET", "POST"])

View File

@@ -83,7 +83,7 @@
<!-- Full-screen preloader container -->
<div id="loader-wrapper">
<div class="loader"></div>
<p class="loader-text">Loading, please wait...</p>
<p class="loader-text">Loading, creating audios, please wait...</p>
</div>
<!-- Wrapper -->
@@ -151,7 +151,7 @@
type="radio"
id="type3"
name="deck_type"
value="paragraph"
value="dictation"
/>
<label for="type3">Paragraph Dictation</label>
</div>

View File

@@ -107,8 +107,22 @@
<div class="content">
<h3>Current Path: {{ listing_path or "-" }}</h3>
<br />
<ul class="items">
<li>
<form id="text_form" method="POST">
<div class="fields">
<label for="name">File Name:</label>
<input type="text" id="name" name="name" required size="10" />
<input
id="process_button"
type="submit"
value="Create File"
class="button primary"
/>
</div>
</form>
<br />
<strong>Input files:</strong>
<ul>
{% for file in file_data['input'] %}