Peeble commited on
Commit
c204627
·
verified ·
1 Parent(s): ea198fd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -0
app.py ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import shutil
3
+ import subprocess
4
+ import os
5
+
6
+ UPLOAD_FOLDER = "./uploads/"
7
+ APK_OUTPUT_FOLDER = "./output_apk/"
8
+
9
+ # Ensure directories exist
10
+ os.makedirs(UPLOAD_FOLDER, exist_ok=True)
11
+ os.makedirs(APK_OUTPUT_FOLDER, exist_ok=True)
12
+
13
+ def convert_exe_to_apk(file):
14
+ # Save EXE file
15
+ exe_path = os.path.join(UPLOAD_FOLDER, file.name)
16
+ shutil.copyfile(file.name, exe_path)
17
+
18
+ # Step 1: Extract assets using AssetRipper
19
+ assetripper_command = f"AssetRipperConsole {exe_path} -o ./unity_project"
20
+ subprocess.run(assetripper_command, shell=True)
21
+
22
+ # Step 2: Build APK using Unity CLI
23
+ unity_command = (
24
+ "Unity -batchmode -nographics -quit "
25
+ "-projectPath ./unity_project "
26
+ "-executeMethod BuildScript.PerformBuild"
27
+ )
28
+ subprocess.run(unity_command, shell=True)
29
+
30
+ # Path to the generated APK
31
+ apk_path = os.path.join(APK_OUTPUT_FOLDER, "converted_app.apk")
32
+
33
+ # Check if APK was created successfully
34
+ if os.path.exists(apk_path):
35
+ return apk_path
36
+ else:
37
+ return "Error: APK conversion failed."
38
+
39
+ # Gradio Interface
40
+ with gr.Blocks() as app:
41
+ gr.Markdown("## EXE to APK Converter")
42
+
43
+ with gr.Row():
44
+ upload_button = gr.UploadButton("Upload EXE File", file_types=[".exe"])
45
+
46
+ output = gr.File(label="Download APK")
47
+
48
+ upload_button.upload(convert_exe_to_apk, upload_button, output)
49
+
50
+ app.launch()