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) app.config.from_pyfile("config.py", silent=True)
for blueprint in (homescreen, mainapp): for blueprint in (homescreen, mainapp):
# for blueprint in (homescreen,): # for blueprint in (homescreen,):
app.register_blueprint(blueprint) app.register_blueprint(blueprint)
return app return app

View File

@@ -3,7 +3,7 @@ from pathlib import Path
# Pip # Pip
from anki_hsk_creator import api 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 anki_hsk_creator.utility import ProcessFile
from flask import ( from flask import (
Blueprint, Blueprint,
@@ -27,33 +27,44 @@ mainapp = Blueprint(
@mainapp.route("/", methods=["GET"]) @mainapp.route("/", methods=["GET"])
def app(): def app():
"""Main app entry pages""" """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", "POST", "DELETE"])
@mainapp.route("/list/", methods=["GET"]) @mainapp.route("/list/", methods=["GET", "POST", "DELETE"])
@mainapp.route("/list/<path:listing_path>", methods=["GET"]) @mainapp.route("/list/<path:listing_path>", methods=["GET", "POST", "DELETE"])
def file_list(listing_path=""): def file_list(listing_path=""):
"""Path for file lister""" """Path for file lister"""
listing_path = Path(listing_path) if request.method == "GET":
root_files = {file: [] for file in api.list_input_files()} listing_path = Path(listing_path)
level = root_files root_files = {file: [] for file in api.list_input_files()}
level_path = Path() level = root_files
for part in listing_path.parts: level_path = Path()
level_path = level_path / part for part in listing_path.parts:
level[level_path] = {file: [] for file in api.list_input_files(level_path)} level_path = level_path / part
level = level[level_path] level[level_path] = {file: [] for file in api.list_input_files(level_path)}
level = level[level_path]
if listing_path: if listing_path:
file_data = api.analize_input_files(listing_path) file_data = api.analize_input_files(listing_path)
else: else:
file_data = api.analize_input_files(None) file_data = api.analize_input_files(None)
return render_template( return render_template(
"file_list.html", "file_list.html",
file_data=file_data, file_data=file_data,
root_files=root_files, root_files=root_files,
listing_path=listing_path, 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"]) @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) response.set_cookie("download_started", "true", max_age=10)
return response 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"]) @mainapp.route("/process/<path:listing_path>", methods=["GET", "POST"])

View File

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

View File

@@ -107,8 +107,22 @@
<div class="content"> <div class="content">
<h3>Current Path: {{ listing_path or "-" }}</h3> <h3>Current Path: {{ listing_path or "-" }}</h3>
<br />
<ul class="items"> <ul class="items">
<li> <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> <strong>Input files:</strong>
<ul> <ul>
{% for file in file_data['input'] %} {% for file in file_data['input'] %}