Spaces:
Running
Running
import subprocess | |
import gradio as gr | |
def build_android_app(app_name, package_name, website_url, app_logo): | |
try: | |
# 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() |