import gradio as gr import openai import os # Read the API key from the .env file openai.api_key = os.getenv("API_KEY") # Define the chatbot function def chatbot(message): response = openai.Completion.create( model="gpt-3.5-turbo", prompt=message, max_tokens=50, temperature=0.8, ) return response.choices[0].text.strip() # Create the interface textbox = gr.inputs.Textbox(label="Chat Message") button = gr.outputs.Button(label="Submit") output_text = gr.outputs.Textbox(label="Chatbot Response") def chat_interface(message): response = chatbot(message) return response gr.Interface( fn=chat_interface, inputs=textbox, outputs=output_text, title="Chat with GPT-3.5 Turbo", description="This is a chatbot powered by GPT-3.5 Turbo.", theme="huggingface", server_port=8080 # Change this to the desired port number ).launch()