update for dictation model
This commit is contained in:
@@ -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,14 +27,16 @@ 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"""
|
||||||
|
if request.method == "GET":
|
||||||
listing_path = Path(listing_path)
|
listing_path = Path(listing_path)
|
||||||
root_files = {file: [] for file in api.list_input_files()}
|
root_files = {file: [] for file in api.list_input_files()}
|
||||||
level = root_files
|
level = root_files
|
||||||
@@ -54,6 +56,15 @@ def file_list(listing_path=""):
|
|||||||
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"])
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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'] %}
|
||||||
|
|||||||
Reference in New Issue
Block a user