Spaces:
Runtime error
Runtime error
| 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, from_lang, to_lang): | |
| """ | |
| Convert the given code from the specified source language to the | |
| specified target language using GPT-3. | |
| """ | |
| # Set the prompt to use as input to the model | |
| prompt = f"Convert {from_lang} code to {to_lang} 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"), | |
| outputs=gr.outputs.Textbox(label="Converted code")) | |
| app.launch() | |