Fix Whisper (#27)

This commit is contained in:
Patrick Stevens
2024-02-02 16:12:09 +00:00
committed by GitHub
parent 24d3d8c00a
commit e879dbcd60
2 changed files with 35 additions and 30 deletions

View File

@@ -156,11 +156,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1705660020, "lastModified": 1706473109,
"narHash": "sha256-1tOuNh+UbiZlaC8RrpQzzypgnLBC67eRlBunfkE4sbQ=", "narHash": "sha256-iyuAvpKTsq2u23Cr07RcV5XlfKExrG8gRpF75hf1uVc=",
"owner": "nix-community", "owner": "nix-community",
"repo": "home-manager", "repo": "home-manager",
"rev": "2064348e555b6aa963da6372a8f14e6acb80a176", "rev": "d634c3abafa454551f2083b054cd95c3f287be61",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -226,11 +226,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1705458851, "lastModified": 1706373441,
"narHash": "sha256-uQvEhiv33Zj/Pv364dTvnpPwFSptRZgVedDzoM+HqVg=", "narHash": "sha256-S1hbgNbVYhuY2L05OANWqmRzj4cElcbLuIkXTb69xkk=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "8bf65f17d8070a0a490daf5f1c784b87ee73982c", "rev": "56911ef3403a9318b7621ce745f5452fb9ef6867",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -242,11 +242,11 @@
}, },
"nixpkgs-stable": { "nixpkgs-stable": {
"locked": { "locked": {
"lastModified": 1705033721, "lastModified": 1705957679,
"narHash": "sha256-K5eJHmL1/kev6WuqyqqbS1cdNnSidIZ3jeqJ7GbrYnQ=", "narHash": "sha256-Q8LJaVZGJ9wo33wBafvZSzapYsjOaNjP/pOnSiKVGHY=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "a1982c92d8980a0114372973cbdfe0a307f1bdea", "rev": "9a333eaa80901efe01df07eade2c16d183761fa3",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -273,11 +273,11 @@
}, },
"nixpkgs_3": { "nixpkgs_3": {
"locked": { "locked": {
"lastModified": 1704842529, "lastModified": 1706173671,
"narHash": "sha256-OTeQA+F8d/Evad33JMfuXC89VMetQbsU4qcaePchGr4=", "narHash": "sha256-lciR7kQUK2FCAYuszyd7zyRRmTaXVeoZsCyK6QFpGdk=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "eabe8d3eface69f5bb16c18f8662a702f50c20d5", "rev": "4fddc9be4eaf195d631333908f2a454b03628ee5",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -380,11 +380,11 @@
"nixpkgs": "nixpkgs_2" "nixpkgs": "nixpkgs_2"
}, },
"locked": { "locked": {
"lastModified": 1703937582, "lastModified": 1706573865,
"narHash": "sha256-M4y/xbrocPoLwG4qUUdCoBvOHumPAGlMoeo8SpWjn0M=", "narHash": "sha256-Gfk5mMz6gRLVwljXrPTfqAX7Bp8UQK4vKtXu9kYkzQM=",
"ref": "refs/heads/main", "ref": "refs/heads/main",
"rev": "cdbc73b07f3cac88e446fbe73c4b0c6616448319", "rev": "e96ae78665db13cbf4745c04d634a8a878549768",
"revCount": 8, "revCount": 10,
"type": "git", "type": "git",
"url": "https://gitea.patrickstevens.co.uk/patrick/puregym-unofficial-dotnet" "url": "https://gitea.patrickstevens.co.uk/patrick/puregym-unofficial-dotnet"
}, },
@@ -469,11 +469,11 @@
"nixpkgs-stable": "nixpkgs-stable" "nixpkgs-stable": "nixpkgs-stable"
}, },
"locked": { "locked": {
"lastModified": 1705356877, "lastModified": 1706410821,
"narHash": "sha256-274jL1cH64DcXUXebVMZBRUsTs3FvFlPIPkCN/yhSnI=", "narHash": "sha256-iCfXspqUOPLwRobqQNAQeKzprEyVowLMn17QaRPQc+M=",
"owner": "Mic92", "owner": "Mic92",
"repo": "sops-nix", "repo": "sops-nix",
"rev": "87755331580fdf23df7e39b46d63ac88236bf42c", "rev": "73bf36912e31a6b21af6e0f39218e067283c67ef",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -571,11 +571,11 @@
"scripts": "scripts_4" "scripts": "scripts_4"
}, },
"locked": { "locked": {
"lastModified": 1705693021, "lastModified": 1706487253,
"narHash": "sha256-Ew7yxjYvwG9IE6YNPxcHNQUn2T8es1yWoK/f+x7UyCM=", "narHash": "sha256-t72k/g6topd9INA2PEjO+NIaC56EyTUIOtDar6V/nAM=",
"owner": "Smaug123", "owner": "Smaug123",
"repo": "static-site-pipeline", "repo": "static-site-pipeline",
"rev": "da3a4d2e53e3068755fcd49b74bcfcf2800c197d", "rev": "18314d94f67917c42202cc1201cbccde7ddb181a",
"type": "github" "type": "github"
}, },
"original": { "original": {
@@ -591,11 +591,11 @@
"nixpkgs": "nixpkgs_7" "nixpkgs": "nixpkgs_7"
}, },
"locked": { "locked": {
"lastModified": 1704121990, "lastModified": 1706487294,
"narHash": "sha256-ss1gDu3C7anyqEo0ksDuOPgcsD3EOUqtCwAt8ei6rM4=", "narHash": "sha256-h5Ptbc6Kks4zZllR2nHnbVPJAJyYOAHEqGyEBFNMvzE=",
"owner": "Smaug123", "owner": "Smaug123",
"repo": "whisper.cpp", "repo": "whisper.cpp",
"rev": "2ff0257983b4a3fe9cece30b215ba2b5087f2613", "rev": "96214a91134021ad6416f06cb7d35419a73b302c",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@@ -11,7 +11,7 @@ app = Flask(__name__)
youtube_regex = re.compile( youtube_regex = re.compile(
r"^(?:https?://)?(?:www\.)?(?:youtu\.be/|youtube\.com/(?:embed/|v/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$") 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): def generate_output(wav_file):
@@ -70,8 +70,8 @@ def transcribe_file():
file = request.args.get('file') file = request.args.get('file')
except KeyError: except KeyError:
return Response("must have a file as obtained from /upload, in the format ?file=...", status=400) return Response("must have a file as obtained from /upload, in the format ?file=...", status=400)
if alnum_regex.match(file) is None: if acceptable_regex.match(file) is None:
return Response(f"filename '{file}' was not alphanumeric", status=400) return Response(f"filename '{file}' did not match acceptable regex", status=400)
return Response(generate_output(file), mimetype="text/event-stream") return Response(generate_output(file), mimetype="text/event-stream")
@@ -86,6 +86,11 @@ def upload():
return 'No "file" part in request', 400 return 'No "file" part in request', 400
file = request.files['file'] file = request.files['file']
try:
os.mkdir("/tmp/whisper")
except FileExistsError:
pass
# Create temp file for this upload # Create temp file for this upload
handle, temp_file = tempfile.mkstemp(text=False) handle, temp_file = tempfile.mkstemp(text=False)
try: try:
@@ -111,8 +116,8 @@ def download():
except KeyError: except KeyError:
return Response("must have a file parameter", status=400) return Response("must have a file parameter", status=400)
if alnum_regex.match(file) is None: if acceptable_regex.match(file) is None:
return Response(f"file '{file}' was not alphanumeric, bad format", status=400) 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") return Response(open(f"/tmp/whisper/{file}.wav", 'rb').read(), mimetype="audio/wav")