import openai import gradio as gr # Set up OpenAI API key openai_api_key = "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" # Define a function to call the OpenAI API def chatbot(input_text): try: response = openai.ChatCompletion.create( model="gpt-3.5-turbo", # You can change this to GPT-4 or others messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": input_text}, ] ) return response['choices'][0]['message']['content'].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()