deeroid / app.py
sudo-soldier's picture
Upload app.py
e93c08a verified
raw
history blame
949 Bytes
import gradio as gr
import subprocess
import tempfile
import os
def build_apk(pwa_url):
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
try:
result = subprocess.run(
["npx", "create-bubblewrap", "--manifest", f"{pwa_url}", "--directory", "."],
capture_output=True, text=True
)
if result.returncode != 0:
return f"Bubblewrap error: {result.stderr}"
subprocess.run(["./gradlew", "assembleRelease"], capture_output=True)
apk_path = "app/build/outputs/apk/release/app-release.apk"
if os.path.exists(apk_path):
return apk_path
else:
return "APK build failed or APK not found."
except Exception as e:
return f"Error: {str(e)}"
demo = gr.Interface(fn=build_apk, inputs="text", outputs="text", title="PWA to APK Builder")
demo.launch()