Spaces:
Runtime error
Runtime error
import gradio as gr | |
import openai | |
import os | |
# Set the API key for the OpenAI API | |
# Set the model to use (e.g. "text-davinci-002") | |
model = "text-davinci-002" | |
def convert_code(code, language_in, language_out): | |
""" | |
Convert the given code to the specified language using GPT-3. | |
""" | |
# Set the prompt to use as input to the model | |
prompt = f""""Convert {language_in} code to {language_out} code:\n{code}""" | |
# Call the GPT-3 API to generate text | |
response = openai.Completion.create( | |
engine=model, | |
prompt=prompt, | |
max_tokens=1024, | |
temperature=0.5, | |
top_p=1, | |
frequency_penalty=0, | |
presence_penalty=0 | |
) | |
# Return the generated text | |
return response["choices"][0]["text"] | |
# Create the Gradio app | |
app = gr.Interface( | |
fn=convert_code, | |
inputs=[gr.inputs.Textbox(lines=10, label="Code to convert"), gr.Radio(["Python", "R"], label="Source language"), gr.Radio(["Python", "R"], label="Output language")], | |
outputs=[gr.outputs.Textbox(label="Converted code")] | |
) | |
app.launch() | |