Download app.py from TONYAI123/Encrypto: direct link, hf CLI and curl.
- Browser
- Download file 2.82 kB
-
https://huggingface.co/spaces/TONYAI123/Encrypto/resolve/main/app.py
- Command line
-
hf download hf://spaces/TONYAI123/Encrypto/app.py
-
curl -L -o app.py https://huggingface.co/spaces/TONYAI123/Encrypto/resolve/main/app.py
2.82 kB
| import gradio as gr | |
| import base64, hashlib, tempfile, os, subprocess | |
| from cryptography.fernet import Fernet | |
| from pathlib import Path | |
| def derive_key(password: str) -> bytes: | |
| digest = hashlib.sha256(password.encode("utf-8")).digest() | |
| return base64.urlsafe_b64encode(digest) | |
| INSTALLER_TEMPLATE = r''' | |
| import os, shutil, string | |
| from pathlib import Path | |
| APP_NAME = "Encrypto" | |
| def find_flash_drive(): | |
| import string, os | |
| from pathlib import Path | |
| for letter in string.ascii_uppercase: | |
| drive = Path(f"{letter}:/") | |
| if drive.exists() and os.path.ismount(drive): | |
| return drive | |
| return None | |
| def main(): | |
| print(f"=== {APP_NAME} Flash Installer ===") | |
| here = Path(__file__).parent | |
| data_file = here / "Encrypto.en" | |
| if not data_file.exists(): | |
| print("Error: Encrypto.en not found next to this program.") | |
| input("Press Enter to exit.") | |
| return | |
| flash = find_flash_drive() | |
| if not flash: | |
| print("No flash drive detected. Insert one and try again.") | |
| input("Press Enter to exit.") | |
| return | |
| dest = flash / "Encrypto.en" | |
| shutil.copy2(data_file, dest) | |
| print(f"Encrypted file copied to: {dest}") | |
| print("Done.") | |
| input("Press Enter to exit.") | |
| if __name__ == "__main__": | |
| main() | |
| ''' | |
| def build_encrypto(file, password): | |
| if file is None: | |
| return None, "No file uploaded." | |
| if not password: | |
| return None, "Password is required." | |
| key = derive_key(password) | |
| f = Fernet(key) | |
| with open(file.name, "rb") as f_in: | |
| data = f_in.read() | |
| encrypted = f.encrypt(data) | |
| tmp = Path(tempfile.mkdtemp()) | |
| data_path = tmp / "Encrypto.en" | |
| installer_py = tmp / "Encrypto_installer.py" | |
| exe_output = tmp / "Encrypto.exe" | |
| data_path.write_bytes(encrypted) | |
| installer_py.write_text(INSTALLER_TEMPLATE) | |
| # Build EXE using PyInstaller (must be available in the environment) | |
| subprocess.run( | |
| [ | |
| "pyinstaller", | |
| "--onefile", | |
| "--name", "Encrypto", | |
| "--distpath", str(tmp), | |
| str(installer_py), | |
| ], | |
| check=True | |
| ) | |
| return str(exe_output), "Encrypto.exe ready. Download it and run on your PC." | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Encrypto — Secure Flash Installer Builder") | |
| file_input = gr.File(label="Upload file to protect") | |
| password_input = gr.Textbox(label="Password", type="password") | |
| build_button = gr.Button("Build Encrypto.exe") | |
| exe_output = gr.File(label="Download Encrypto.exe") | |
| status_output = gr.Textbox(label="Status", interactive=False) | |
| build_button.click( | |
| fn=build_encrypto, | |
| inputs=[file_input, password_input], | |
| outputs=[exe_output, status_output] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |