Spaces:
Running
Running
:zap: use tmp dir for output path
Browse files
app.py
CHANGED
@@ -1,10 +1,15 @@
|
|
|
|
1 |
import os
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
from boilerplate_x.generator import ProjectGenerator
|
5 |
|
6 |
from blocks import customisation_block, github_repo_block
|
7 |
|
|
|
|
|
|
|
8 |
INTRO_MD = """
|
9 |
<center>
|
10 |
|
@@ -14,9 +19,7 @@ Create project boilerplate for any programming language in minutes, with just an
|
|
14 |
|
15 |
</center>
|
16 |
"""
|
17 |
-
|
18 |
-
OUTPUT_PATH = "outputs/"
|
19 |
-
OPT_MAP = {True: "yes", False: "no"}
|
20 |
|
21 |
|
22 |
def generate_boilerplate(
|
@@ -33,43 +36,44 @@ def generate_boilerplate(
|
|
33 |
"""Generates project boilerplate."""
|
34 |
if not api_key:
|
35 |
gr.Error("Please enter your OpenAI API key!")
|
36 |
-
|
37 |
os.environ["OPENAI_API_KEY"] = api_key
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
73 |
|
74 |
|
75 |
def build_app():
|
|
|
1 |
+
import logging
|
2 |
import os
|
3 |
+
import tempfile
|
4 |
|
5 |
import gradio as gr
|
6 |
from boilerplate_x.generator import ProjectGenerator
|
7 |
|
8 |
from blocks import customisation_block, github_repo_block
|
9 |
|
10 |
+
logging.basicConfig(level=logging.INFO)
|
11 |
+
logger = logging.getLogger("gradio")
|
12 |
+
|
13 |
INTRO_MD = """
|
14 |
<center>
|
15 |
|
|
|
19 |
|
20 |
</center>
|
21 |
"""
|
22 |
+
BOOL2STR = {True: "yes", False: "no"}
|
|
|
|
|
23 |
|
24 |
|
25 |
def generate_boilerplate(
|
|
|
36 |
"""Generates project boilerplate."""
|
37 |
if not api_key:
|
38 |
gr.Error("Please enter your OpenAI API key!")
|
|
|
39 |
os.environ["OPENAI_API_KEY"] = api_key
|
40 |
+
|
41 |
+
with tempfile.TemporaryDirectory() as output_path:
|
42 |
+
customisation_kwargs = {
|
43 |
+
"unit_tests": BOOL2STR[unit_tests],
|
44 |
+
"dockerization": BOOL2STR[dockerization],
|
45 |
+
"github_actions": BOOL2STR[github_actions],
|
46 |
+
"pre_commit_hooks": BOOL2STR[pre_commit_hooks],
|
47 |
+
}
|
48 |
+
|
49 |
+
if not gh_token:
|
50 |
+
gr.Error("Please enter your GitHub token!")
|
51 |
+
if not gh_repo_name:
|
52 |
+
gr.Error("Please enter your GitHub repository name!")
|
53 |
+
|
54 |
+
github_repo_creator_kwargs = {
|
55 |
+
"token": gh_token,
|
56 |
+
"repo_name": gh_repo_name,
|
57 |
+
"private": private,
|
58 |
+
"target_folder": output_path,
|
59 |
+
}
|
60 |
+
|
61 |
+
generator = ProjectGenerator(
|
62 |
+
prompt=prompt,
|
63 |
+
output_path=output_path,
|
64 |
+
verbose=True,
|
65 |
+
customisation_kwargs=customisation_kwargs,
|
66 |
+
github_repo_creator_kwargs=github_repo_creator_kwargs,
|
67 |
+
)
|
68 |
+
|
69 |
+
try:
|
70 |
+
logger.info("Generating project boilerplate...")
|
71 |
+
generator.generate_template()
|
72 |
+
except Exception as e:
|
73 |
+
logger.error(e)
|
74 |
+
gr.Error(e)
|
75 |
+
|
76 |
+
return f"Your project is now available on {generator.github_repo_url} 🚀 !"
|
77 |
|
78 |
|
79 |
def build_app():
|