From 03fb3fa0e2f328912619794e111e9f7fff2ab024 Mon Sep 17 00:00:00 2001 From: MasterPhooey <106418429+MasterPhooey@users.noreply.github.com> Date: Sun, 5 Jan 2025 18:30:22 -0600 Subject: [PATCH] Update advanced_training_notebook.ipynb --- advanced_training_notebook.ipynb | 62 ++++++++++---------------------- 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/advanced_training_notebook.ipynb b/advanced_training_notebook.ipynb index f314237..12e37ee 100644 --- a/advanced_training_notebook.ipynb +++ b/advanced_training_notebook.ipynb @@ -640,73 +640,49 @@ "id": "ex_UIWvwtjAN" }, "outputs": [], - "source": [ + "source": [ "import shutil\n", "import json\n", - "from http.server import HTTPServer, SimpleHTTPRequestHandler\n", - "import threading\n", - "from pathlib import Path\n", + "from IPython.display import FileLink\n", "\n", - "# Copy the TFLite model file to the working directory\n", + "# Define the source path and desired download location for the TFLite file\n", "source_path = \"trained_models/wakeword/tflite_stream_state_internal_quant/stream_state_internal_quant.tflite\"\n", "destination_path = \"./stream_state_internal_quant.tflite\"\n", + "\n", + "# Copy the TFLite file to the current working directory\n", "shutil.copy(source_path, destination_path)\n", "\n", - "# Define the JSON metadata for the model\n", + "# Define the JSON file content\n", "json_data = {\n", " \"type\": \"micro\",\n", - " \"wake_word\": \"hey_norman\", # Adjust based on your target wake word\n", + " \"wake_word\": \"khum_puter\", # Adjust this if the target_word changes dynamically\n", " \"author\": \"master phooey\",\n", " \"website\": \"https://github.com/MasterPhooey/MicroWakeWord-Trainer-Docker\",\n", " \"model\": \"stream_state_internal_quant.tflite\",\n", " \"trained_languages\": [\"en\"],\n", " \"version\": 2,\n", " \"micro\": {\n", - " \"probability_cutoff\": 0.97, # Threshold for wake word detection\n", - " \"sliding_window_size\": 5, # Frames averaged for predictions\n", + " \"probability_cutoff\": 0.97,\n", + " \"sliding_window_size\": 5,\n", " \"feature_step_size\": 10,\n", - " \"tensor_arena_size\": 30000, # Memory allocation for TensorFlow Lite model\n", + " \"tensor_arena_size\": 30000,\n", " \"minimum_esphome_version\": \"2024.7.0\"\n", " }\n", "}\n", "\n", - "# Write the metadata to a JSON file\n", + "# Define the JSON file path\n", "json_path = \"./stream_state_internal_quant.json\"\n", + "\n", + "# Write the JSON file\n", "with open(json_path, \"w\") as json_file:\n", " json.dump(json_data, json_file, indent=2)\n", "\n", - "# Custom HTTPRequestHandler to set the Content-Disposition header\n", - "class CustomHTTPRequestHandler(SimpleHTTPRequestHandler):\n", - " def end_headers(self):\n", - " if self.path.endswith(\".json\"):\n", - " self.send_header(\"Content-Disposition\", \"attachment\")\n", - " super().end_headers()\n", - "\n", - "# Start an HTTP server in a separate thread\n", - "def start_server():\n", - " server = HTTPServer((\"0.0.0.0\", 8000), CustomHTTPRequestHandler)\n", - " print(\"Serving files on http://localhost:8000\")\n", - " server.serve_forever()\n", - "\n", - "thread = threading.Thread(target=start_server, daemon=True)\n", - "thread.start()\n", - "\n", - "# Generate download links with styled HTML\n", - "html_content = f\"\"\"\n", - "
,\n", - "\\\"MicroWakeWord\\n\"\n", - "

MicroWakeWord Trainer Docker

\n", - "
\\n\n", - "

Your files are ready for download:

\n", - "\n", - "

Click the links to download the files. Ensure the files are moved to the correct directory for deployment.

\n", - "\"\"\"\n", - "\n", - "from IPython.display import HTML\n", - "display(HTML(html_content))" + "# Generate download links for both files\n", + "print(\"Download your files:\")\n", + "print(\"TFLite Model:\")\n", + "display(FileLink(destination_path))\n", + "print(\"\\nJSON Metadata:\")\n", + "display(FileLink(json_path))" ] } ],