Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import subprocess
|
3 |
+
import tempfile
|
4 |
+
import os
|
5 |
+
|
6 |
+
def build_apk(pwa_url):
|
7 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
8 |
+
os.chdir(tmpdir)
|
9 |
+
try:
|
10 |
+
result = subprocess.run(
|
11 |
+
["npx", "create-bubblewrap", "--manifest", f"{pwa_url}", "--directory", "."],
|
12 |
+
capture_output=True, text=True
|
13 |
+
)
|
14 |
+
if result.returncode != 0:
|
15 |
+
return f"Bubblewrap error: {result.stderr}"
|
16 |
+
subprocess.run(["./gradlew", "assembleRelease"], capture_output=True)
|
17 |
+
apk_path = "app/build/outputs/apk/release/app-release.apk"
|
18 |
+
if os.path.exists(apk_path):
|
19 |
+
return apk_path
|
20 |
+
else:
|
21 |
+
return "APK build failed or APK not found."
|
22 |
+
except Exception as e:
|
23 |
+
return f"Error: {str(e)}"
|
24 |
+
|
25 |
+
demo = gr.Interface(fn=build_apk, inputs="text", outputs="text", title="PWA to APK Builder")
|
26 |
+
demo.launch()
|