import openai import gradio as gr # Set up OpenAI API credentials openai.api_key = "YOUR_API_KEY_HERE" # Define the chat function def chat(prompt): # Define the parameters for the OpenAI API request model_engine = "text-davinci-003" max_tokens = 60 temperature = 0.7 response = openai.Completion.create( engine=model_engine, prompt=prompt, max_tokens=max_tokens, temperature=temperature, n=1, stop=None, ) # Extract the generated text from the OpenAI API response message = response.choices[0].text.strip() # Return the generated message return message # Define the input and output components for the Gradio interface prompt_input = gr.inputs.Textbox(label="Prompt") response_output = gr.outputs.Textbox(label="Response") # Define the Gradio interface chat_interface = gr.Interface( fn=chat, inputs=prompt_input, outputs=response_output, title="OpenAI GPT-3 Chatbot", description="Enter a prompt and the AI will generate a response.", theme="light", layout="vertical", show_input=True, show_output=True ) # Launch the interface chat_interface.launch()