import openai as ai ai.api_key = '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' # replace with your key from earlier import os import openai as ai # Get the key from an environment variable on the machine it is running on # ai.api_key = os.environ.get("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") def generate_gpt3_response(user_text, print_output=False): """ Query OpenAI GPT-3 for the specific key and get back a response :type user_text: str the user's text to query for :type print_output: boolean whether or not to print the raw output JSON """ completions = ai.Completion.create( engine='text-davinci-003', # Determines the quality, speed, and cost. temperature=0.5, # Level of creativity in the response prompt=user_text, # What the user typed in max_tokens=100, # Maximum tokens in the prompt AND response n=1, # The number of completions to generate stop=None, # An optional setting to control response generation ) # Displaying the output can be helpful if things go wrong if print_output: print(completions) # Return the first choice's text return completions.choices[0].text models = ai.Model.list() for model in models.data: (model.id) if __name__ == '__main__': prompt = 'Magento with 0% plagiarism' response = generate_gpt3_response(prompt) print(response) import gradio as gr input_text = gr.inputs.Textbox(lines=20, label='Input Text') output_text = gr.outputs.Textbox(label='Output Text') app = gr.Interface(generate_gpt3_response, inputs=input_text, css="""span.svelte-1l2rj76{color: #591fc9;font-size: 18px; font-weight: 600;}.secondary.svelte-1ma3u5b{background: #591fc9; color: #fff;}.secondary.svelte-1ma3u5b:hover{background:#8a59e8;color:#000;} .svelte-2xzfnp textarea {border: 1px solid #591fc9}.primary.svelte-1ma3u5b{background: #f8d605;color: #000;}.primary.svelte-1ma3u5b:hover{background: #ffe751;color: #591fc9;}.svelte-2xzfnp{height: 168px !important;}.svelte-1iguv9h {max-width: none !important; margin: 0px !important; padding: 0px !important;} label.svelte-2xzfnp{display: contents !important;} """, outputs=output_text, title='Content Generator') # Launch the user interface app.launch(inline=False)