import gradio as gr import openai import os # Get the OpenAI API key from the environment variable api_key = os.getenv('OpenAIKey') # Function to call OpenAI API def get_openai_response(api_key, model, prompt): client = openai.OpenAI(api_key=api_key) response = client.chat.completions.create( model=model, messages=[ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt} ] ) return response.choices[0].message.content def generate_responses(prompt): response_gpt3 = get_openai_response(api_key, "gpt-3.5-turbo", prompt) response_gpt4 = get_openai_response(api_key, "gpt-4o", prompt) return response_gpt3, response_gpt4 # Gradio Interface inputs = [ gr.Textbox(label="Your Question") ] outputs = [ gr.Textbox(label="GPT-3.5 Turbo Response"), gr.Textbox(label="GPT-4o Response") ] gr.Interface( fn=generate_responses, inputs=inputs, outputs=outputs, title="Compare GPT Models", description="Enter your question to get responses from GPT-3.5 Turbo and GPT-4o models, compare the results", css="styles.css" ).launch(show_api=False)