mirror of
https://github.com/MrSanZz/KawaiiGPT.git
synced 2025-12-03 17:13:01 +00:00
Update install.py
This commit is contained in:
85
install.py
85
install.py
@@ -4,7 +4,7 @@ try:
|
||||
import subprocess
|
||||
except ModuleNotFoundError as e:
|
||||
import os
|
||||
module = str(e).replace(" No module named'", '').replace("'", '')
|
||||
module = str(e).replace("No module named ", '').replace("'", '')
|
||||
os.system(f'python3 -m pip install {module} && python3 install.py')
|
||||
|
||||
repo_owner = 'MrSanZz'
|
||||
@@ -12,7 +12,21 @@ repo_name = 'KawaiiGPT'
|
||||
files_to_check = ['kawai.py', 'requirements.txt']
|
||||
package_termux = ['pkg update && pkg upgrade -y', 'pkg install git', 'pkg install python3']
|
||||
package_linux = ['apt-get update && apt-get upgrade', 'apt install python3 && apt install python3-pip', 'apt install git']
|
||||
module = ['prompt_toolkit', 'requests', 'fake_useragent', 'edge_tts', 'deep_translator', 'sounddevice', 'soundfile', 'regex', 'psutil', 'colorama', 'pycryptodome', 'pexpect']
|
||||
|
||||
module = [
|
||||
'prompt_toolkit',
|
||||
'requests',
|
||||
'fake_useragent',
|
||||
'edge_tts',
|
||||
'deep_translator',
|
||||
'sounddevice',
|
||||
'soundfile',
|
||||
'regex',
|
||||
'psutil',
|
||||
'colorama',
|
||||
'pycryptodome',
|
||||
'pexpect'
|
||||
]
|
||||
|
||||
def get_latest_release():
|
||||
url = f'https://api.github.com/repos/{repo_owner}/{repo_name}/releases/latest'
|
||||
@@ -20,7 +34,7 @@ def get_latest_release():
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
print(f'====Nothing need to be updated====')
|
||||
print(f'====Nothing needs to be updated====')
|
||||
return None
|
||||
|
||||
def download_file(release_url, file_name):
|
||||
@@ -29,16 +43,24 @@ def download_file(release_url, file_name):
|
||||
if response.status_code == 200:
|
||||
with open(file_name, 'wb') as file:
|
||||
file.write(response.content)
|
||||
print('====Downloaded {file_name}====')
|
||||
print(f'====Downloaded {file_name}====')
|
||||
else:
|
||||
print(f'====Failed to download {file_name}====')
|
||||
|
||||
def check_for_updates():
|
||||
latest_release = get_latest_release()
|
||||
if latest_release:
|
||||
release_url = latest_release['assets_url']
|
||||
for file_name in files_to_check:
|
||||
download_file(release_url, file_name)
|
||||
assets = latest_release.get('assets', [])
|
||||
for asset in assets:
|
||||
if asset['name'] in files_to_check:
|
||||
download_url = asset['browser_download_url']
|
||||
response = requests.get(download_url)
|
||||
if response.status_code == 200:
|
||||
with open(asset['name'], 'wb') as file:
|
||||
file.write(response.content)
|
||||
print(f'====Downloaded {asset["name"]}====')
|
||||
else:
|
||||
print(f'====Failed to download {asset["name"]}====')
|
||||
|
||||
def detect_os():
|
||||
if os.path.exists("/data/data/com.termux/files/usr/bin/bash"):
|
||||
@@ -49,24 +71,53 @@ def detect_os():
|
||||
def up_package():
|
||||
os_type = detect_os()
|
||||
if os_type == 1:
|
||||
print("Detected Termux environment")
|
||||
for command in package_termux:
|
||||
print(f"Executing: {command}")
|
||||
os.system(command)
|
||||
else:
|
||||
print("Detected Linux environment")
|
||||
for command in package_linux:
|
||||
print(f"Executing: {command}")
|
||||
os.system(command)
|
||||
|
||||
def main():
|
||||
print('='*4+'Updating package'+'='*4)
|
||||
up_package() if input('[~] Update package? Y/N: ').lower() == 'y' else print("[+] Skipping package update..")
|
||||
print('='*4+'Downloading module'+'='*4)
|
||||
def install_modules():
|
||||
print('='*4+'Installing Python modules'+'='*4)
|
||||
failed_modules = []
|
||||
for modules in module:
|
||||
try:
|
||||
os.system(f'python3 -m pip install {modules}')
|
||||
except:
|
||||
print(f'[!] Module {modules} cannot be downloaded')
|
||||
continue
|
||||
print('='*4+'Running'+'='*4)
|
||||
os.system('python3 kawai.py')
|
||||
print(f"Installing {modules}...")
|
||||
result = os.system(f'python3 -m pip install {modules}')
|
||||
if result != 0:
|
||||
failed_modules.append(modules)
|
||||
except Exception as e:
|
||||
print(f'[!] Module {modules} cannot be installed: {e}')
|
||||
failed_modules.append(modules)
|
||||
|
||||
if failed_modules:
|
||||
print(f"[!] Failed to install: {', '.join(failed_modules)}")
|
||||
print("[!] You may need to install these manually")
|
||||
|
||||
def main():
|
||||
print('='*4+'KawaiiGPT Installer'+'='*4)
|
||||
|
||||
print('='*4+'Updating system packages'+'='*4)
|
||||
if input('[~] Update system packages? Y/N: ').lower() == 'y':
|
||||
up_package()
|
||||
else:
|
||||
print("[+] Skipping package update..")
|
||||
|
||||
install_modules()
|
||||
|
||||
print('='*4+'Checking for updates'+'='*4)
|
||||
if input('[~] Check for latest release? Y/N: ').lower() == 'y':
|
||||
check_for_updates()
|
||||
|
||||
print('='*4+'Starting KawaiiGPT'+'='*4)
|
||||
if os.path.exists('kawai.py'):
|
||||
os.system('python3 kawai.py')
|
||||
else:
|
||||
print("[!] kawai.py not found. Please download it first.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user