| | import gradio as gr |
| | import os |
| | import subprocess |
| | import tempfile |
| |
|
| | def create_buildozer_ini(): |
| | """Создает базовый buildozer.ini файл""" |
| | buildozer_config = """[app] |
| | title = MyApp |
| | package.name = myapp |
| | package.domain = org.test |
| | source.dir = . |
| | source.include_exts = py |
| | version = 0.1 |
| | requirements = python3,kivy,kivymd |
| | orientation = portrait |
| | osx.python_version = 3 |
| | osx.kivy_version = 1.9.1 |
| | fullscreen = 0 |
| | android.permissions = INTERNET |
| | android.api = 27 |
| | android.minapi = 21 |
| | android.sdk = 20 |
| | android.ndk = 19b |
| | android.private_storage = True |
| | android.accept_sdk_license = True |
| | """ |
| | with open("buildozer.ini", "w") as f: |
| | f.write(buildozer_config) |
| |
|
| | def build_apk(code): |
| | try: |
| | |
| | with tempfile.TemporaryDirectory() as temp_dir: |
| | os.chdir(temp_dir) |
| | |
| | |
| | with open("main.py", "w") as f: |
| | f.write(code) |
| | |
| | |
| | create_buildozer_ini() |
| | |
| | |
| | process = subprocess.Popen( |
| | ["buildozer", "android", "debug"], |
| | stdout=subprocess.PIPE, |
| | stderr=subprocess.PIPE |
| | ) |
| | |
| | output, error = process.communicate() |
| | |
| | |
| | apk_path = os.path.join(temp_dir, "bin") |
| | if os.path.exists(apk_path): |
| | apk_files = [f for f in os.listdir(apk_path) if f.endswith('.apk')] |
| | if apk_files: |
| | return os.path.join(apk_path, apk_files[0]) |
| | |
| | return f"Ошибка при сборке: {error.decode()}" |
| | |
| | except Exception as e: |
| | return f"Произошла ошибка: {str(e)}" |
| |
|
| | |
| | iface = gr.Interface( |
| | fn=build_apk, |
| | inputs=gr.Textbox(lines=10, label="Введите код на Python с Kivy MD"), |
| | outputs=gr.File(label="Скачать APK"), |
| | title="Kivy MD to APK Builder", |
| | description="Введите код на Python с Kivy MD для создания APK файла" |
| | ) |
| |
|
| | |
| | iface.launch() |