Spaces:
Runtime error
Runtime error
[email protected]
commited on
Commit
·
cc117e5
1
Parent(s):
17a4116
Adding model selection
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import subprocess
|
4 |
import shutil
|
|
|
5 |
|
6 |
css_style = """
|
7 |
.gradio-container {
|
@@ -9,7 +10,7 @@ css_style = """
|
|
9 |
}
|
10 |
"""
|
11 |
|
12 |
-
def process_repository(url):
|
13 |
|
14 |
|
15 |
# Split the URL to get the repo name
|
@@ -25,7 +26,7 @@ def process_repository(url):
|
|
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:
|
@@ -40,10 +41,20 @@ def process_repository(url):
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
else:
|
48 |
return "Please add a valid OpenAI API Key (you can get them [here](https://platform.openai.com/account/api-keys))"
|
49 |
|
@@ -58,15 +69,17 @@ with gr.Blocks(css=css_style) as demo:
|
|
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.
|
|
|
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)
|
|
|
2 |
import os
|
3 |
import subprocess
|
4 |
import shutil
|
5 |
+
import openai
|
6 |
|
7 |
css_style = """
|
8 |
.gradio-container {
|
|
|
10 |
}
|
11 |
"""
|
12 |
|
13 |
+
def process_repository(url, model):
|
14 |
|
15 |
|
16 |
# Split the URL to get the repo name
|
|
|
26 |
os.chdir(repo_name)
|
27 |
|
28 |
# Run your package command
|
29 |
+
subprocess.run(['gpt4readability', '.', '--function', 'readme', '--model', model])
|
30 |
|
31 |
# Open the README.md file and return its contents
|
32 |
with open('README.md', 'r') as readme_file:
|
|
|
41 |
if os.path.exists(repo_name):
|
42 |
shutil.rmtree(repo_name)
|
43 |
|
44 |
+
def generate_repo(url, api_key, model):
|
45 |
if api_key:
|
46 |
os.environ['OPENAI_API_KEY'] = api_key.strip()
|
47 |
+
if model == 'gpt-4':
|
48 |
+
try:
|
49 |
+
response = openai.Completion.create(
|
50 |
+
model="gpt-4", # or whatever the exact model ID is
|
51 |
+
prompt="test",
|
52 |
+
max_tokens=5
|
53 |
+
)
|
54 |
+
print("Access to GPT-4 confirmed!")
|
55 |
+
except:
|
56 |
+
return "The API key either does not have access to GPT-4 or is not valid."
|
57 |
+
return process_repository(url, model)
|
58 |
else:
|
59 |
return "Please add a valid OpenAI API Key (you can get them [here](https://platform.openai.com/account/api-keys))"
|
60 |
|
|
|
69 |
* [langchain](https://github.com/hwchase17/langchain) is the main library this tool utilizes.
|
70 |
1. Enter API Key ([What is that?](https://platform.openai.com/account/api-keys))
|
71 |
2. Paste in a GitHub Repository URL
|
72 |
+
3. Choose a model (The gpt-4 API as of July 2023 is not available to everyone)
|
73 |
+
4. Generate a README or suggestions markdown file
|
74 |
""")
|
75 |
|
76 |
openai_api_key = gr.Textbox(
|
77 |
label="OpenAI API Key", placeholder="sk-...", type="password")
|
78 |
url = gr.Textbox(label="GitHub Repository URL")
|
79 |
+
model = gr.Dropdown(["gpt-3.5-turbo", "gpt-4"], type="value", label='Model Type')
|
80 |
output = gr.Markdown(label="README.md")
|
81 |
btn = gr.Button("Generate README.md")
|
82 |
+
btn.click(fn=generate_repo, inputs=[url, openai_api_key, model], outputs=[output], api_name="Generate README.md")
|
83 |
|
84 |
|
85 |
demo.queue(concurrency_count=20)
|