From f8cb8d6af661976a9d12f67b374912055566ab1f Mon Sep 17 00:00:00 2001 From: cyber <19499442+cyberofficial@users.noreply.github.com> Date: Mon, 31 Jul 2023 20:31:41 -0400 Subject: [PATCH] Split Functions into Modules * Start to split functions into separate modules * Fixed an issue in the main script where it loads the old fine tune model --- .../model_downloader.cpython-310.pyc | Bin 0 -> 1386 bytes .../version_checker.cpython-310.pyc | Bin 0 -> 1384 bytes modules/model_downloader.py | 29 ++++++++ modules/version_checker.py | 38 ++++++++++ transcribe_audio.py | 67 ++---------------- 5 files changed, 71 insertions(+), 63 deletions(-) create mode 100644 modules/__pycache__/model_downloader.cpython-310.pyc create mode 100644 modules/__pycache__/version_checker.cpython-310.pyc create mode 100644 modules/model_downloader.py create mode 100644 modules/version_checker.py diff --git a/modules/__pycache__/model_downloader.cpython-310.pyc b/modules/__pycache__/model_downloader.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5532da18f0260c6afc4de5aaeabd7f12bb51c02f GIT binary patch literal 1386 zcmc&!%We}f6tz7w$uy(|%92)!cvKBi(l!(*Z)l@R2#G=ouh24@#wKw)nMrL=3sE8= zm2Jf@lw}tD0AIj2c*}}4J0t|x)0Re*uCe9gYv0G*YadTEIG91uUM+l~pB#j~nniyj zu($(5P6ALwae%63CIN2ZD#p8eq)Mno?f0l^QHQ2rwkdv$^678jg&yRww$(aq*34?Z zr9c>fF$d%OX8;A!w@gIRMGCKy4l*&fNf#@tgIDbxLY#4 zDLOziTjaxN*9O}(XpU{;GFl$$Ivq#MbnG3s1Kt>QtepXxHq!cqXOO)Oeapfqbf=J< z+k}17U%)t|UF_FFw%H_G1a%HRXkRHun_&?7l!x`)YaX(KibFXR&Fi?w{6Lc@+?HZ>yOQreQnewHXQh9Fv z?o?@ZOfdP6?enFn=}VWVFP6sqST)wz+naaqE#9y4#$-LZ%%4azVSA}*q1*~-{Zc$&cUP@cB2s9Qtn^fcNRcW_Ye4+7c?Iely zkT?Soe_VflZK=*xBVJirWPVVn@Fpu%gdfVlS3C-rpt3k%(#$OI{^Tu+t+#sk&k5`v zfJXy(PUw3Mz{NHm!YA-B&H~yv1D(7hKSzF%cO$>DDRB;rj(i)!0=6tDrnG8o^MzCqtSstBMH66URov;o(EdG_t`Bd7znxnGZ$ut*FUpX0_S ze~3Nf2iEz1Dv6WE>9hfJxw~){Bt3fgrusfPY>dwv7z4;V;*^mS#u34in@Ti&QIq&d YX!pi0MQ&kmlIF+iqAYf?OR|H%0e8lOwg3PC literal 0 HcmV?d00001 diff --git a/modules/__pycache__/version_checker.cpython-310.pyc b/modules/__pycache__/version_checker.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cd02c58a5983668f955c3f37c5fffb3386b99005 GIT binary patch literal 1384 zcmZ8gPmkL~6rZsj#|fKNceno}F2f$6fv!VUsn7@zXocW__RtgrCdit2CW*U_C%hTA ztmT}_x2P&@k9?Ez6@2BiAAz2D<0RcJW6hg4^Zv~Hz4=-7dR>C!!O3g!cZ-mJ?B?ol zaPu`z{W%Ij1kFgaUTH*y6FI_-T;W9?t}W4ueBq1spCoFFKy+{o1Rarn_X4BINg3P= zKMfx~{On%TOU@<|)O4CADbLEIxiL#U91LcunHQ5VQH#Ml9)rli4t6K-I{?amUU|hX>KsO3v#Jq^(>cAcN#tC3t4yU{qd5U zdF>XE*-P|NjLA(VbhCfcLO@!+_JlI+8qBy-~hqD8U8#RuNygjBzbo9I94B9&ghnbD5k<2$yH|K7xziO=}siZ=<+LyR_^0bccGVc{Ff5dJQMs zKx2aQ?XbTA{vK;uJwe5g6*1H}#ufCryP_2pq@ZxWLb{#0@S*XLa+Y|mCEiQV5(Lk- zYs<85ku7QP+~3&SHs+E}mS+9nq&zSdYy#;-#=H=zLS*F!TP`e8z2GL9hwKNH@QiJ` zFl6Qa-7POJ&+Z)Kd!#}FE0zM=m(Q3{4TZ3o$cJrsSl;;2I!MN!@-*X<3^jvE`@g7y zall;$l8ZA|=q3r0@c$Y1jxG7}w>gn`e%;>G(sUVm*i6{9Vh2Ut{Vp}%7n4WGuD%oX zG7Bi)2JBlm%ZRnOZUgq3w~nU@;s%e@@8hwyHV+>*Z~}Ur2J{+g`_%gv?7R0nU>_4Y zR@_8U_eR*GzfWQMIixAOZD|N9!+ecJ}@Q D6jy)V literal 0 HcmV?d00001 diff --git a/modules/model_downloader.py b/modules/model_downloader.py new file mode 100644 index 0000000..9760a15 --- /dev/null +++ b/modules/model_downloader.py @@ -0,0 +1,29 @@ +import requests +from tqdm import tqdm +import re + +def fine_tune_model_dl(): + print("Downloading fine-tuned model... [Via OneDrive (Public)]") + url = "https://onedrive.live.com/download?cid=22FB8D582DCFA12B&resid=22FB8D582DCFA12B%21456432&authkey=AIRKZih0go6iUTs" + r = requests.get(url, stream=True) + total_length = int(r.headers.get('content-length')) + with tqdm(total=total_length, unit='B', unit_scale=True, unit_divisor=1024) as pbar: + with open("models/fine_tuned_model-v2.pt", "wb") as f: + for chunk in r.iter_content(chunk_size=1024): + if chunk: + f.write(chunk) + pbar.update(1024) + print("Fine-tuned model downloaded.") + +def fine_tune_model_dl_compressed(): + print("Downloading fine-tuned compressed model... [Via OneDrive (Public)]") + url = "https://onedrive.live.com/download?cid=22FB8D582DCFA12B&resid=22FB8D582DCFA12B%21456433&authkey=AOTrQ949dOFhdxQ" + r = requests.get(url, stream=True) + total_length = int(r.headers.get('content-length')) + with tqdm(total=total_length, unit='B', unit_scale=True, unit_divisor=1024) as pbar: + with open("models/fine_tuned_model_compressed_v2.pt", "wb") as f: + for chunk in r.iter_content(chunk_size=1024): + if chunk: + f.write(chunk) + pbar.update(1024) + print("Fine-tuned model (compressed) downloaded.") \ No newline at end of file diff --git a/modules/version_checker.py b/modules/version_checker.py new file mode 100644 index 0000000..35c8989 --- /dev/null +++ b/modules/version_checker.py @@ -0,0 +1,38 @@ +import requests +import re + +version = "1.0.9971" +ScriptCreator = "cyberofficial" +GitHubRepo = "https://github.com/cyberofficial/Synthalingua" +repo_owner = "cyberofficial" +repo_name = "Synthalingua" + +def get_remote_version(repo_owner, repo_name, file_path): + url = f"https://raw.githubusercontent.com/{repo_owner}/{repo_name}/master/{file_path}" + response = requests.get(url) + + if response.status_code == 200: + remote_file_content = response.text + version_search = re.search(r'version\s*=\s*"([\d.]+)"', remote_file_content) + if version_search: + remote_version = version_search.group(1) + return remote_version + else: + print("Error: Version not found in the remote file.") + return None + else: + print(f"An error occurred. Status code: {response.status_code}") + return None + +def check_for_updates(): + local_version = version + remote_version = get_remote_version(repo_owner, repo_name, "transcribe_audio.py") + + if remote_version is not None: + if remote_version != local_version: + print(f"Version mismatch. Local version: {local_version}, remote version: {remote_version}") + print("Consider updating to the latest version.") + print(f"Update available at: " + GitHubRepo) + else: + print("You are already using the latest version.") + print(f"Current version: {local_version}") diff --git a/transcribe_audio.py b/transcribe_audio.py index fbce0e0..602ca8d 100644 --- a/transcribe_audio.py +++ b/transcribe_audio.py @@ -94,74 +94,15 @@ except: cuda_available = False +from modules.version_checker import check_for_updates +from modules.model_downloader import fine_tune_model_dl, fine_tune_model_dl_compressed + # Code is semi documented, but if you have any questions, feel free to ask in the Discussions tab. def main(): - version = "1.0.9971" - ScriptCreator = "cyberofficial" - GitHubRepo = "https://github.com/cyberofficial/Real-Time-Synthalingua" - repo_owner = "cyberofficial" - repo_name = "Synthalingua" - - def get_remote_version(repo_owner, repo_name, file_path): - url = f"https://raw.githubusercontent.com/{repo_owner}/{repo_name}/master/{file_path}" - response = requests.get(url) - - if response.status_code == 200: - remote_file_content = response.text - version_search = re.search(r'version\s*=\s*"([\d.]+)"', remote_file_content) - if version_search: - remote_version = version_search.group(1) - return remote_version - else: - print("Error: Version not found in the remote file.") - return None - else: - print(f"An error occurred. Status code: {response.status_code}") - return None - - def check_for_updates(): - local_version = version - remote_version = get_remote_version(repo_owner, repo_name, "transcribe_audio.py") - - if remote_version is not None: - if remote_version != local_version: - print(f"Version mismatch. Local version: {local_version}, remote version: {remote_version}") - print("Consider updating to the latest version.") - print(f"Update available at: " + GitHubRepo) - else: - print("You are already using the latest version.") - print(f"Current version: {local_version}") - check_for_updates() - def fine_tune_model_dl(): - print("Downloading fine-tuned model... [Via OneDrive (Public)]") - url = "https://onedrive.live.com/download?cid=22FB8D582DCFA12B&resid=22FB8D582DCFA12B%21456432&authkey=AIRKZih0go6iUTs" - r = requests.get(url, stream=True) - total_length = int(r.headers.get('content-length')) - with tqdm(total=total_length, unit='B', unit_scale=True, unit_divisor=1024) as pbar: - with open("models/fine_tuned_model-v2.pt", "wb") as f: - for chunk in r.iter_content(chunk_size=1024): - if chunk: - f.write(chunk) - pbar.update(1024) - print("Fine-tuned model downloaded.") - - def fine_tune_model_dl_compressed(): - print("Downloading fine-tuned compressed model... [Via OneDrive (Public)]") - url = "https://onedrive.live.com/download?cid=22FB8D582DCFA12B&resid=22FB8D582DCFA12B%21456433&authkey=AOTrQ949dOFhdxQ" - r = requests.get(url, stream=True) - total_length = int(r.headers.get('content-length')) - with tqdm(total=total_length, unit='B', unit_scale=True, unit_divisor=1024) as pbar: - with open("models/fine_tuned_model_compressed_v2.pt", "wb") as f: - for chunk in r.iter_content(chunk_size=1024): - if chunk: - f.write(chunk) - pbar.update(1024) - print("Fine-tuned model (compressed) downloaded.") - def record_callback(_, audio:sr.AudioData) -> None: data = audio.get_raw_data() data_queue.put(data) @@ -495,7 +436,7 @@ def print_warning(old_ram_flag, new_ram_flag, needed_vram, detected_vram): fine_tune_model_dl() try: if args.use_finetune == True: - whisper.load_model("models/fine_tuned_model.pt", device=device, download_root="models") + whisper.load_model("models/fine_tuned_model-v2.pt", device=device, download_root="models") print("Fine-tuned model loaded into memory.") if device.type == "cuda": max_split_size_mb = 128