Spaces:
Sleeping
Sleeping
| import subprocess | |
| import gradio as gr | |
| import platform | |
| import os | |
| def install_flutter(): | |
| if platform.system() == "Windows": | |
| # Download the Flutter installation bundle | |
| subprocess.check_call(["powershell", "curl", "-o", "flutter_windows_stable.zip", "https://storage.googleapis.com/flutter_infra/releases/stable/windows/flutter_windows_stable.zip"]) | |
| # Extract the zip file | |
| subprocess.check_call(["powershell", "Expand-Archive", "-Path", "flutter_windows_stable.zip", "-DestinationPath", "C:\\src\\flutter"]) | |
| # Update the system's PATH environment variable | |
| subprocess.check_call(["powershell", "setx", "PATH", "%PATH%;C:\\src\\flutter\\bin"]) | |
| elif platform.system() == "Darwin": # macOS | |
| # Install Flutter using Homebrew | |
| subprocess.check_call(["brew", "install", "--cask", "flutter"]) | |
| elif platform.system() == "Linux": | |
| # Download the Flutter installation bundle | |
| subprocess.check_call(["wget", "https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_stable.tar.xz"]) | |
| # Extract the tar file | |
| subprocess.check_call(["tar", "xvf", "flutter_linux_stable.tar.xz", "-C", "~/development/"]) | |
| # Update the system's PATH environment variable | |
| with open(os.path.expanduser("~/.bashrc"), "a") as f: | |
| f.write("export PATH=$PATH:~/development/flutter/bin") | |
| subprocess.check_call(["source", "~/.bashrc"]) | |
| def build_android_app(app_name, package_name, website_url, app_logo): | |
| try: | |
| # Install Flutter if it's not already installed | |
| if not subprocess.check_output(["which", "flutter"]).decode("utf-8"): | |
| install_flutter() | |
| # Create a new Android app | |
| subprocess.check_call(["flutter", "create", app_name]) | |
| # Configure the app | |
| with open(f"{app_name}/pubspec.yaml", "r+") as f: | |
| content = f.read() | |
| f.seek(0) | |
| f.write(content.replace("name: flutter_app", f"name: {app_name}").replace("description: A new Flutter project.", f"description: {website_url}").replace("# The following line ensures that the Material Icons font is\n # included with your application, so that you can use the icons in\n # the material Icons class.", f" flutter:\n assets:\n - {app_logo}")) | |
| f.truncate() | |
| # Install dependencies | |
| subprocess.check_call(["flutter", "pub", "get"], cwd=app_name) | |
| # Run the app | |
| subprocess.check_call(["flutter", "run"], cwd=app_name) | |
| return "App built successfully." | |
| except Exception as e: | |
| return f"Error: {str(e)}" | |
| # Gradio interface setup | |
| demo = gr.Blocks() | |
| with demo: | |
| gr.Markdown("## Android App Builder\nEnter your app details to build an Android app") | |
| with gr.Row(): | |
| app_name = gr.Textbox(label="App Name") | |
| package_name = gr.Textbox(label="Package Name") | |
| website_url = gr.Textbox(label="Website URL") | |
| app_logo = gr.Textbox(label="App Logo") | |
| output = gr.Textbox(label="Output", placeholder="Output will appear here", lines=10) | |
| # Button to trigger app building | |
| build_button = gr.Button("Build App") | |
| # Bind the button to the function that builds the app | |
| build_button.click(fn=build_android_app, inputs=[app_name, package_name, website_url, app_logo], outputs=output) | |
| # Launch the Gradio app | |
| demo.launch() |