typesdigital commited on
Commit
fd1a5cd
·
1 Parent(s): 7704a4e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+
4
+ # Define a function that takes a user's input code as a prompt and uses the OpenAI API to generate a corrected version of the code
5
+ def correct_code(prompt):
6
+ # Use the OpenAI API to generate suggestions for fixing syntax errors in the code
7
+ response = openai.Completion.create(
8
+ engine="davinci-codex",
9
+ prompt=prompt,
10
+ max_tokens=1024,
11
+ n=1,
12
+ stop=None,
13
+ temperature=0.5,
14
+ )
15
+
16
+ # Extract the corrected code from the API response
17
+ corrected_code = response.choices[0].text.strip()
18
+
19
+ return corrected_code
20
+
21
+ # Define a Gradio interface for the code editor
22
+ input_code = gr.inputs.Textbox(lines=20, label="Write your code here")
23
+ output_code = gr.outputs.Textbox(label="Corrected Code")
24
+
25
+ def generate_code(input_code):
26
+ corrected_code = correct_code(input_code)
27
+ return corrected_code
28
+
29
+ # Define the Gradio interface for the code editor
30
+ interface = gr.Interface(fn=generate_code, inputs=input_code, outputs=output_code, title="AI Code Editor", description="Write your code in the editor and click submit to generate a corrected version.")
31
+
32
+ # Run the Gradio interface for the code editor
33
+ interface.launch(share=True)