import openai import os import gradio as gr # Fetching API key from environment variable API_KEY = os.environ['API_KEY'] # Setting up OpenAI API credentials openai.api_key = API_KEY model_engine = 'text-davinci-002' prompt = 'Please solve the following math problem: ' # Defining the function to solve math problems def math_tutor(problem): response = openai.Completion.create( engine='gpt-3.5-turbo-0301', prompt=prompt + problem, max_tokens=50, n=1, stop=None, temperature=0.7, ) answer = response.choices[0].text.strip() return answer # Creating a Gradio interface for the math tutor iface = gr.Interface( fn=math_tutor, inputs=gr.inputs.Textbox(label="Enter a math problem"), outputs="text", title="Math Tutor", description="Enter a math problem and the Math Tutor will solve it for you!", theme="compact" ) # Running the Gradio interface if __name__ == '__main__': iface.launch()