JohanDL commited on
Commit
e01f2c9
·
verified ·
1 Parent(s): dda8c8d

Add rendered md option for easier copying.

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -43,7 +43,7 @@ def process_repository(url, model):
43
  if os.path.exists(repo_name):
44
  shutil.rmtree(repo_name)
45
 
46
- def generate_repo(url, api_key, model):
47
  if api_key:
48
  os.environ['OPENAI_API_KEY'] = api_key.strip()
49
  # if model == 'gpt-4':
@@ -56,7 +56,11 @@ def generate_repo(url, api_key, model):
56
  # print("Access to GPT-4 confirmed!")
57
  # except:
58
  # return "The API key either does not have access to GPT-4 or is not valid."
59
- return process_repository(url, model)
 
 
 
 
60
  else:
61
  return "Please add a valid OpenAI API Key (you can get them [here](https://platform.openai.com/account/api-keys))"
62
 
@@ -83,9 +87,17 @@ with gr.Blocks(css=css_style) as demo:
83
  label="OpenAI API Key", placeholder="sk-...", type="password")
84
  url = gr.Textbox(label="GitHub Repository URL")
85
  model = gr.Dropdown(["gpt-3.5-turbo", "gpt-4"], type="value", label='Model Type')
86
- output = gr.Markdown(label="README.md")
 
 
87
  btn = gr.Button("Generate README.md")
88
- btn.click(fn=generate_repo, inputs=[url, openai_api_key, model], outputs=[output], api_name="Generate README.md")
 
 
 
 
 
 
89
 
90
 
91
  demo.queue(concurrency_count=20)
 
43
  if os.path.exists(repo_name):
44
  shutil.rmtree(repo_name)
45
 
46
+ def generate_repo(url, api_key, model, output_format):
47
  if api_key:
48
  os.environ['OPENAI_API_KEY'] = api_key.strip()
49
  # if model == 'gpt-4':
 
56
  # print("Access to GPT-4 confirmed!")
57
  # except:
58
  # return "The API key either does not have access to GPT-4 or is not valid."
59
+ readme_contents = process_repository(url, model)
60
+ if output_format == "Rendered Markdown":
61
+ return readme_contents, None
62
+ else:
63
+ return None, readme_contents
64
  else:
65
  return "Please add a valid OpenAI API Key (you can get them [here](https://platform.openai.com/account/api-keys))"
66
 
 
87
  label="OpenAI API Key", placeholder="sk-...", type="password")
88
  url = gr.Textbox(label="GitHub Repository URL")
89
  model = gr.Dropdown(["gpt-3.5-turbo", "gpt-4"], type="value", label='Model Type')
90
+ output_format = gr.Radio(choices=["Rendered Markdown", "Plain Markdown"], label="Output Format", value="Rendered Markdown")
91
+ output_md = gr.Markdown(label="Rendered README.md", visible=False)
92
+ output_text = gr.Text(label="Plain Markdown README.md", visible=False)
93
  btn = gr.Button("Generate README.md")
94
+
95
+ def update_output(*args):
96
+ md_content, text_content = generate_repo(*args)
97
+ output_md.update(value=md_content, visible=md_content is not None)
98
+ output_text.update(value=text_content, visible=text_content is not None)
99
+
100
+ btn.click(fn=update_output, inputs=[url, openai_api_key, model, output_format], outputs=[output_md, output_text])
101
 
102
 
103
  demo.queue(concurrency_count=20)