File size: 1,052 Bytes
e27f3f4
 
 
 
 
83e859c
e27f3f4
 
 
 
043af13
e27f3f4
043af13
e27f3f4
 
043af13
e27f3f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ce07fb6
2d4cb27
043af13
ec9bd81
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import gradio as gr
import openai
import os

# Set the API key for the OpenAI API
openai.api_key = "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"

# Set the model to use (e.g. "text-davinci-002")
model = "text-davinci-002"

def convert_code(code, language):
    """
    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} code to R 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.controls.Radio(["Python", "R"], label="Source language")],
    outputs=gr.outputs.Textbox(label="Converted code"))

app.launch()