import openai import gradio as gr # Set up OpenAI API key openai.api_key = "your-openai-secret-key" # Define a function to call the OpenAI API def chatbot(input_text): try: response = openai.completions.create( model="gpt-3.5-turbo", # You can change this model if you have access to GPT-4 or other models prompt=input_text, max_tokens=150 ) return response['choices'][0]['text'].strip() except Exception as e: return f"Error: {str(e)}" # Create the Gradio interface iface = gr.Interface( fn=chatbot, inputs=gr.Textbox(lines=2, placeholder="Type your message here..."), outputs=gr.Textbox(), live=True ) # Launch the interface iface.launch()