sudo-soldier commited on
Commit
9ebdcbe
·
verified ·
1 Parent(s): 99c70b1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -24
app.py CHANGED
@@ -1,26 +1,36 @@
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()
 
 
 
 
1
  import os
2
+ import subprocess
3
+ from flask import Flask, request, send_file
4
+
5
+ app = Flask(__name__)
6
+
7
+ # Endpoint to generate APK from PWA URL
8
+ @app.route("/generate-apk", methods=["POST"])
9
+ def generate_apk():
10
+ pwa_url = request.form["url"]
11
+
12
+ if not pwa_url:
13
+ return "URL is required", 400
14
+
15
+ # Create the Bubblewrap configuration and generate APK
16
+ try:
17
+ subprocess.run(["bubblewrap", "init", "--manifest", pwa_url], check=True)
18
+
19
+ # Build the APK
20
+ subprocess.run(["bubblewrap", "build"], check=True)
21
+
22
+ # Assuming APK is stored in 'output' directory
23
+ apk_path = "output/app-release.apk"
24
+
25
+ # Check if APK was generated
26
+ if os.path.exists(apk_path):
27
+ return send_file(apk_path, as_attachment=True)
28
+ else:
29
+ return "APK generation failed", 500
30
+
31
+ except subprocess.CalledProcessError as e:
32
+ return f"Error generating APK: {str(e)}", 500
33
+
34
+ if __name__ == "__main__":
35
+ app.run(host="0.0.0.0", port=7860)
36