From e879dbcd606dc9e74196f472852e63fff313695a Mon Sep 17 00:00:00 2001 From: Patrick Stevens <3138005+Smaug123@users.noreply.github.com> Date: Fri, 2 Feb 2024 16:12:09 +0000 Subject: [PATCH] Fix Whisper (#27) --- PulumiWebServer/Nix/flake.lock | 50 +++++++++++++------------- PulumiWebServer/Nix/whisper/whisper.py | 15 +++++--- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/PulumiWebServer/Nix/flake.lock b/PulumiWebServer/Nix/flake.lock index c719447..680f625 100644 --- a/PulumiWebServer/Nix/flake.lock +++ b/PulumiWebServer/Nix/flake.lock @@ -156,11 +156,11 @@ ] }, "locked": { - "lastModified": 1705660020, - "narHash": "sha256-1tOuNh+UbiZlaC8RrpQzzypgnLBC67eRlBunfkE4sbQ=", + "lastModified": 1706473109, + "narHash": "sha256-iyuAvpKTsq2u23Cr07RcV5XlfKExrG8gRpF75hf1uVc=", "owner": "nix-community", "repo": "home-manager", - "rev": "2064348e555b6aa963da6372a8f14e6acb80a176", + "rev": "d634c3abafa454551f2083b054cd95c3f287be61", "type": "github" }, "original": { @@ -226,11 +226,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1705458851, - "narHash": "sha256-uQvEhiv33Zj/Pv364dTvnpPwFSptRZgVedDzoM+HqVg=", + "lastModified": 1706373441, + "narHash": "sha256-S1hbgNbVYhuY2L05OANWqmRzj4cElcbLuIkXTb69xkk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "8bf65f17d8070a0a490daf5f1c784b87ee73982c", + "rev": "56911ef3403a9318b7621ce745f5452fb9ef6867", "type": "github" }, "original": { @@ -242,11 +242,11 @@ }, "nixpkgs-stable": { "locked": { - "lastModified": 1705033721, - "narHash": "sha256-K5eJHmL1/kev6WuqyqqbS1cdNnSidIZ3jeqJ7GbrYnQ=", + "lastModified": 1705957679, + "narHash": "sha256-Q8LJaVZGJ9wo33wBafvZSzapYsjOaNjP/pOnSiKVGHY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "a1982c92d8980a0114372973cbdfe0a307f1bdea", + "rev": "9a333eaa80901efe01df07eade2c16d183761fa3", "type": "github" }, "original": { @@ -273,11 +273,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1704842529, - "narHash": "sha256-OTeQA+F8d/Evad33JMfuXC89VMetQbsU4qcaePchGr4=", + "lastModified": 1706173671, + "narHash": "sha256-lciR7kQUK2FCAYuszyd7zyRRmTaXVeoZsCyK6QFpGdk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "eabe8d3eface69f5bb16c18f8662a702f50c20d5", + "rev": "4fddc9be4eaf195d631333908f2a454b03628ee5", "type": "github" }, "original": { @@ -380,11 +380,11 @@ "nixpkgs": "nixpkgs_2" }, "locked": { - "lastModified": 1703937582, - "narHash": "sha256-M4y/xbrocPoLwG4qUUdCoBvOHumPAGlMoeo8SpWjn0M=", + "lastModified": 1706573865, + "narHash": "sha256-Gfk5mMz6gRLVwljXrPTfqAX7Bp8UQK4vKtXu9kYkzQM=", "ref": "refs/heads/main", - "rev": "cdbc73b07f3cac88e446fbe73c4b0c6616448319", - "revCount": 8, + "rev": "e96ae78665db13cbf4745c04d634a8a878549768", + "revCount": 10, "type": "git", "url": "https://gitea.patrickstevens.co.uk/patrick/puregym-unofficial-dotnet" }, @@ -469,11 +469,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1705356877, - "narHash": "sha256-274jL1cH64DcXUXebVMZBRUsTs3FvFlPIPkCN/yhSnI=", + "lastModified": 1706410821, + "narHash": "sha256-iCfXspqUOPLwRobqQNAQeKzprEyVowLMn17QaRPQc+M=", "owner": "Mic92", "repo": "sops-nix", - "rev": "87755331580fdf23df7e39b46d63ac88236bf42c", + "rev": "73bf36912e31a6b21af6e0f39218e067283c67ef", "type": "github" }, "original": { @@ -571,11 +571,11 @@ "scripts": "scripts_4" }, "locked": { - "lastModified": 1705693021, - "narHash": "sha256-Ew7yxjYvwG9IE6YNPxcHNQUn2T8es1yWoK/f+x7UyCM=", + "lastModified": 1706487253, + "narHash": "sha256-t72k/g6topd9INA2PEjO+NIaC56EyTUIOtDar6V/nAM=", "owner": "Smaug123", "repo": "static-site-pipeline", - "rev": "da3a4d2e53e3068755fcd49b74bcfcf2800c197d", + "rev": "18314d94f67917c42202cc1201cbccde7ddb181a", "type": "github" }, "original": { @@ -591,11 +591,11 @@ "nixpkgs": "nixpkgs_7" }, "locked": { - "lastModified": 1704121990, - "narHash": "sha256-ss1gDu3C7anyqEo0ksDuOPgcsD3EOUqtCwAt8ei6rM4=", + "lastModified": 1706487294, + "narHash": "sha256-h5Ptbc6Kks4zZllR2nHnbVPJAJyYOAHEqGyEBFNMvzE=", "owner": "Smaug123", "repo": "whisper.cpp", - "rev": "2ff0257983b4a3fe9cece30b215ba2b5087f2613", + "rev": "96214a91134021ad6416f06cb7d35419a73b302c", "type": "github" }, "original": { diff --git a/PulumiWebServer/Nix/whisper/whisper.py b/PulumiWebServer/Nix/whisper/whisper.py index 6d49b85..9b3d178 100644 --- a/PulumiWebServer/Nix/whisper/whisper.py +++ b/PulumiWebServer/Nix/whisper/whisper.py @@ -11,7 +11,7 @@ app = Flask(__name__) youtube_regex = re.compile( r"^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com/(?:embed/|v/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$") -alnum_regex = re.compile(r"^[a-zA-Z0-9]+$") +acceptable_regex = re.compile(r"^[a-zA-Z0-9_]+$") def generate_output(wav_file): @@ -70,8 +70,8 @@ def transcribe_file(): file = request.args.get('file') except KeyError: return Response("must have a file as obtained from /upload, in the format ?file=...", status=400) - if alnum_regex.match(file) is None: - return Response(f"filename '{file}' was not alphanumeric", status=400) + if acceptable_regex.match(file) is None: + return Response(f"filename '{file}' did not match acceptable regex", status=400) return Response(generate_output(file), mimetype="text/event-stream") @@ -86,6 +86,11 @@ def upload(): return 'No "file" part in request', 400 file = request.files['file'] + try: + os.mkdir("/tmp/whisper") + except FileExistsError: + pass + # Create temp file for this upload handle, temp_file = tempfile.mkstemp(text=False) try: @@ -111,8 +116,8 @@ def download(): except KeyError: return Response("must have a file parameter", status=400) - if alnum_regex.match(file) is None: - return Response(f"file '{file}' was not alphanumeric, bad format", status=400) + if acceptable_regex.match(file) is None: + return Response(f"file '{file}' did not match acceptable regex, bad format", status=400) return Response(open(f"/tmp/whisper/{file}.wav", 'rb').read(), mimetype="audio/wav")