Spaces:
Runtime error
Runtime error
Commit
·
043af13
1
Parent(s):
2d4cb27
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,13 +8,12 @@ openai.api_key = "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"
|
|
| 8 |
# Set the model to use (e.g. "text-davinci-002")
|
| 9 |
model = "text-davinci-002"
|
| 10 |
|
| 11 |
-
def convert_code(code,
|
| 12 |
"""
|
| 13 |
-
Convert the given code
|
| 14 |
-
specified target language using GPT-3.
|
| 15 |
"""
|
| 16 |
# Set the prompt to use as input to the model
|
| 17 |
-
prompt = f"Convert {
|
| 18 |
|
| 19 |
# Call the GPT-3 API to generate text
|
| 20 |
response = openai.Completion.create(
|
|
@@ -34,5 +33,7 @@ def convert_code(code, from_lang, to_lang):
|
|
| 34 |
app = gr.Interface(
|
| 35 |
fn=convert_code,
|
| 36 |
inputs=gr.inputs.Textbox(lines=10, label="Code to convert"),
|
|
|
|
| 37 |
outputs=gr.outputs.Textbox(label="Converted code"))
|
|
|
|
| 38 |
app.launch()
|
|
|
|
| 8 |
# Set the model to use (e.g. "text-davinci-002")
|
| 9 |
model = "text-davinci-002"
|
| 10 |
|
| 11 |
+
def convert_code(code, language):
|
| 12 |
"""
|
| 13 |
+
Convert the given code to the specified language using GPT-3.
|
|
|
|
| 14 |
"""
|
| 15 |
# Set the prompt to use as input to the model
|
| 16 |
+
prompt = f"Convert {language} code to R code:\n{code}"
|
| 17 |
|
| 18 |
# Call the GPT-3 API to generate text
|
| 19 |
response = openai.Completion.create(
|
|
|
|
| 33 |
app = gr.Interface(
|
| 34 |
fn=convert_code,
|
| 35 |
inputs=gr.inputs.Textbox(lines=10, label="Code to convert"),
|
| 36 |
+
controls=gr.controls.Radio(["Python", "R"], label="Source language"),
|
| 37 |
outputs=gr.outputs.Textbox(label="Converted code"))
|
| 38 |
+
|
| 39 |
app.launch()
|