loevliedenny@gmail.com commited on
Commit
17a4116
1 Parent(s): 541450c

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +73 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import subprocess
4
+ import shutil
5
+
6
+ css_style = """
7
+ .gradio-container {
8
+ font-family: "IBM Plex Mono";
9
+ }
10
+ """
11
+
12
+ def process_repository(url):
13
+
14
+
15
+ # Split the URL to get the repo name
16
+ repo_name = url.split('/')[-1]
17
+ if repo_name.endswith('.git'):
18
+ repo_name = repo_name[:-4]
19
+
20
+ # Clone the repo
21
+ subprocess.run(['git', 'clone', url], check=True)
22
+
23
+ try:
24
+ # Change directory to the cloned repo
25
+ os.chdir(repo_name)
26
+
27
+ # Run your package command
28
+ subprocess.run(['gpt4readability', '.', '--function', 'readme'])
29
+
30
+ # Open the README.md file and return its contents
31
+ with open('README.md', 'r') as readme_file:
32
+ readme_contents = readme_file.read()
33
+
34
+ return readme_contents
35
+ finally:
36
+ # Change back to the original directory
37
+ os.chdir('..')
38
+
39
+ # Delete the repo directory
40
+ if os.path.exists(repo_name):
41
+ shutil.rmtree(repo_name)
42
+
43
+ def generate_repo(url, api_key):
44
+ if api_key:
45
+ os.environ['OPENAI_API_KEY'] = api_key.strip()
46
+ return process_repository(url)
47
+ else:
48
+ return "Please add a valid OpenAI API Key (you can get them [here](https://platform.openai.com/account/api-keys))"
49
+
50
+ with gr.Blocks(css=css_style) as demo:
51
+ gr.Markdown(f"""
52
+ # GPT4Readability (v0.0.3)
53
+ *By Dennis Loevlie ([@DennisLoevlie](https://twitter.com/DennisLoevlie))*
54
+ [![License Badge](https://img.shields.io/github/license/loevlie/GPT4Readability)](https://github.com/loevlie/GPT4Readability/blob/main/LICENSE)
55
+
56
+ GPT4Readability is a powerful tool designed to automatically generate a comprehensive README.md file and suggest code improvements for any Python code repository.
57
+ * [GPT4Readability](https://github.com/loevlie/GPT4Readability) is the code used to build this tool.
58
+ * [langchain](https://github.com/hwchase17/langchain) is the main library this tool utilizes.
59
+ 1. Enter API Key ([What is that?](https://platform.openai.com/account/api-keys))
60
+ 2. Paste in a GitHub Repository URL
61
+ 3. Generate a README or suggestions markdown file
62
+ """)
63
+
64
+ openai_api_key = gr.Textbox(
65
+ label="OpenAI API Key", placeholder="sk-...", type="password")
66
+ url = gr.Textbox(label="GitHub Repository URL")
67
+ output = gr.Markdown(label="README.md")
68
+ btn = gr.Button("Generate README.md")
69
+ btn.click(fn=generate_repo, inputs=[url,openai_api_key], outputs=[output], api_name="Generate README.md")
70
+
71
+
72
+ demo.queue(concurrency_count=20)
73
+ demo.launch(share=False)
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ GPT4Readability==0.0.3