Spaces:
Runtime error
Runtime error
Commit
·
804ba71
1
Parent(s):
ade4354
Update app.py
Browse files
app.py
CHANGED
@@ -1 +1,29 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import openai
|
3 |
+
|
4 |
+
def generate_code(api_key, prompt):
|
5 |
+
openai.api_key = api_key
|
6 |
+
|
7 |
+
response = openai.Completion.create(
|
8 |
+
engine="text-davinci-002",
|
9 |
+
prompt=prompt,
|
10 |
+
max_tokens=100,
|
11 |
+
n=1,
|
12 |
+
stop=None,
|
13 |
+
temperature=0.5,
|
14 |
+
)
|
15 |
+
|
16 |
+
return response.choices[0].text.strip()
|
17 |
+
|
18 |
+
if __name__ == "__main__":
|
19 |
+
api_key_input = gr.inputs.Textbox(lines=1, label="OpenAI API Key", type="password")
|
20 |
+
prompt_input = gr.inputs.Textbox(lines=5, label="Prompt")
|
21 |
+
output = gr.outputs.Textbox(label="Generated Code")
|
22 |
+
|
23 |
+
gr.Interface(
|
24 |
+
fn=generate_code,
|
25 |
+
inputs=[api_key_input, prompt_input],
|
26 |
+
outputs=output,
|
27 |
+
title="OpenAI Code Generator",
|
28 |
+
description="Generate code using OpenAI's GPT-4 model. Enter your API key and a prompt, and let the AI write code for you!",
|
29 |
+
).launch()
|