Spaces:
Sleeping
Sleeping
File size: 984 Bytes
2bdde4b 57eaad1 a2ea3bb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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()
|