import gradio as gr import openai import os # Set up the OpenAI API credentials # openai.api_key = os.environ["OPENAI_API_KEY"] openai.api_key = os.getenv("OPENAI_API_KEY") model = "gpt-3.5-turbo" # Define the chatbot function def chatbot(text): # Call OpenAI API to generate text completion completion = openai.ChatCompletion.create(model=model, messages=[{"role": "user", "content": text}]) # Extract the generated response and return it return completion.choices[0].message.content # Create the Gradio interface iface = gr.Interface(fn=chatbot, inputs="text", outputs="text", title="GPT-3.5 Turbo Chatbot") # Launch the interface iface.launch()