Spaces:
Runtime error
Runtime error
import gradio as gr | |
import openai | |
# Set up the OpenAI API credentials | |
openai.api_key = "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" | |
# 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 | |
def correct_code(prompt): | |
# Use the OpenAI API to generate suggestions for fixing syntax errors in the code | |
response = openai.Completion.create( | |
engine="davinci-codex", | |
prompt=prompt, | |
max_tokens=1024, | |
n=1, | |
stop=None, | |
temperature=0.5, | |
) | |
# Extract the corrected code from the API response | |
corrected_code = response.choices[0].text.strip() | |
return corrected_code | |
# Define a Gradio interface for the code editor | |
input_code = gr.inputs.Textbox(lines=20, label="Write your code here") | |
output_code = gr.outputs.Textbox(label="Corrected Code") | |
def generate_code(input_code): | |
corrected_code = correct_code(input_code) | |
return corrected_code | |
# Define the Gradio interface for the code editor | |
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.") | |
# Run the Gradio interface for the code editor | |
interface.launch() |