Taf2023 commited on
Commit
09f8d76
·
verified ·
1 Parent(s): d475e29

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -74
app.py CHANGED
@@ -1,82 +1,22 @@
1
- import subprocess
2
  import gradio as gr
3
- import platform
4
  import os
5
 
6
- def install_flutter():
7
- if platform.system() == "Windows":
8
- # Download the Flutter installation bundle
9
- subprocess.check_call(["powershell", "curl", "-o", "flutter_windows_stable.zip", "https://storage.googleapis.com/flutter_infra/releases/stable/windows/flutter_windows_stable.zip"])
10
-
11
- # Extract the zip file
12
- subprocess.check_call(["powershell", "Expand-Archive", "-Path", "flutter_windows_stable.zip", "-DestinationPath", "C:\\src\\flutter"])
13
-
14
- # Update the system's PATH environment variable
15
- subprocess.check_call(["powershell", "setx", "PATH", "%PATH%;C:\\src\\flutter\\bin"])
16
-
17
- elif platform.system() == "Darwin": # macOS
18
- # Install Flutter using Homebrew
19
- subprocess.check_call(["brew", "install", "--cask", "flutter"])
20
-
21
- elif platform.system() == "Linux":
22
- # Download the Flutter installation bundle
23
- subprocess.check_call(["wget", "https://storage.googleapis.com/flutter_infra/releases/stable/linux/flutter_linux_stable.tar.xz"])
24
-
25
- # Extract the tar file
26
- subprocess.check_call(["tar", "xvf", "flutter_linux_stable.tar.xz", "-C", "~/development/"])
27
-
28
- # Update the system's PATH environment variable
29
- with open(os.path.expanduser("~/.bashrc"), "a") as f:
30
- f.write("export PATH=$PATH:~/development/flutter/bin")
31
-
32
- subprocess.check_call(["source", "~/.bashrc"])
33
-
34
- def build_android_app(app_name, package_name, website_url, app_logo):
35
  try:
36
- # Install Flutter if it's not already installed
37
- if not subprocess.check_output(["which", "flutter"]).decode("utf-8"):
38
- install_flutter()
39
-
40
- # Create a new Android app
41
- subprocess.check_call(["flutter", "create", app_name])
42
-
43
- # Configure the app
44
- with open(f"{app_name}/pubspec.yaml", "r+") as f:
45
- content = f.read()
46
- f.seek(0)
47
- 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}"))
48
- f.truncate()
49
-
50
- # Install dependencies
51
- subprocess.check_call(["flutter", "pub", "get"], cwd=app_name)
52
-
53
- # Run the app
54
- subprocess.check_call(["flutter", "run"], cwd=app_name)
55
-
56
- return "App built successfully."
57
-
58
  except Exception as e:
59
- return f"Error: {str(e)}"
60
-
61
- # Gradio interface setup
62
- demo = gr.Blocks()
63
-
64
- with demo:
65
- gr.Markdown("## Android App Builder\nEnter your app details to build an Android app")
66
-
67
- with gr.Row():
68
- app_name = gr.Textbox(label="App Name")
69
- package_name = gr.Textbox(label="Package Name")
70
-
71
- website_url = gr.Textbox(label="Website URL")
72
- app_logo = gr.Textbox(label="App Logo")
73
- output = gr.Textbox(label="Output", placeholder="Output will appear here", lines=10)
74
 
75
- # Button to trigger app building
76
- build_button = gr.Button("Build App")
77
-
78
- # Bind the button to the function that builds the app
79
- build_button.click(fn=build_android_app, inputs=[app_name, package_name, website_url, app_logo], outputs=output)
 
 
 
 
80
 
81
- # Launch the Gradio app
82
  demo.launch()
 
 
1
  import gradio as gr
 
2
  import os
3
 
4
+ def generate_html(name, code):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  try:
6
+ with open(f"{name}.html", "w") as f:
7
+ f.write(code)
8
+ return f"HTML file {name}.html generated successfully!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  except Exception as e:
10
+ return f"Error generating HTML file: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ demo = gr.Interface(
13
+ fn=generate_html,
14
+ inputs=[
15
+ gr.Textbox(label="File Name"),
16
+ gr.Code(label="HTML Code")
17
+ ],
18
+ outputs="text",
19
+ title="HTML Generator"
20
+ )
21
 
 
22
  demo.launch()