ajndkr commited on
Commit
b3e3a0c
1 Parent(s): 24930d9

:zap: use tmp dir for output path

Browse files
Files changed (1) hide show
  1. app.py +43 -39
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
- output_path = OUTPUT_PATH
39
-
40
- customisation_kwargs = {
41
- "unit_tests": OPT_MAP[unit_tests],
42
- "dockerization": OPT_MAP[dockerization],
43
- "github_actions": OPT_MAP[github_actions],
44
- "pre_commit_hooks": OPT_MAP[pre_commit_hooks],
45
- }
46
-
47
- if not gh_token:
48
- gr.Error("Please enter your GitHub token!")
49
- if not gh_repo_name:
50
- gr.Error("Please enter your GitHub repository name!")
51
-
52
- github_repo_creator_kwargs = {
53
- "token": gh_token,
54
- "repo_name": gh_repo_name,
55
- "private": private,
56
- "target_folder": output_path,
57
- }
58
-
59
- generator = ProjectGenerator(
60
- prompt=prompt,
61
- output_path=output_path,
62
- verbose=True,
63
- customisation_kwargs=customisation_kwargs,
64
- github_repo_creator_kwargs=github_repo_creator_kwargs,
65
- )
66
-
67
- try:
68
- generator.generate_template()
69
- except Exception as e:
70
- gr.Error(e)
71
-
72
- return f"Your project is now available on {generator.github_repo_url} 🚀 !"
 
 
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():